npm: adopt terminal quick fix api (#167664)
Fixes https://github.com/microsoft/vscode/issues/167588pull/167947/head
parent
6c1ad724ed
commit
dc83ca1951
|
@ -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",
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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",
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue