Skip to content

Commit

Permalink
add CompletionItem#preselect, #35551
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 18, 2018
1 parent 5bde5c1 commit 62e0f34
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export interface ISuggestion {
documentation?: string | IMarkdownString;
filterText?: string;
sortText?: string;
autoSelect?: boolean;
preselect?: boolean;
noAutoAccept?: boolean;
commitCharacters?: string[];
overwriteBefore?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/suggest/suggestMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export abstract class Memory {
// stop when leaving the group of top matches
break;
}
if (suggestion.autoSelect) {
if (suggestion.preselect) {
// stop when seeing an auto-select-item
return i;
}
Expand Down
12 changes: 6 additions & 6 deletions src/vs/editor/contrib/suggest/test/suggestMemory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ suite('SuggestMemories', function () {
let item2 = createSuggestItem('bazz', 0);
let item3 = createSuggestItem('bazz', 0);
let item4 = createSuggestItem('bazz', 0);
item1.suggestion.autoSelect = false;
item2.suggestion.autoSelect = true;
item3.suggestion.autoSelect = true;
item1.suggestion.preselect = false;
item2.suggestion.preselect = true;
item3.suggestion.preselect = true;

assert.equal(mem.select(buffer, pos, [item1, item2, item3, item4]), 1);
});
Expand All @@ -57,9 +57,9 @@ suite('SuggestMemories', function () {
let item2 = createSuggestItem('bazz', 0);
let item3 = createSuggestItem('bazz', 0);
let item4 = createSuggestItem('bazz', 0);
item1.suggestion.autoSelect = false;
item2.suggestion.autoSelect = true;
item3.suggestion.autoSelect = true;
item1.suggestion.preselect = false;
item2.suggestion.preselect = true;
item3.suggestion.preselect = true;
let items = [item1, item2, item3, item4];


Expand Down
7 changes: 7 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3105,6 +3105,13 @@ declare module 'vscode' {
*/
filterText?: string;

/**
* Select this item when showing. *Note* that only one completion item can be selected and
* that the editor decides which item that is. The rule is that the *first* item of those
* that match best is selected.
*/
preselect?: boolean;

/**
* A string or snippet that should be inserted in a document when selecting
* this completion. When `falsy` the [label](#CompletionItem.label)
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/node/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ class SuggestAdapter {
documentation: item.documentation,
filterText: item.filterText,
sortText: item.sortText,
preselect: item.preselect,
//
insertText: undefined,
additionalTextEdits: item.additionalTextEdits && item.additionalTextEdits.map(typeConvert.TextEdit.from),
Expand Down
4 changes: 3 additions & 1 deletion src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,14 +1073,15 @@ export enum CompletionItemKind {
TypeParameter = 24
}

export class CompletionItem {
export class CompletionItem implements vscode.CompletionItem {

label: string;
kind: CompletionItemKind;
detail: string;
documentation: string | MarkdownString;
sortText: string;
filterText: string;
preselect: boolean;
insertText: string | SnippetString;
range: Range;
textEdit: TextEdit;
Expand All @@ -1100,6 +1101,7 @@ export class CompletionItem {
documentation: this.documentation,
sortText: this.sortText,
filterText: this.filterText,
preselect: this.preselect,
insertText: this.insertText,
textEdit: this.textEdit
};
Expand Down

0 comments on commit 62e0f34

Please sign in to comment.