Skip to content

Commit

Permalink
Adds more logging for file watching issues
Browse files Browse the repository at this point in the history
If repo lacks watching, pretend change checks are true if unknown change
  • Loading branch information
eamodio committed Dec 12, 2020
1 parent 38cc8b1 commit cbc742e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -69,7 +69,7 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |
context.globalState.get<string>(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
Expand Down
45 changes: 37 additions & 8 deletions src/git/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/hovers/hovers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/quickpicks/quickPicksItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down

0 comments on commit cbc742e

Please sign in to comment.