diff --git a/extensions/npm/package.json b/extensions/npm/package.json index 5f39c6cd1b2..d87e2f1d016 100644 --- a/extensions/npm/package.json +++ b/extensions/npm/package.json @@ -40,10 +40,8 @@ "browser": "./dist/browser/npmBrowserMain", "activationEvents": [ "onTaskType:npm", - "onCommand:npm.runScriptFromFolder", "onLanguage:json", - "workspaceContains:package.json", - "onView:npm" + "workspaceContains:package.json" ], "capabilities": { "virtualWorkspaces": { @@ -341,8 +339,7 @@ "when": "shellExecutionSupported" } ], - "terminal": { - "quickFixes": [ + "terminalQuickFixes": [ { "id": "ms-vscode.npm-command", "commandLineMatcher": "npm", @@ -355,7 +352,6 @@ } } ] - } }, "repository": { "type": "git", diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 7892cd8f582..dd90c56776c 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -11,8 +11,6 @@ import { IPtyHostProcessReplayEvent, ISerializedCommandDetectionCapability, ITer import { IGetTerminalLayoutInfoArgs, IProcessDetails, ISetTerminalLayoutInfoArgs } from 'vs/platform/terminal/common/terminalProcess'; import { ThemeIcon } from 'vs/base/common/themables'; import { ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable'; -import { ITerminalCommandSelector } from 'vs/platform/terminal/common/xterm/terminalQuickFix'; - export const enum TerminalSettingPrefix { Shell = 'terminal.integrated.shell.', @@ -844,7 +842,6 @@ export interface IShellIntegration { export interface ITerminalContributions { profiles?: ITerminalProfileContribution[]; - quickFixes?: ITerminalCommandSelector[]; } export const enum ShellIntegrationStatus { diff --git a/src/vs/workbench/contrib/terminal/browser/terminalQuickFixService.ts b/src/vs/workbench/contrib/terminal/browser/terminalQuickFixService.ts index bfb26f0af28..4fec8ef769f 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalQuickFixService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalQuickFixService.ts @@ -25,7 +25,7 @@ export class TerminalQuickFixService implements ITerminalQuickFixService { readonly onDidUnregisterProvider = this._onDidUnregisterProvider.event; constructor(@ITerminalContributionService private readonly _terminalContributionService: ITerminalContributionService) { - this._terminalContributionService.quickFixes.then(selectors => { + this._terminalContributionService.terminalQuickFixes.then(selectors => { for (const selector of selectors) { this.registerCommandSelector(selector); } @@ -42,7 +42,7 @@ export class TerminalQuickFixService implements ITerminalQuickFixService { // IDisposable synchronously but we must await ITerminalContributionService.quickFixes // asynchronously before actually registering the provider. let disposed = false; - this._terminalContributionService.quickFixes.then(() => { + this._terminalContributionService.terminalQuickFixes.then(() => { if (disposed) { return; } diff --git a/src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts b/src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts index 32b0717c125..3b374527e54 100644 --- a/src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts +++ b/src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts @@ -93,7 +93,7 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon, })); } this._register(this._quickFixService.onDidRegisterProvider(result => this.registerCommandFinishedListener(convertToQuickFixOptions(result)))); - terminalContributionService.quickFixes.then(quickFixSelectors => { + terminalContributionService.terminalQuickFixes.then(quickFixSelectors => { for (const selector of quickFixSelectors) { this.registerCommandSelector(selector); } diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 8fe584d95e9..fef77887bdb 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -739,73 +739,12 @@ export const terminalContributionsDescriptor: IExtensionPointDescriptor[^\s]+)/;`\n\n`terminalCommand: 'git push --set-upstream origin ${group:branchName}';`\n"), - type: 'object', - required: ['lineMatcher', 'anchor', 'offset', 'length'], - properties: { - lineMatcher: { - description: 'A regular expression or string to test the command line against', - type: 'string' - }, - anchor: { - description: 'Where the search should begin in the buffer', - enum: ['top', 'bottom'] - }, - offset: { - description: 'The number of lines vertically from the anchor in the buffer to start matching against', - type: 'number' - }, - length: { - description: 'The number of rows to match against, this should be as small as possible for performance reasons', - type: 'number' - } - } - }, - commandExitResult: { - description: nls.localize('vscode.extension.contributes.terminal.quickFixes.commandExitResult', "The command exit result to match on"), - enum: ['success', 'error'], - enumDescriptions: [ - 'The command exited with an exit code of zero.', - 'The command exited with a non-zero exit code.' - ] - } - }, - } - }, profiles: { type: 'array', description: nls.localize('vscode.extension.contributes.terminal.profiles', "Defines additional terminal profiles that the user can create."), @@ -852,3 +791,71 @@ export const terminalContributionsDescriptor: IExtensionPointDescriptor = { + extensionPoint: 'terminalQuickFixes', + defaultExtensionKind: ['workspace'], + activationEventsGenerator: (terminalQuickFixes: ITerminalCommandSelector[], result: { push(item: string): void }) => { + for (const quickFixContrib of terminalQuickFixes ?? []) { + result.push(`onTerminalQuickFixRequest:${quickFixContrib.id}`); + } + }, + jsonSchema: { + description: nls.localize('vscode.extension.contributes.terminalQuickFixes', 'Contributes terminal quick fixes.'), + type: 'array', + items: { + type: 'object', + additionalProperties: false, + required: ['id', 'commandLineMatcher', 'outputMatcher', 'commandExitResult'], + defaultSnippets: [{ + body: { + id: '$1', + commandLineMatcher: '$2', + outputMatcher: '$3', + exitStatus: '$4' + } + }], + properties: { + id: { + description: nls.localize('vscode.extension.contributes.terminalQuickFixes.id', "The ID of the quick fix provider"), + type: 'string', + }, + commandLineMatcher: { + description: nls.localize('vscode.extension.contributes.terminalQuickFixes.commandLineMatcher', "A regular expression or string to test the command line against"), + type: 'string', + }, + outputMatcher: { + markdownDescription: nls.localize('vscode.extension.contributes.terminalQuickFixes.outputMatcher', "A regular expression or string to test the output against, which provides groups to be referenced in terminalCommand and uri.\n\nFor example:\n\n `lineMatcher: /git push --set-upstream origin (?[^\s]+)/;`\n\n`terminalCommand: 'git push --set-upstream origin ${group:branchName}';`\n"), + type: 'object', + required: ['lineMatcher', 'anchor', 'offset', 'length'], + properties: { + lineMatcher: { + description: 'A regular expression or string to test the command line against', + type: 'string' + }, + anchor: { + description: 'Where the search should begin in the buffer', + enum: ['top', 'bottom'] + }, + offset: { + description: 'The number of lines vertically from the anchor in the buffer to start matching against', + type: 'number' + }, + length: { + description: 'The number of rows to match against, this should be as small as possible for performance reasons', + type: 'number' + } + } + }, + commandExitResult: { + description: nls.localize('vscode.extension.contributes.terminalQuickFixes.commandExitResult', "The command exit result to match on"), + enum: ['success', 'error'], + enumDescriptions: [ + 'The command exited with an exit code of zero.', + 'The command exited with a non-zero exit code.' + ] + } + }, + } + }, +}; diff --git a/src/vs/workbench/contrib/terminal/common/terminalExtensionPoints.ts b/src/vs/workbench/contrib/terminal/common/terminalExtensionPoints.ts index c55a24c8323..9d288ff8acd 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalExtensionPoints.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalExtensionPoints.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as extensionsRegistry from 'vs/workbench/services/extensions/common/extensionsRegistry'; -import { terminalContributionsDescriptor } from 'vs/workbench/contrib/terminal/common/terminal'; +import { terminalContributionsDescriptor, terminalQuickFixesContributionsDescriptor } from 'vs/workbench/contrib/terminal/common/terminal'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IExtensionTerminalProfile, ITerminalContributions, ITerminalProfileContribution } from 'vs/platform/terminal/common/terminal'; import { URI } from 'vs/base/common/uri'; @@ -13,12 +13,13 @@ import { ITerminalCommandSelector } from 'vs/platform/terminal/common/xterm/term // terminal extension point const terminalsExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint(terminalContributionsDescriptor); +const terminalQuickFixesExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint(terminalQuickFixesContributionsDescriptor); export interface ITerminalContributionService { readonly _serviceBrand: undefined; readonly terminalProfiles: ReadonlyArray; - readonly quickFixes: Promise>; + readonly terminalQuickFixes: Promise>; } export const ITerminalContributionService = createDecorator('terminalContributionsService'); @@ -29,18 +30,20 @@ export class TerminalContributionService implements ITerminalContributionService private _terminalProfiles: ReadonlyArray = []; get terminalProfiles() { return this._terminalProfiles; } - quickFixes: Promise>; + terminalQuickFixes: Promise>; constructor() { - this.quickFixes = new Promise((r) => terminalsExtPoint.setHandler(contributions => { + this.terminalQuickFixes = new Promise((r) => terminalQuickFixesExtPoint.setHandler(fixes => { + const quickFixes = (fixes.filter(c => isProposedApiEnabled(c.description, 'terminalQuickFixProvider')).map(c => c.value ? c.value.map(fix => { return { ...fix, extensionIdentifier: c.description.identifier.value }; }) : [])).flat(); + r(quickFixes); + })); + terminalsExtPoint.setHandler(contributions => { this._terminalProfiles = contributions.map(c => { return c.value?.profiles?.filter(p => hasValidTerminalIcon(p)).map(e => { return { ...e, extensionIdentifier: c.description.identifier.value }; }) || []; }).flat(); - const quickFixes = (contributions.filter(c => isProposedApiEnabled(c.description, 'terminalQuickFixProvider')).map(c => c.value.quickFixes ? c.value.quickFixes.map(fix => { return { ...fix, extensionIdentifier: c.description.identifier.value }; }) : [])).flat(); - r(quickFixes); - })); + }); } } diff --git a/src/vs/workbench/contrib/terminal/test/browser/quickFixAddon.test.ts b/src/vs/workbench/contrib/terminal/test/browser/quickFixAddon.test.ts index ab2cfe1c7a4..ec6f9b8a418 100644 --- a/src/vs/workbench/contrib/terminal/test/browser/quickFixAddon.test.ts +++ b/src/vs/workbench/contrib/terminal/test/browser/quickFixAddon.test.ts @@ -46,7 +46,7 @@ suite('QuickFixAddon', () => { rows: 30 }); instantiationService.stub(IStorageService, new TestStorageService()); - instantiationService.stub(ITerminalContributionService, { quickFixes: Promise.resolve([]) } as Partial); + instantiationService.stub(ITerminalContributionService, { terminalQuickFixes: Promise.resolve([]) } as Partial); instantiationService.stub(ITerminalQuickFixService, { onDidRegisterProvider: new Emitter().event, onDidUnregisterProvider: new Emitter().event, onDidRegisterCommandSelector: new Emitter().event } as Partial); instantiationService.stub(IConfigurationService, new TestConfigurationService()); instantiationService.stub(ILabelService, {} as Partial); diff --git a/src/vs/workbench/contrib/terminal/test/browser/terminalProfileService.integrationTest.ts b/src/vs/workbench/contrib/terminal/test/browser/terminalProfileService.integrationTest.ts index c889388f825..7a65ff5dc58 100644 --- a/src/vs/workbench/contrib/terminal/test/browser/terminalProfileService.integrationTest.ts +++ b/src/vs/workbench/contrib/terminal/test/browser/terminalProfileService.integrationTest.ts @@ -90,7 +90,7 @@ class TestTerminalExtensionService extends TestExtensionService { class TestTerminalContributionService implements ITerminalContributionService { _serviceBrand: undefined; terminalProfiles: readonly IExtensionTerminalProfile[] = []; - quickFixes: Promise = Promise.resolve([]); + terminalQuickFixes: Promise = Promise.resolve([]); setProfiles(profiles: IExtensionTerminalProfile[]): void { this.terminalProfiles = profiles; }