Skip to content

Commit 00cdd2e

Browse files
committed
Adds "on" state to file annotation command
Adds "progress" state to file annotation command
1 parent 787e0e6 commit 00cdd2e

17 files changed

+146
-25
lines changed

images/dark/git-icon-orange.svg

Lines changed: 10 additions & 0 deletions
Loading

images/dark/git-icon-progress.svg

Lines changed: 12 additions & 0 deletions
Loading

images/light/git-icon-orange.svg

Lines changed: 10 additions & 0 deletions
Loading

images/light/git-icon-progress.svg

Lines changed: 13 additions & 0 deletions
Loading

package.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,24 @@
818818
"light": "images/light/git-icon.svg"
819819
}
820820
},
821+
{
822+
"command": "gitlens.clearFileAnnotations",
823+
"title": "Clear File Annotations",
824+
"category": "GitLens",
825+
"icon": {
826+
"dark": "images/dark/git-icon-orange.svg",
827+
"light": "images/light/git-icon-orange.svg"
828+
}
829+
},
830+
{
831+
"command": "gitlens.computingFileAnnotations",
832+
"title": "Computing File Annotations...",
833+
"category": "GitLens",
834+
"icon": {
835+
"dark": "images/dark/git-icon-progress.svg",
836+
"light": "images/light/git-icon-progress.svg"
837+
}
838+
},
821839
{
822840
"command": "gitlens.toggleFileRecentChanges",
823841
"title": "Toggle Recent File Changes Annotations",
@@ -1046,6 +1064,14 @@
10461064
"command": "gitlens.toggleFileBlame",
10471065
"when": "gitlens:isBlameable"
10481066
},
1067+
{
1068+
"command": "gitlens.clearFileAnnotations",
1069+
"when": "gitlens:annotationStatus == computed"
1070+
},
1071+
{
1072+
"command": "gitlens.computingFileAnnotations",
1073+
"when": "false"
1074+
},
10491075
{
10501076
"command": "gitlens.toggleFileRecentChanges",
10511077
"when": "gitlens:isTracked"
@@ -1227,7 +1253,17 @@
12271253
{
12281254
"command": "gitlens.toggleFileBlame",
12291255
"alt": "gitlens.toggleFileRecentChanges",
1230-
"when": "gitlens:isBlameable && config.gitlens.advanced.menus.editorTitle.blame",
1256+
"when": "gitlens:isBlameable && !gitlens:annotationStatus && config.gitlens.advanced.menus.editorTitle.blame",
1257+
"group": "navigation@100"
1258+
},
1259+
{
1260+
"command": "gitlens.computingFileAnnotations",
1261+
"when": "gitlens:annotationStatus == computing && config.gitlens.advanced.menus.editorTitle.blame",
1262+
"group": "navigation@100"
1263+
},
1264+
{
1265+
"command": "gitlens.clearFileAnnotations",
1266+
"when": "gitlens:annotationStatus == computed && config.gitlens.advanced.menus.editorTitle.blame",
12311267
"group": "navigation@100"
12321268
},
12331269
{

src/annotations/annotationController.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AnnotationProviderBase } from './annotationProvider';
55
import { Keyboard, KeyboardScope, KeyCommand, Keys } from '../keyboard';
66
import { TextDocumentComparer, TextEditorComparer } from '../comparers';
77
import { ExtensionKey, IConfig, LineHighlightLocations, themeDefaults } from '../configuration';
8+
import { CommandContext, setCommandContext } from '../constants';
89
import { BlameabilityChangeEvent, GitContextTracker, GitService, GitUri } from '../gitService';
910
import { GutterBlameAnnotationProvider } from './gutterBlameAnnotationProvider';
1011
import { HoverBlameAnnotationProvider } from './hoverBlameAnnotationProvider';
@@ -203,6 +204,8 @@ export class AnnotationController extends Disposable {
203204
if (this._annotationProviders.size === 0) {
204205
Logger.log(`Remove listener registrations for annotations`);
205206

207+
await setCommandContext(CommandContext.AnnotationStatus, undefined);
208+
206209
this._keyboardScope && this._keyboardScope.dispose();
207210
this._keyboardScope = undefined;
208211

@@ -235,7 +238,16 @@ export class AnnotationController extends Disposable {
235238
return true;
236239
}
237240

238-
return window.withProgress({ location: ProgressLocation.Window }, async (progress: Progress<{message: string}>) => this._showAnnotationsCore(currentProvider, editor, type, shaOrLine, progress));
241+
return window.withProgress({ location: ProgressLocation.Window }, async (progress: Progress<{ message: string }>) => {
242+
await setCommandContext(CommandContext.AnnotationStatus, 'computing');
243+
244+
const computingAnnotations = this._showAnnotationsCore(currentProvider, editor, type, shaOrLine, progress);
245+
const result = await computingAnnotations;
246+
247+
await setCommandContext(CommandContext.AnnotationStatus, result ? 'computed' : undefined);
248+
249+
return computingAnnotations;
250+
});
239251
}
240252

241253
private async _showAnnotationsCore(currentProvider: AnnotationProviderBase | undefined, editor: TextEditor, type: FileAnnotationType, shaOrLine?: string | number, progress?: Progress<{ message: string}>): Promise<boolean> {
@@ -311,11 +323,12 @@ export class AnnotationController extends Disposable {
311323
this._onDidToggleAnnotations.fire();
312324
return true;
313325
}
326+
314327
return false;
315328
}
316329

317330
async toggleAnnotations(editor: TextEditor, type: FileAnnotationType, shaOrLine?: string | number): Promise<boolean> {
318-
if (!editor || !editor.document || type === FileAnnotationType.RecentChanges ? !this.git.isTrackable(editor.document.uri) : !this.git.isEditorBlameable(editor)) return false;
331+
if (!editor || !editor.document || (type === FileAnnotationType.RecentChanges ? !this.git.isTrackable(editor.document.uri) : !this.git.isEditorBlameable(editor))) return false;
319332

320333
const provider = this._annotationProviders.get(editor.viewColumn || -1);
321334
if (provider === undefined) return this.showAnnotations(editor, type, shaOrLine);

src/annotations/annotationProvider.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { Functions } from '../system';
2+
// import { Functions } from '../system';
33
import { Disposable, ExtensionContext, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
44
import { FileAnnotationType } from '../annotations/annotationController';
55
import { TextDocumentComparer } from '../comparers';
@@ -43,19 +43,12 @@ import { WhitespaceController } from './whitespaceController';
4343
async clear() {
4444
if (this.editor !== undefined) {
4545
try {
46-
if (this.decoration !== undefined) {
47-
this.editor.setDecorations(this.decoration, []);
48-
}
49-
5046
if (this.highlightDecoration !== undefined) {
5147
this.editor.setDecorations(this.highlightDecoration, []);
48+
}
5249

53-
// I have no idea why the decorators sometimes don't get removed, but if they don't try again with a tiny delay
54-
await Functions.wait(1);
55-
56-
if (this.highlightDecoration === undefined) return;
57-
58-
this.editor.setDecorations(this.highlightDecoration, []);
50+
if (this.decoration !== undefined) {
51+
this.editor.setDecorations(this.decoration, []);
5952
}
6053
}
6154
catch (ex) { }

src/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
export * from './commands/common';
33

4+
export * from './commands/clearFileAnnotations';
45
export * from './commands/closeUnchangedFiles';
56
export * from './commands/copyMessageToClipboard';
67
export * from './commands/copyShaToClipboard';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
import { TextEditor, TextEditorEdit, Uri, window } from 'vscode';
3+
import { AnnotationController } from '../annotations/annotationController';
4+
import { Commands, EditorCommand } from './common';
5+
import { Logger } from '../logger';
6+
7+
export class ClearFileAnnotationsCommand extends EditorCommand {
8+
9+
constructor(private annotationController: AnnotationController) {
10+
super(Commands.ClearFileAnnotations);
11+
}
12+
13+
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri): Promise<any> {
14+
if (editor === undefined || editor.document === undefined || editor.document.isDirty) return undefined;
15+
16+
try {
17+
return this.annotationController.clear(editor.viewColumn || -1);
18+
}
19+
catch (ex) {
20+
Logger.error(ex, 'ClearFileAnnotationsCommand');
21+
return window.showErrorMessage(`Unable to clear file annotations. See output channel for more details`);
22+
}
23+
}
24+
}

src/commands/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { ExplorerNode } from '../views/explorerNodes';
44
import { Logger } from '../logger';
55
import { Telemetry } from '../telemetry';
66

7-
export type Commands = 'gitlens.closeUnchangedFiles' |
7+
export type Commands =
8+
'gitlens.clearFileAnnotations' |
9+
'gitlens.closeUnchangedFiles' |
810
'gitlens.copyMessageToClipboard' |
911
'gitlens.copyShaToClipboard' |
1012
'gitlens.diffDirectory' |
@@ -43,6 +45,7 @@ export type Commands = 'gitlens.closeUnchangedFiles' |
4345
'gitlens.toggleFileRecentChanges' |
4446
'gitlens.toggleLineBlame';
4547
export const Commands = {
48+
ClearFileAnnotations: 'gitlens.clearFileAnnotations' as Commands,
4649
CloseUnchangedFiles: 'gitlens.closeUnchangedFiles' as Commands,
4750
CopyMessageToClipboard: 'gitlens.copyMessageToClipboard' as Commands,
4851
CopyShaToClipboard: 'gitlens.copyShaToClipboard' as Commands,

0 commit comments

Comments
 (0)