Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@
"tags": [
"usesOnlineServices"
]
},
"npm.scriptHover": {
"type": "boolean",
"description": "%config.npm.scriptHover%",
"default": true,
"scope": "window"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions extensions/npm/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
13 changes: 13 additions & 0 deletions extensions/npm/src/scriptHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,29 @@ 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));
context.subscriptions.push(commands.registerCommand('npm.debugScriptFromHover', this.debugScriptFromHover, this));
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) {
Expand Down