🎁 Add option to disable script hovers in package.json files (#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>
This commit is contained in:
Babak K. Shandiz 2022-08-01 21:13:31 +04:30 committed by GitHub
parent 59cd6e48d8
commit 2150470804
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -298,6 +298,12 @@
"tags": [
"usesOnlineServices"
]
},
"npm.scriptHover": {
"type": "boolean",
"description": "%config.npm.scriptHover%",
"default": true,
"scope": "window"
}
}
},

View file

@ -15,6 +15,7 @@
"config.npm.scriptExplorerExclude": "An array of regular expressions that indicate which scripts should be excluded from the NPM Scripts view.",
"config.npm.enableRunFromFolder": "Enable running npm scripts contained in a folder from the Explorer context menu.",
"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.",
"config.npm.scriptHover": "Display hover with 'Run' and 'Debug' commands for scripts.",
"npm.parseError": "Npm task detection: failed to parse the file {0}",
"taskdef.script": "The npm script to customize.",
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",

View file

@ -33,6 +33,7 @@ export function invalidateHoverScriptsCache(document?: TextDocument) {
}
export class NpmScriptHoverProvider implements HoverProvider {
private enabled: boolean;
constructor(private context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand('npm.runScriptFromHover', this.runScriptFromHover, this));
@ -40,9 +41,21 @@ export class NpmScriptHoverProvider implements HoverProvider {
context.subscriptions.push(workspace.onDidChangeTextDocument((e) => {
invalidateHoverScriptsCache(e.document);
}));
const isEnabled = () => workspace.getConfiguration('npm').get<boolean>('scriptHover', true);
this.enabled = isEnabled();
context.subscriptions.push(workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('npm.scriptHover')) {
this.enabled = isEnabled();
}
}));
}
public provideHover(document: TextDocument, position: Position, _token: CancellationToken): ProviderResult<Hover> {
if (!this.enabled) {
return;
}
let hover: Hover | undefined = undefined;
if (!cachedDocument || cachedDocument.fsPath !== document.uri.fsPath) {