Skip to content

Commit 8bec045

Browse files
committed
rename suggestions: migrate to using list widget
1 parent 07446f6 commit 8bec045

File tree

13 files changed

+506
-126
lines changed

13 files changed

+506
-126
lines changed

src/vs/editor/common/languages.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,17 @@ export interface RenameProvider {
16521652
resolveRenameLocation?(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<RenameLocation & Rejection>;
16531653
}
16541654

1655+
export enum NewSymbolNameTag {
1656+
AIGenerated = 1
1657+
}
1658+
1659+
export interface NewSymbolName {
1660+
readonly newSymbolName: string;
1661+
readonly tags?: readonly NewSymbolNameTag[];
1662+
}
1663+
16551664
export interface NewSymbolNamesProvider {
1656-
provideNewSymbolNames(model: model.ITextModel, range: IRange, token: CancellationToken): ProviderResult<string[]>;
1665+
provideNewSymbolNames(model: model.ITextModel, range: IRange, token: CancellationToken): ProviderResult<NewSymbolName[]>;
16571666
}
16581667

16591668
export interface Command {

src/vs/editor/common/standalone/standaloneEnums.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ export enum MouseTargetType {
702702
OUTSIDE_EDITOR = 13
703703
}
704704

705+
export enum NewSymbolNameTag {
706+
AIGenerated = 1
707+
}
708+
705709
/**
706710
* A positioning preference for rendering overlay widgets.
707711
*/

src/vs/editor/contrib/rename/browser/rename.ts

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
1111
import { DisposableStore } from 'vs/base/common/lifecycle';
1212
import { assertType } from 'vs/base/common/types';
1313
import { URI } from 'vs/base/common/uri';
14-
import { CodeEditorStateFlag, EditorStateCancellationTokenSource } from 'vs/editor/contrib/editorState/browser/editorState';
1514
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
16-
import { EditorAction, EditorCommand, EditorContributionInstantiation, registerEditorAction, registerEditorCommand, registerEditorContribution, registerModelAndPositionCommand, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
15+
import { EditorAction, EditorCommand, EditorContributionInstantiation, ServicesAccessor, registerEditorAction, registerEditorCommand, registerEditorContribution, registerModelAndPositionCommand } from 'vs/editor/browser/editorExtensions';
1716
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
1817
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
1918
import { IPosition, Position } from 'vs/editor/common/core/position';
2019
import { Range } from 'vs/editor/common/core/range';
2120
import { IEditorContribution } from 'vs/editor/common/editorCommon';
2221
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
22+
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
23+
import { NewSymbolName, Rejection, RenameLocation, RenameProvider, WorkspaceEdit } from 'vs/editor/common/languages';
2324
import { ITextModel } from 'vs/editor/common/model';
24-
import { Rejection, RenameLocation, RenameProvider, WorkspaceEdit } from 'vs/editor/common/languages';
25+
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
2526
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfiguration';
27+
import { CodeEditorStateFlag, EditorStateCancellationTokenSource } from 'vs/editor/contrib/editorState/browser/editorState';
2628
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
2729
import * as nls from 'vs/nls';
30+
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
2831
import { ConfigurationScope, Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
2932
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
3033
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -33,9 +36,7 @@ import { ILogService } from 'vs/platform/log/common/log';
3336
import { INotificationService } from 'vs/platform/notification/common/notification';
3437
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
3538
import { Registry } from 'vs/platform/registry/common/platform';
36-
import { CONTEXT_RENAME_INPUT_VISIBLE, RenameInputField } from './renameInputField';
37-
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
38-
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
39+
import { CONTEXT_RENAME_INPUT_FOCUSED, CONTEXT_RENAME_INPUT_VISIBLE, RenameInputField } from './renameInputField';
3940

4041
class RenameSkeleton {
4142

@@ -213,7 +214,7 @@ class RenameController implements IEditorContribution {
213214
this._languageFeaturesService.newSymbolNamesProvider
214215
.all(model)
215216
.map(provider => provider.provideNewSymbolNames(model, loc.range, cts2.token)) // TODO@ulugbekna: make sure this works regardless if the result is then-able
216-
).then((candidates) => candidates.filter((c): c is string[] => !!c).flat());
217+
).then((candidates) => candidates.filter((c): c is NewSymbolName[] => !!c).flat());
217218

218219
const selection = this.editor.getSelection();
219220
let selectionStart = 0;
@@ -288,6 +289,14 @@ class RenameController implements IEditorContribution {
288289
cancelRenameInput(): void {
289290
this._renameInputField.cancelInput(true);
290291
}
292+
293+
focusNextRenameSuggestion(): void {
294+
this._renameInputField.focusNextRenameSuggestion();
295+
}
296+
297+
focusPreviousRenameSuggestion(): void {
298+
this._renameInputField.focusPreviousRenameSuggestion();
299+
}
291300
}
292301

293302
// ---- action implementation
@@ -380,6 +389,76 @@ registerEditorCommand(new RenameCommand({
380389
}
381390
}));
382391

392+
registerAction2(class FocusNextRenameSuggestion extends Action2 {
393+
constructor() {
394+
super({
395+
id: 'focusNextRenameSuggestion',
396+
title: {
397+
...nls.localize2('focusNextRenameSuggestion', "Focus Next Rename Suggestion"),
398+
},
399+
precondition: CONTEXT_RENAME_INPUT_VISIBLE,
400+
keybinding: [
401+
{
402+
when: CONTEXT_RENAME_INPUT_FOCUSED,
403+
primary: KeyCode.Tab,
404+
weight: KeybindingWeight.EditorContrib + 99,
405+
},
406+
{
407+
when: CONTEXT_RENAME_INPUT_FOCUSED.toNegated(),
408+
primary: KeyCode.Tab,
409+
secondary: [KeyCode.DownArrow],
410+
weight: KeybindingWeight.EditorContrib + 99,
411+
}
412+
]
413+
});
414+
}
415+
416+
override run(accessor: ServicesAccessor): void {
417+
const currentEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
418+
if (!currentEditor) { return; }
419+
420+
const controller = RenameController.get(currentEditor);
421+
if (!controller) { return; }
422+
423+
controller.focusNextRenameSuggestion();
424+
}
425+
});
426+
427+
registerAction2(class FocusPreviousRenameSuggestion extends Action2 {
428+
constructor() {
429+
super({
430+
id: 'focusPreviousRenameSuggestion',
431+
title: {
432+
...nls.localize2('focusPreviousRenameSuggestion', "Focus Previous Rename Suggestion"),
433+
},
434+
precondition: CONTEXT_RENAME_INPUT_VISIBLE,
435+
keybinding: [
436+
{
437+
when: CONTEXT_RENAME_INPUT_FOCUSED,
438+
primary: KeyCode.Tab | KeyCode.Shift,
439+
weight: KeybindingWeight.EditorContrib + 99,
440+
},
441+
{
442+
when: CONTEXT_RENAME_INPUT_FOCUSED.toNegated(),
443+
primary: KeyMod.Shift | KeyCode.Tab,
444+
secondary: [KeyCode.UpArrow],
445+
weight: KeybindingWeight.EditorContrib + 99,
446+
}
447+
]
448+
});
449+
}
450+
451+
override run(accessor: ServicesAccessor): void {
452+
const currentEditor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
453+
if (!currentEditor) { return; }
454+
455+
const controller = RenameController.get(currentEditor);
456+
if (!controller) { return; }
457+
458+
controller.focusPreviousRenameSuggestion();
459+
}
460+
});
461+
383462
// ---- api bridge command
384463

385464
registerModelAndPositionCommand('_executeDocumentRenameProvider', function (accessor, model, position, ...args) {

src/vs/editor/contrib/rename/browser/renameInputField.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@
2424
opacity: .8;
2525
}
2626

27-
.rename-box .new-name-candidates-container {
28-
display: flex;
29-
flex-direction: row;
30-
flex-wrap: wrap;
31-
margin-top: 5px;
32-
}
33-
34-
.rename-box .new-name-candidates-container > .monaco-text-button {
35-
width: auto;
36-
margin: 2px;
37-
padding: 2px;
38-
}
39-
4027
.monaco-editor .rename-box.preview .rename-label {
4128
display: inherit;
4229
}

0 commit comments

Comments
 (0)