Skip to content

Commit 2150470

Browse files
authored
🎁 Add option to disable script hovers in package.json files (microsoft#156752)
* βš™οΈ Define `npm.scriptHover` configuration parameter Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com> * 🌐 Add localized description for `npm.scriptHover` config parameter Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com> * 🎁 Respect `npm.scriptHover` config parameter in `NpmScriptHoverProvider` Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>
1 parent 59cd6e4 commit 2150470

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

β€Žextensions/npm/package.jsonβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@
298298
"tags": [
299299
"usesOnlineServices"
300300
]
301+
},
302+
"npm.scriptHover": {
303+
"type": "boolean",
304+
"description": "%config.npm.scriptHover%",
305+
"default": true,
306+
"scope": "window"
301307
}
302308
}
303309
},

β€Žextensions/npm/package.nls.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"config.npm.scriptExplorerExclude": "An array of regular expressions that indicate which scripts should be excluded from the NPM Scripts view.",
1616
"config.npm.enableRunFromFolder": "Enable running npm scripts contained in a folder from the Explorer context menu.",
1717
"config.npm.fetchOnlinePackageInfo": "Fetch data from https://registry.npmjs.org and https://registry.bower.io to provide auto-completion and information on hover features on npm dependencies.",
18+
"config.npm.scriptHover": "Display hover with 'Run' and 'Debug' commands for scripts.",
1819
"npm.parseError": "Npm task detection: failed to parse the file {0}",
1920
"taskdef.script": "The npm script to customize.",
2021
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",

β€Žextensions/npm/src/scriptHover.tsβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,29 @@ export function invalidateHoverScriptsCache(document?: TextDocument) {
3333
}
3434

3535
export class NpmScriptHoverProvider implements HoverProvider {
36+
private enabled: boolean;
3637

3738
constructor(private context: ExtensionContext) {
3839
context.subscriptions.push(commands.registerCommand('npm.runScriptFromHover', this.runScriptFromHover, this));
3940
context.subscriptions.push(commands.registerCommand('npm.debugScriptFromHover', this.debugScriptFromHover, this));
4041
context.subscriptions.push(workspace.onDidChangeTextDocument((e) => {
4142
invalidateHoverScriptsCache(e.document);
4243
}));
44+
45+
const isEnabled = () => workspace.getConfiguration('npm').get<boolean>('scriptHover', true);
46+
this.enabled = isEnabled();
47+
context.subscriptions.push(workspace.onDidChangeConfiguration((e) => {
48+
if (e.affectsConfiguration('npm.scriptHover')) {
49+
this.enabled = isEnabled();
50+
}
51+
}));
4352
}
4453

4554
public provideHover(document: TextDocument, position: Position, _token: CancellationToken): ProviderResult<Hover> {
55+
if (!this.enabled) {
56+
return;
57+
}
58+
4659
let hover: Hover | undefined = undefined;
4760

4861
if (!cachedDocument || cachedDocument.fsPath !== document.uri.fsPath) {

0 commit comments

Comments
Β (0)