npm: adopt terminal quick fix api (#167664)

Fixes https://github.com/microsoft/vscode/issues/167588
This commit is contained in:
Connor Peet 2022-12-02 08:20:53 -08:00 committed by GitHub
parent 6c1ad724ed
commit dc83ca1951
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 2 deletions

View file

@ -12,6 +12,9 @@
"categories": [
"Other"
],
"enabledApiProposals": [
"terminalQuickFixProvider"
],
"scripts": {
"compile": "gulp compile-extension:npm",
"watch": "gulp watch-extension:npm"
@ -334,7 +337,23 @@
},
"when": "shellExecutionSupported"
}
]
],
"terminal": {
"quickFixes": [
{
"id": "ms-vscode.npm-command",
"commandLineMatcher": "npm",
"exitStatus": false,
"outputMatcher": {
"anchor": "bottom",
"length": 8,
"lineMatcher": "Did you mean (?:this|one of these)\\?((?:\\n.+?npm .+ #.+)+)",
"offset": 2,
"multipleMatches": true
}
}
]
}
},
"repository": {
"type": "git",

View file

@ -70,6 +70,33 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
return '';
}));
context.subscriptions.push(new NpmScriptLensProvider());
context.subscriptions.push(vscode.window.registerTerminalQuickFixProvider('ms-vscode.npm-command', {
provideTerminalQuickFixes({ outputMatch }) {
if (!outputMatch) {
return;
}
const lines = outputMatch.regexMatch[1];
const fixes: vscode.TerminalQuickFixCommandAction[] = [];
for (const line of lines.split('\n')) {
// search from the second char, since the lines might be prefixed with
// "npm ERR!" which comes before the actual command suggestion.
const begin = line.indexOf('npm', 1);
if (begin === -1) {
continue;
}
const end = line.lastIndexOf('#');
fixes.push({
type: vscode.TerminalQuickFixType.command,
terminalCommand: line.slice(begin, end === -1 ? undefined : end - 1)
});
}
return fixes;
},
}));
}
async function getNPMCommandPath(): Promise<string | undefined> {

View file

@ -8,6 +8,7 @@
},
"include": [
"src/**/*",
"../../src/vscode-dts/vscode.d.ts"
"../../src/vscode-dts/vscode.d.ts",
"../../src/vscode-dts/vscode.proposed.terminalQuickFixProvider.d.ts",
]
}