Skip to content

Commit 152a97d

Browse files
authored
Merge pull request #281266 from microsoft/benibenj/zoophagous-snake
Rename suggestion tweaks
2 parents 3c9c9c8 + c28fed5 commit 152a97d

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

src/vs/editor/contrib/inlineCompletions/browser/model/InlineSuggestAlternativeAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Command } from '../../../../common/languages.js';
77

88
export type InlineSuggestAlternativeAction = {
99
label: string;
10-
icon?: ThemeIcon;
10+
icon: ThemeIcon;
1111
command: Command;
1212
count: Promise<number>;
1313
};

src/vs/editor/contrib/inlineCompletions/browser/model/renameSymbolProcessor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { renameSymbolCommandId } from '../controller/commandIds.js';
2525
import { InlineSuggestionItem } from './inlineSuggestionItem.js';
2626
import { IInlineSuggestDataActionEdit } from './provideInlineCompletions.js';
2727
import { InlineSuggestAlternativeAction } from './InlineSuggestAlternativeAction.js';
28+
import { Codicon } from '../../../../../base/common/codicons.js';
2829

2930
enum RenameKind {
3031
no = 'no',
@@ -365,7 +366,7 @@ export class RenameSymbolProcessor extends Disposable {
365366

366367
// Check asynchronously if a rename is possible
367368
let timedOut = false;
368-
const check = await raceTimeout<RenameKind>(this.checkRenamePrecondition(suggestItem, textModel, position, oldName, newName), 1000, () => { timedOut = true; });
369+
const check = await raceTimeout<RenameKind>(this.checkRenamePrecondition(suggestItem, textModel, position, oldName, newName), 100, () => { timedOut = true; });
369370
const renamePossible = check === RenameKind.yes || check === RenameKind.maybe;
370371

371372
suggestItem.setRenameProcessingInfo({
@@ -404,7 +405,7 @@ export class RenameSymbolProcessor extends Disposable {
404405
};
405406
const alternativeAction: InlineSuggestAlternativeAction = {
406407
label: localize('rename', "Rename"),
407-
//icon: Codicon.replaceAll,
408+
icon: Codicon.replaceAll,
408409
command,
409410
count: runnable.getCount(),
410411
};

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/components/gutterIndicatorMenu.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { defaultKeybindingLabelStyles } from '../../../../../../../platform/them
2626
import { asCssVariable, descriptionForeground, editorActionListForeground, editorHoverBorder } from '../../../../../../../platform/theme/common/colorRegistry.js';
2727
import { ObservableCodeEditor } from '../../../../../../browser/observableCodeEditor.js';
2828
import { EditorOption } from '../../../../../../common/config/editorOptions.js';
29-
import { hideInlineCompletionId, inlineSuggestCommitId, toggleShowCollapsedId } from '../../../controller/commandIds.js';
29+
import { hideInlineCompletionId, inlineSuggestCommitAlternativeActionId, inlineSuggestCommitId, toggleShowCollapsedId } from '../../../controller/commandIds.js';
3030
import { FirstFnArg, } from '../utils/utils.js';
3131
import { InlineSuggestionGutterMenuData } from './gutterIndicatorView.js';
3232

@@ -81,6 +81,13 @@ export class GutterIndicatorMenuContent {
8181
commandId: hideInlineCompletionId
8282
}));
8383

84+
const alternativeCommand = this._data.alternativeAction ? option(createOptionArgs({
85+
id: 'alternativeCommand',
86+
title: this._data.alternativeAction.command.title,
87+
icon: this._data.alternativeAction.icon,
88+
commandId: inlineSuggestCommitAlternativeActionId,
89+
})) : undefined;
90+
8491
const extensionCommands = this._data.extensionCommands.map((c, idx) => option(createOptionArgs({
8592
id: c.command.id + '_' + idx,
8693
title: c.command.title,
@@ -148,6 +155,7 @@ export class GutterIndicatorMenuContent {
148155
return hoverContent([
149156
title,
150157
gotoAndAccept,
158+
alternativeCommand,
151159
reject,
152160
toggleCollapsedMode,
153161
modelOptions.length ? separator() : undefined,

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/components/gutterIndicatorView.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ export class InlineEditsGutterIndicatorData {
4646

4747
export class InlineSuggestionGutterMenuData {
4848
public static fromInlineSuggestion(suggestion: InlineSuggestionItem): InlineSuggestionGutterMenuData {
49+
const alternativeAction = suggestion.action?.kind === 'edit' ? suggestion.action.alternativeAction : undefined;
4950
return new InlineSuggestionGutterMenuData(
5051
suggestion.gutterMenuLinkAction,
5152
suggestion.source.provider.displayName ?? localize('inlineSuggestion', "Inline Suggestion"),
5253
suggestion.source.inlineSuggestions.commands ?? [],
54+
alternativeAction,
5355
suggestion.source.provider.modelInfo,
5456
suggestion.source.provider.setModelId?.bind(suggestion.source.provider),
5557
);
@@ -59,6 +61,7 @@ export class InlineSuggestionGutterMenuData {
5961
readonly action: Command | undefined,
6062
readonly displayName: string,
6163
readonly extensionCommands: InlineCompletionCommand[],
64+
readonly alternativeAction: InlineSuggestAlternativeAction | undefined,
6265
readonly modelInfo: IInlineCompletionModelInfo | undefined,
6366
readonly setModelId: ((modelId: string) => Promise<void>) | undefined,
6467
) { }

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/inlineEditsViews/inlineEditsWordReplacementView.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,15 @@ export class InlineEditsWordReplacementView extends Disposable implements IInlin
122122
const label = this._viewData.alternativeAction.label;
123123
const count = altCount.read(reader);
124124
const active = altModifierActive.read(reader);
125+
const occurrencesLabel = count !== undefined ? count === 1 ?
126+
localize('labelOccurence', "{0} 1 occurrence", label) :
127+
localize('labelOccurences', "{0} {1} occurrences", label, count)
128+
: label;
129+
const keybindingTooltip = localize('shiftToSeeOccurences', "{0} show occurrences", '[shift]');
125130
alternativeAction = {
126-
label: count !== undefined ? (active ? localize('labelOccurances', "{0} {1} occurrences", label, count) : label) : label,
127-
tooltip: count !== undefined ? localize('labelOccurances', "{0} {1} occurrences", label, count) : label,
128-
icon: this._viewData.alternativeAction.icon,
131+
label: count !== undefined ? (active ? occurrencesLabel : label) : label,
132+
tooltip: occurrencesLabel ? `${occurrencesLabel}\n${keybindingTooltip}` : undefined,
133+
icon: undefined, //this._viewData.alternativeAction.icon, Do not render icon fo the moment
129134
count,
130135
keybinding: this._keybindingService.lookupKeybinding(inlineSuggestCommitAlternativeActionId),
131136
active: altModifierActive,
@@ -290,7 +295,9 @@ export class InlineEditsWordReplacementView extends Disposable implements IInlin
290295
this._secondaryElement.set(elem, undefined);
291296
},
292297
ref: (elem) => {
293-
reader.store.add(this._hoverService.setupDelayedHoverAtMouse(elem, { content: altAction.tooltip, appearance: { compact: true } }));
298+
if (altAction.tooltip) {
299+
reader.store.add(this._hoverService.setupDelayedHoverAtMouse(elem, { content: altAction.tooltip, appearance: { compact: true } }));
300+
}
294301
}
295302
}, [
296303
keybinding,

0 commit comments

Comments
 (0)