mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
🎁 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:
parent
59cd6e48d8
commit
2150470804
|
@ -298,6 +298,12 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"usesOnlineServices"
|
"usesOnlineServices"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"npm.scriptHover": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "%config.npm.scriptHover%",
|
||||||
|
"default": true,
|
||||||
|
"scope": "window"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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.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.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.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}",
|
"npm.parseError": "Npm task detection: failed to parse the file {0}",
|
||||||
"taskdef.script": "The npm script to customize.",
|
"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.",
|
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",
|
||||||
|
|
|
@ -33,6 +33,7 @@ export function invalidateHoverScriptsCache(document?: TextDocument) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NpmScriptHoverProvider implements HoverProvider {
|
export class NpmScriptHoverProvider implements HoverProvider {
|
||||||
|
private enabled: boolean;
|
||||||
|
|
||||||
constructor(private context: ExtensionContext) {
|
constructor(private context: ExtensionContext) {
|
||||||
context.subscriptions.push(commands.registerCommand('npm.runScriptFromHover', this.runScriptFromHover, this));
|
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) => {
|
context.subscriptions.push(workspace.onDidChangeTextDocument((e) => {
|
||||||
invalidateHoverScriptsCache(e.document);
|
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> {
|
public provideHover(document: TextDocument, position: Position, _token: CancellationToken): ProviderResult<Hover> {
|
||||||
|
if (!this.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let hover: Hover | undefined = undefined;
|
let hover: Hover | undefined = undefined;
|
||||||
|
|
||||||
if (!cachedDocument || cachedDocument.fsPath !== document.uri.fsPath) {
|
if (!cachedDocument || cachedDocument.fsPath !== document.uri.fsPath) {
|
||||||
|
|
Loading…
Reference in a new issue