mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
parent
04dc8ba26a
commit
6877e7d265
|
@ -59,7 +59,7 @@ import { IDetectedLinks, TerminalLinkManager } from 'vs/workbench/contrib/termin
|
|||
import { TerminalLinkQuickpick } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkQuickpick';
|
||||
import { IRequestAddInstanceToGroupEvent, ITerminalExternalLinkProvider, ITerminalInstance, TerminalDataTransfers } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { TerminalLaunchHelpAction } from 'vs/workbench/contrib/terminal/browser/terminalActions';
|
||||
import { freePort, gitCreatePr, gitPushSetUpstream, gitSimilar, gitTwoDashes, pwshGeneralCommandErrorFeedback as pwshGeneralCommandError } from 'vs/workbench/contrib/terminal/browser/terminalQuickFixBuiltinActions';
|
||||
import { freePort, gitCreatePr, gitPushSetUpstream, gitSimilar, gitTwoDashes, pwshGeneralError as pwshGeneralError, pwshUnixCommandNotFoundError } from 'vs/workbench/contrib/terminal/browser/terminalQuickFixBuiltinActions';
|
||||
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminalConfigHelper';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { TerminalFindWidget } from 'vs/workbench/contrib/terminal/browser/terminalFindWidget';
|
||||
|
@ -739,11 +739,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
|
|||
this._quickFixAddon = this._scopedInstantiationService.createInstance(TerminalQuickFixAddon, this._aliases, this.capabilities);
|
||||
this.xterm?.raw.loadAddon(this._quickFixAddon);
|
||||
this._registerQuickFixProvider(this._quickFixAddon, gitTwoDashes(), freePort(this), gitSimilar(), gitPushSetUpstream(), gitCreatePr());
|
||||
|
||||
if ((this.os || OS) === OperatingSystem.Linux) {
|
||||
// this.registerQuickFixProvider(pwshUnixCommandNotFound);
|
||||
} else {
|
||||
this._registerQuickFixProvider(this._quickFixAddon, pwshGeneralCommandError());
|
||||
this._registerQuickFixProvider(this._quickFixAddon, pwshUnixCommandNotFoundError());
|
||||
// Avoid the general provide on Linux as the unix command not found error provider is
|
||||
// generally preferable.
|
||||
if ((this.os || OS) !== OperatingSystem.Linux) {
|
||||
this._registerQuickFixProvider(this._quickFixAddon, pwshGeneralError());
|
||||
}
|
||||
this._register(this._quickFixAddon.onDidRequestRerunCommand(async (e) => await this.runCommand(e.command, e.addNewLine || false)));
|
||||
this.updateAccessibilitySupport();
|
||||
|
|
|
@ -194,9 +194,9 @@ export function gitCreatePr(): IInternalOptions {
|
|||
};
|
||||
}
|
||||
|
||||
export function pwshGeneralCommandErrorFeedback(): IInternalOptions {
|
||||
export function pwshGeneralError(): IInternalOptions {
|
||||
return {
|
||||
id: 'Pwsh General Command Error Feedback',
|
||||
id: 'Pwsh General Error',
|
||||
type: 'internal',
|
||||
commandLineMatcher: /.+/,
|
||||
outputMatcher: {
|
||||
|
@ -225,3 +225,58 @@ export function pwshGeneralCommandErrorFeedback(): IInternalOptions {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function pwshUnixCommandNotFoundError(): IInternalOptions {
|
||||
return {
|
||||
id: 'Unix Command Not Found',
|
||||
type: 'internal',
|
||||
commandLineMatcher: /.+/,
|
||||
outputMatcher: {
|
||||
lineMatcher: /^Suggestion \[cmd-not-found\]:/,
|
||||
anchor: 'bottom',
|
||||
offset: 0,
|
||||
length: 10
|
||||
},
|
||||
commandExitResult: 'error',
|
||||
getQuickFixes: (matchResult: ITerminalCommandMatchResult) => {
|
||||
const lines = matchResult.outputMatch?.regexMatch.input?.split('\n');
|
||||
if (!lines) {
|
||||
return;
|
||||
}
|
||||
const result: ITerminalQuickFixCommandAction[] = [];
|
||||
|
||||
// Always remove the first element as it's the "Suggestion [cmd-not-found]"" line
|
||||
let inSuggestions = false;
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
const line = lines[i].trim();
|
||||
if (line.length === 0) {
|
||||
break;
|
||||
}
|
||||
const installCommand = line.match(/You also have .+ installed, you can run '(?<command>.+)' instead./)?.groups?.command;
|
||||
if (installCommand) {
|
||||
result.push({
|
||||
id: 'Pwsh Unix Command Not Found Error',
|
||||
type: TerminalQuickFixType.Command,
|
||||
terminalCommand: installCommand,
|
||||
source: QuickFixSource.Builtin
|
||||
});
|
||||
inSuggestions = false;
|
||||
continue;
|
||||
}
|
||||
if (line.match(/Command '.+' not found, but can be installed with:/)) {
|
||||
inSuggestions = true;
|
||||
continue;
|
||||
}
|
||||
if (inSuggestions) {
|
||||
result.push({
|
||||
id: 'Pwsh Unix Command Not Found Error',
|
||||
type: TerminalQuickFixType.Command,
|
||||
terminalCommand: line.trim(),
|
||||
source: QuickFixSource.Builtin
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue