Skip to content

Commit 596c176

Browse files
committed
fix: don't show clear lens command when not available
Fixes #57
1 parent d1143fd commit 596c176

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/vscode-js-profile-core/src/profileCodeLensProvider.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
import {
66
CodeLens,
7+
CodeLensProvider,
8+
commands,
79
Disposable,
810
EventEmitter,
9-
CodeLensProvider,
10-
TextDocument,
1111
ProviderResult,
12+
TextDocument,
1213
} from 'vscode';
13-
import { lowerCaseInsensitivePath } from './path';
1414
import { DownloadFileProvider } from './download-file-provider';
15+
import { lowerCaseInsensitivePath } from './path';
1516
import { ProfileAnnotations } from './profileAnnotations';
1617

1718
/**
@@ -31,13 +32,13 @@ export class ProfileCodeLensProvider implements CodeLensProvider {
3132
*/
3233
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3334
public registerLenses(lenses: ProfileAnnotations): Disposable {
35+
commands.executeCommand('setContext', 'jsProfileVisualizer.hasCodeLenses', true);
3436
this.lenses = lenses;
3537

3638
return {
3739
dispose: () => {
3840
if (this.lenses === lenses) {
39-
this.lenses = undefined;
40-
this.changeEmitter.fire();
41+
this.clear();
4142
}
4243
},
4344
};
@@ -47,8 +48,11 @@ export class ProfileCodeLensProvider implements CodeLensProvider {
4748
* Clears the current set of profiling lenses.
4849
*/
4950
public clear() {
50-
this.lenses = undefined;
51-
this.changeEmitter.fire();
51+
if (this.lenses) {
52+
this.lenses = undefined;
53+
commands.executeCommand('setContext', 'jsProfileVisualizer.hasCodeLenses', false);
54+
this.changeEmitter.fire();
55+
}
5256
}
5357

5458
/**

packages/vscode-js-profile-table/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@
5858
"command": "extension.jsProfileVisualizer.table.clearCodeLenses",
5959
"title": "Clear Profile Code Lenses"
6060
}
61-
]
61+
],
62+
"menus": {
63+
"commandPalette": [
64+
{
65+
"command": "extension.jsProfileVisualizer.table.clearCodeLenses",
66+
"when": "jsProfileVisualizer.hasCodeLenses == true"
67+
}
68+
]
69+
}
6270
},
6371
"bugs": {
6472
"url": "https://github.com/microsoft/vscode-js-profile-visualizer/issues"

0 commit comments

Comments
 (0)