Skip to content

Commit ad683fc

Browse files
committed
add source and description
1 parent e243427 commit ad683fc

File tree

7 files changed

+62
-16
lines changed

7 files changed

+62
-16
lines changed

src/vs/platform/actionWidget/browser/actionList.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as dom from 'vs/base/browser/dom';
6+
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
67
import { KeybindingLabel } from 'vs/base/browser/ui/keybindingLabel/keybindingLabel';
78
import { IListEvent, IListMouseEvent, IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
89
import { List } from 'vs/base/browser/ui/list/listWidget';
@@ -29,6 +30,7 @@ export interface IListMenuItem<T extends IActionItem> {
2930
group?: { kind?: any; icon?: { codicon: Codicon; color?: string }; title: string };
3031
disabled?: boolean;
3132
label?: string;
33+
description?: string;
3234
}
3335

3436
interface IActionMenuTemplateData {
@@ -131,6 +133,11 @@ class ActionItemRenderer<T extends IListMenuItem<IActionItem>> implements IListR
131133
} else {
132134
data.container.title = '';
133135
}
136+
if (element.description) {
137+
const label = new HighlightedLabel(dom.append(data.container, dom.$('span.label-description')));
138+
label.element.classList.add('action-list-description');
139+
label.set(element.description);
140+
}
134141
}
135142

