From cbc742e3e97f2fdaecb6db66bfe8541b44db3ed7 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 12 Dec 2020 02:04:44 -0500 Subject: [PATCH] Adds more logging for file watching issues If repo lacks watching, pretend change checks are true if unknown change --- src/extension.ts | 4 ++-- src/git/models/repository.ts | 45 ++++++++++++++++++++++++++++++++------- src/hovers/hovers.ts | 4 ++-- src/logger.ts | 14 ++++++++++++ src/quickpicks/quickPicksItems.ts | 1 - 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index df75f2f..5dcc1ae 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,7 @@ import { Container } from './container'; import { Git, GitCommit } from './git/git'; import { GitService } from './git/gitService'; import { GitUri } from './git/gitUri'; -import { Logger, TraceLevel } from './logger'; +import { Logger } from './logger'; import { Messages } from './messages'; import { Strings, Versions } from './system'; import { ViewNode } from './views/nodes'; @@ -69,7 +69,7 @@ export async function activate(context: ExtensionContext): Promise(GlobalState.Deprecated_Version) ?? syncedVersion; - if (Logger.level === TraceLevel.Debug || Logger.isDebugging) { + if (Logger.willLog('debug')) { Logger.debug( `GitLens (v${gitlensVersion}): syncedVersion=${syncedVersion}, previousVersion=${previousVersion}, ${ SyncedState.WelcomeViewVisible diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index cf2c924..11619ad 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -47,18 +47,37 @@ export class RepositoryChangeEvent { constructor(public readonly repository?: Repository, public readonly changes: RepositoryChange[] = []) {} changed(change: RepositoryChange, only: boolean = false) { - if (only) return this.changes.length === 1 && this.changes[0] === change; + if (only) { + if (this.changes.length !== 1) return false; + if (this.changes[0] === change) return true; + + if (this.repository?.supportsChangeEvents === false && this.changes[0] === RepositoryChange.Unknown) { + switch (change) { + case RepositoryChange.Closed: + case RepositoryChange.Starred: + return false; + default: + return true; + } + } - return this.changes.includes(change); + return false; + } - // const changed = this.changes.includes(change); - // if (changed) return true; + if (this.changes.includes(change)) return true; - // if (change === RepositoryChange.Repository) { - // return this.changes.includes(RepositoryChange.Stashes); - // } + if (this.repository?.supportsChangeEvents === false && this.changes.includes(RepositoryChange.Unknown)) { + switch (change) { + case RepositoryChange.Closed: + case RepositoryChange.Ignores: + case RepositoryChange.Starred: + return false; + default: + return true; + } + } - // return false; + return false; } } @@ -159,6 +178,16 @@ export class Repository implements Disposable { configuration.onDidChange(this.onConfigurationChanged, this), ); this.onConfigurationChanged(configuration.initializingChangeEvent); + + if (!this.supportsChangeEvents && Logger.willLog('debug')) { + Logger.debug( + `Repository[${this.name}(${ + this.id + })] doesn't support file watching; path=${path}, workspaceFolders=${workspace.workspaceFolders + ?.map(wf => wf.uri.fsPath) + .join('; ')}`, + ); + } } dispose() { diff --git a/src/hovers/hovers.ts b/src/hovers/hovers.ts index c2d5177..80ec9f0 100644 --- a/src/hovers/hovers.ts +++ b/src/hovers/hovers.ts @@ -14,7 +14,7 @@ import { GitRevision, } from '../git/git'; import { GitUri } from '../git/gitUri'; -import { Logger, TraceLevel } from '../logger'; +import { Logger } from '../logger'; import { Iterables, Promises, Strings } from '../system'; export namespace Hovers { @@ -258,7 +258,7 @@ export namespace Hovers { timeout: timeout, }); - if (autolinks != null && (Logger.level === TraceLevel.Debug || Logger.isDebugging)) { + if (autolinks != null && Logger.willLog('debug')) { // If there are any issues/PRs that timed out, log it const count = Iterables.count(autolinks.values(), pr => pr instanceof Promises.CancellationError); if (count !== 0) { diff --git a/src/logger.ts b/src/logger.ts index f40d0c9..fbaf603 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -196,6 +196,20 @@ export class Logger { } } + static willLog(type: 'debug' | 'error' | 'log' | 'warn'): boolean { + switch (type) { + case 'debug': + return this.level === TraceLevel.Debug || Logger.isDebugging; + case 'error': + case 'warn': + return this.level !== TraceLevel.Silent || Logger.isDebugging; + case 'log': + return this.level === TraceLevel.Verbose || this.level === TraceLevel.Debug || Logger.isDebugging; + default: + return false; + } + } + static showOutputChannel() { if (this.output == null) return; diff --git a/src/quickpicks/quickPicksItems.ts b/src/quickpicks/quickPicksItems.ts index 0af4176..6066ac7 100644 --- a/src/quickpicks/quickPicksItems.ts +++ b/src/quickpicks/quickPicksItems.ts @@ -6,7 +6,6 @@ import { GitReference, GitRevisionReference, GitStashCommit, SearchPattern } fro import { Keys } from '../keyboard'; declare module 'vscode' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface QuickPickItem { onDidSelect?(): void; onDidPressKey?(key: Keys): Promise;