136143
disposeTemplate(_templateData: IActionMenuTemplateData): void {

src/vs/platform/actionWidget/browser/actionWidget.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
.action-list-description {
7+
opacity: .7;
8+
margin-left: 0.5em;
9+
font-size: .9em;
10+
white-space: pre;
11+
}
12+
613
.action-widget {
714
font-size: 13px;
815
border-radius: 0;

src/vs/platform/terminal/common/xterm/terminalQuickFix.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export interface ITerminalQuickFixOptions {
2525
commandLineMatcher: string | RegExp;
2626
outputMatcher?: ITerminalOutputMatcher;
2727
exitStatus: boolean;
28+
extensionId?: string;
2829
}
2930

3031
export interface ITerminalQuickFix {
3132
type: 'command' | 'opener';
3233
id?: string;
34+
source: string;
3335
}
3436

3537
export interface ITerminalQuickFixCommandAction extends ITerminalQuickFix {
@@ -57,6 +59,7 @@ export type TerminalQuickFixCallback = (matchResult: ITerminalCommandMatchResult
5759
export type TerminalQuickFixCallbackExtension = (terminalCommand: ITerminalCommand, lines: string[] | undefined, option: ITerminalQuickFixOptions, token: CancellationToken) => Promise<ITerminalQuickFix[] | ITerminalQuickFix | undefined>;
5860

5961
export interface ITerminalQuickFixProvider {
62+
extensionId: string;
6063
/**
6164
* Provides terminal quick fixes
6265
* @param commandMatchResult The command match result for which to provide quick fixes
@@ -85,6 +88,7 @@ export interface IInternalOptions extends ITerminalQuickFixOptions {
8588
export interface IResolvedExtensionOptions extends ITerminalQuickFixOptions {
8689
type: 'resolved';
8790
getQuickFixes: TerminalQuickFixCallbackExtension;
91+
extensionId: string;
8892
}
8993

9094
export interface IUnresolvedExtensionOptions extends ITerminalQuickFixOptions {

src/vs/workbench/api/browser/mainThreadTerminalService.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
248248
this._profileProviders.delete(id);
249249
}
250250

251-
public async $registerQuickFixProvider(id: string): Promise<void> {
251+
public async $registerQuickFixProvider(id: string, extensionId: string): Promise<void> {
252252
this._quickFixProviders.set(id, this._terminalQuickFixService.registerQuickFixProvider(id,
253253
{
254+
extensionId,
254255
provideTerminalQuickFixes: async (terminalCommand: ITerminalCommand, lines: string[], option: ITerminalQuickFixOptions, token: CancellationToken) => {
255256
if (token.isCancellationRequested) {
256257
return;
@@ -274,7 +275,20 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
274275
const matchResult = { commandLineMatch, outputMatch, commandLine: terminalCommand.command };
275276

276277
if (matchResult) {
277-
return this._proxy.$provideTerminalQuickFixes(id, matchResult, token);
278+
const result = await this._proxy.$provideTerminalQuickFixes(id, matchResult, token);
279+
if (result && Array.isArray(result)) {
280+
return result.map(r => {
281+
return {
282+
source: extensionId,
283+
...r
284+
};
285+
});
286+
} else if (result) {
287+
return {
288+
source: extensionId,
289+
...result
290+
};
291+
}
278292
}
279293
return;
280294
}

src/vs/workbench/contrib/terminal/browser/terminalQuickFixBuiltinActions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export function gitSimilar(): IInternalOptions {
4343
id: 'Git Similar',
4444
type: TerminalQuickFixType.Command,
4545
terminalCommand: matchResult.commandLine.replace(/git\s+[^\s]+/, `git ${fixedCommand}`),
46-
addNewLine: true
46+
addNewLine: true,
47+
source: 'builtin'
4748
});
4849
}
4950
}
@@ -73,7 +74,8 @@ export function gitTwoDashes(): IInternalOptions {
7374
type: TerminalQuickFixType.Command,
7475
id: 'Git Two Dashes',
7576
terminalCommand: matchResult.commandLine.replace(` -${problemArg}`, ` --${problemArg}`),
76-
addNewLine: true
77+
addNewLine: true,
78+
source: 'builtin'
7779
};
7880
}
7981
};
@@ -146,7 +148,8 @@ export function gitPushSetUpstream(): IInternalOptions {
146148
type: 'command',
147149
id: 'Git Push Set Upstream',
148150
terminalCommand: fixedCommand,
149-
addNewLine: true
151+
addNewLine: true,
152+
source: 'builtin'
150153
});
151154
return actions;
152155
}

src/vs/workbench/contrib/terminal/browser/widgets/terminalQuickFixMenuItems.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export class TerminalQuickFix implements IActionItem {
2121
type: string;
2222
disabled?: boolean;
2323
title?: string;
24-
constructor(action: IAction, type: string, title?: string, disabled?: boolean) {
24+
source: string;
25+
constructor(action: IAction, type: string, source: string, title?: string, disabled?: boolean) {
2526
this.action = action;
2627
this.disabled = disabled;
2728
this.title = title;
29+
this.source = source;
2830
this.type = type;
2931
}
3032
}
@@ -50,7 +52,8 @@ export function toMenuItems(inputQuickFixes: readonly TerminalQuickFix[], showHe
5052
title: quickFix.action.label
5153
},
5254
disabled: false,
53-
label: quickFix.title
55+
label: quickFix.title,
56+
description: quickFix.source
5457
});
5558
}
5659
}

src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
6161

6262
private _commandListeners: Map<string, (ITerminalQuickFixOptions | IResolvedExtensionOptions | IUnresolvedExtensionOptions)[]> = new Map();
6363

64-
private _quickFixes: IAction[] | undefined;
64+
private _quickFixes: ITerminalAction[] | undefined;
6565

6666
private _decoration: IDecoration | undefined;
6767

@@ -259,8 +259,8 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
259259
height: rect.height
260260
};
261261
// TODO: What's documentation do? Need a vscode command?
262-
const documentation = fixes.map(f => { return { id: f.id, title: f.label, tooltip: f.tooltip }; });
263-
const actions = fixes.map(f => new TerminalQuickFix(f, f.class || TerminalQuickFixType.Command, f.label));
262+
const actions = fixes.map(f => new TerminalQuickFix(f, f.class || TerminalQuickFixType.Command, f.source, f.label));
263+
const documentation = fixes.map(f => { return { id: f.source, title: f.label, tooltip: f.source }; });
264264
const actionSet = {
265265
// TODO: Documentation and actions are separate?
266266
documentation,
@@ -294,17 +294,21 @@ export class TerminalQuickFixAddon extends Disposable implements ITerminalAddon,
294294
}
295295
}
296296

297+
export interface ITerminalAction extends IAction {
298+
source: string;
299+
}
300+
297301
export async function getQuickFixesForCommand(
298302
terminal: Terminal,
299303
terminalCommand: ITerminalCommand,
300304
quickFixOptions: Map<string, ITerminalQuickFixOptions[]>,
301305
openerService: IOpenerService,
302306
onDidRequestRerunCommand?: Emitter<{ command: string; addNewLine?: boolean }>,
303307
getResolvedFixes?: (selector: ITerminalQuickFixOptions, lines?: string[]) => Promise<ITerminalQuickFix | ITerminalQuickFix[] | undefined>
304-
): Promise<{ fixes: IAction[]; onDidRunQuickFix: Event<string>; expectedCommands?: string[] } | undefined> {
308+
): Promise<{ fixes: ITerminalAction[]; onDidRunQuickFix: Event<string>; expectedCommands?: string[] } | undefined> {
305309
const onDidRunQuickFixEmitter = new Emitter<string>();
306310
const onDidRunQuickFix = onDidRunQuickFixEmitter.event;
307-
const fixes: IAction[] = [];
311+
const fixes: ITerminalAction[] = [];
308312
const newCommand = terminalCommand.command;
309313
const expectedCommands = [];
310314
for (const options of quickFixOptions.values()) {
@@ -340,13 +344,14 @@ export async function getQuickFixesForCommand(
340344

341345
if (quickFixes) {
342346
for (const quickFix of asArray(quickFixes)) {
343-
let action: IAction | undefined;
347+
let action: ITerminalAction | undefined;
344348
if ('type' in quickFix) {
345349
switch (quickFix.type) {
346350
case TerminalQuickFixType.Command: {
347351
const fix = quickFix as ITerminalQuickFixCommandAction;
348352
const label = localize('quickFix.command', 'Run: {0}', fix.terminalCommand);
349353
action = {
354+
source: quickFix.source,
350355
id: quickFix.id,
351356
label,
352357
class: quickFix.type,
@@ -359,14 +364,15 @@ export async function getQuickFixesForCommand(
359364
},
360365
tooltip: label,
361366
command: fix.terminalCommand
362-
} as IAction;
367+
} as ITerminalAction;
363368
expectedCommands.push(fix.terminalCommand);
364369
break;
365370
}
366371
case TerminalQuickFixType.Opener: {
367372
const fix = quickFix as ITerminalQuickFixOpenerAction;
368373
const label = localize('quickFix.opener', 'Open: {0}', fix.uri.toString());
369374
action = {
375+
source: quickFix.source,
370376
id: quickFix.id,
371377
label,
372378
class: quickFix.type,
@@ -379,13 +385,14 @@ export async function getQuickFixesForCommand(
379385
},
380386
tooltip: label,
381387
uri: fix.uri
382-
} as IAction;
388+
} as ITerminalAction;
383389
break;
384390
}
385391
}
386392
} else {
387-
const fix = quickFix as IAction;
393+
const fix = quickFix as ITerminalAction;
388394
action = {
395+
source: 'builtin',
389396
id: fix.id,
390397
label: fix.label,
391398
class: fix.class,
@@ -415,5 +422,6 @@ function convertToQuickFixOptions(selectorProvider: ITerminalQuickFixProviderSel
415422
outputMatcher: selectorProvider.selector.outputMatcher,
416423
exitStatus: selectorProvider.selector.exitStatus,
417424
getQuickFixes: selectorProvider.provider.provideTerminalQuickFixes,
425+
extensionId: selectorProvider.provider.extensionId
418426
};
419427
}

0 commit comments

Comments
 (0)