Skip to content

Commit

Permalink
use label, detail, and description for CompletionItemLabel, tweak ren…
Browse files Browse the repository at this point in the history
…dering, #39441
  • Loading branch information
jrieken committed Jun 22, 2021
1 parent 9cfc4bc commit a2c4a0c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 69 deletions.
22 changes: 3 additions & 19 deletions src/vs/editor/common/modes.ts
Expand Up @@ -487,25 +487,9 @@ export let completionKindFromString: {
})();

export interface CompletionItemLabel {
/**
* The function or variable. Rendered leftmost.
*/
name: string;

/**
* The parameters without the return type. Render after `name`.
*/
signature?: string;

/**
* The fully qualified name, like package name or file path. Rendered after `signature`.
*/
qualifier?: string;

/**
* The return-type of a function or type of a property/variable. Rendered rightmost.
*/
type?: string;
label: string;
detail?: string;
description?: string;
}

export const enum CompletionItemTag {
Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/contrib/suggest/media/suggest.css
Expand Up @@ -166,9 +166,9 @@
}

.monaco-editor .suggest-widget .monaco-list .monaco-list-row>.contents>.main>.left>.qualifier-label {
margin-left: 4px;
margin-left: 12px;
opacity: 0.4;
font-size: 90%;
font-size: 85%;
line-height: initial;
text-overflow: ellipsis;
overflow: hidden;
Expand All @@ -178,6 +178,7 @@
/** Type Info and icon next to the label in the focused completion item **/

.monaco-editor .suggest-widget .monaco-list .monaco-list-row>.contents>.main>.right>.details-label {
font-size: 85%;
margin-left: 1.1em;
overflow: hidden;
text-overflow: ellipsis;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/suggest/suggest.ts
Expand Up @@ -74,7 +74,7 @@ export class CompletionItem {
) {
this.textLabel = typeof completion.label === 'string'
? completion.label
: completion.label.name;
: completion.label.label;

// ensure lower-variants (perf)
this.labelLow = this.textLabel.toLowerCase();
Expand Down Expand Up @@ -227,7 +227,7 @@ export async function provideSuggestionItems(
}
// fill in default sortText when missing
if (!suggestion.sortText) {
suggestion.sortText = typeof suggestion.label === 'string' ? suggestion.label : suggestion.label.name;
suggestion.sortText = typeof suggestion.label === 'string' ? suggestion.label : suggestion.label.label;
}
if (!needsClipboard && suggestion.insertTextRules && suggestion.insertTextRules & modes.CompletionItemInsertTextRule.InsertAsSnippet) {
needsClipboard = SnippetParser.guessNeedsClipboard(suggestion.insertText);
Expand Down
8 changes: 2 additions & 6 deletions src/vs/editor/contrib/suggest/suggestWidgetRenderer.ts
Expand Up @@ -208,16 +208,12 @@ export class ItemRenderer implements IListRenderer<CompletionItem, ISuggestionTe
data.iconLabel.setLabel(element.textLabel, undefined, labelOptions);
if (typeof completion.label === 'string') {
data.parametersLabel.textContent = '';
data.qualifierLabel.textContent = '';
data.detailsLabel.textContent = stripNewLines(completion.detail || '');
data.root.classList.add('string-label');
data.root.title = '';
} else {
data.parametersLabel.textContent = stripNewLines(completion.label.signature || '');
data.qualifierLabel.textContent = stripNewLines(completion.label.qualifier || '');
data.detailsLabel.textContent = stripNewLines(completion.label.type || '');
data.parametersLabel.textContent = stripNewLines(completion.label.detail || '');
data.detailsLabel.textContent = stripNewLines(completion.label.description || '');
data.root.classList.remove('string-label');
data.root.title = `${element.textLabel}${completion.label.signature ?? ''} ${completion.label.qualifier ?? ''} ${completion.label.type ?? ''}`;
}

if (this._editor.getOption(EditorOption.suggest).showInlineDetails) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/suggest/wordDistance.ts
Expand Up @@ -57,7 +57,7 @@ export abstract class WordDistance {
if (item.kind === CompletionItemKind.Keyword) {
return 2 << 20;
}
let word = typeof item.label === 'string' ? item.label : item.label.name;
let word = typeof item.label === 'string' ? item.label : item.label.label;
let wordLines = wordRanges[word];
if (isFalsyOrEmpty(wordLines)) {
return 2 << 20;
Expand Down
19 changes: 3 additions & 16 deletions src/vs/monaco.d.ts
Expand Up @@ -5673,22 +5673,9 @@ declare namespace monaco.languages {
}

export interface CompletionItemLabel {
/**
* The function or variable. Rendered leftmost.
*/
name: string;
/**
* The parameters without the return type. Render after `name`.
*/
signature?: string;
/**
* The fully qualified name, like package name or file path. Rendered after `signature`.
*/
qualifier?: string;
/**
* The return-type of a function or type of a property/variable. Rendered rightmost.
*/
type?: string;
label: string;
detail?: string;
description?: string;
}

export enum CompletionItemTag {
Expand Down
21 changes: 8 additions & 13 deletions src/vs/vscode.proposed.d.ts
Expand Up @@ -1406,29 +1406,24 @@ declare module 'vscode' {
}

export interface CompletionItemLabel {

/**
* The name of this completion item. By default
* The label of this completion item. By default
* this is also the text that is inserted when selecting
* this completion.
*/
name: string;

/**
* The signature of this completion item. Will be rendered right after the
* {@link CompletionItemLabel.name name}.
*/
signature?: string;
label: string;

/**
* The fully qualified name, like package name or file path. Rendered after `signature`.
* A string which is rendered less prominent and directly after {@link CompletionItemLabel.label name}
* without any spacing. Should be used for function signatures or type annotations.
*/
//todo@API find better name
qualifier?: string;
detail?: string;

/**
* The return-type of a function or type of a property/variable. Rendered rightmost.
* The fully qualified name, like package name or file path. Rendered after `detail`.
*/
type?: string;
description?: string;
}

//#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostTypeConverters.ts
Expand Up @@ -997,7 +997,7 @@ export namespace CompletionItem {

export function to(suggestion: modes.CompletionItem, converter?: CommandsConverter): types.CompletionItem {

const result = new types.CompletionItem(typeof suggestion.label === 'string' ? suggestion.label : suggestion.label.name);
const result = new types.CompletionItem(typeof suggestion.label === 'string' ? suggestion.label : suggestion.label.label);
if (typeof suggestion.label !== 'string') {
result.label2 = suggestion.label;
}
Expand Down
8 changes: 3 additions & 5 deletions src/vs/workbench/api/common/extHostTypes.ts
Expand Up @@ -1467,13 +1467,11 @@ export enum CompletionItemTag {
}

export interface CompletionItemLabel {
name: string;
parameters?: string;
qualifier?: string;
type?: string;
label: string;
detail?: string;
description?: string;
}


@es5ClassCompat
export class CompletionItem implements vscode.CompletionItem {

Expand Down
Expand Up @@ -33,7 +33,7 @@ export class SnippetCompletion implements CompletionItem {
readonly snippet: Snippet,
range: IRange | { insert: IRange, replace: IRange }
) {
this.label = { name: snippet.prefix, type: snippet.name };
this.label = { label: snippet.prefix, description: snippet.name };
this.detail = localize('detail.snippet', "{0} ({1})", snippet.description || snippet.name, snippet.source);
this.insertText = snippet.codeSnippet;
this.range = range;
Expand All @@ -48,7 +48,7 @@ export class SnippetCompletion implements CompletionItem {
}

static compareByLabel(a: SnippetCompletion, b: SnippetCompletion): number {
return compare(a.label.name, b.label.name);
return compare(a.label.label, b.label.label);
}
}

Expand Down Expand Up @@ -156,10 +156,10 @@ export class SnippetCompletionProvider implements CompletionItemProvider {
let item = suggestions[i];
let to = i + 1;
for (; to < suggestions.length && item.label === suggestions[to].label; to++) {
suggestions[to].label.name = localize('snippetSuggest.longLabel', "{0}, {1}", suggestions[to].label.name, suggestions[to].snippet.name);
suggestions[to].label.label = localize('snippetSuggest.longLabel', "{0}, {1}", suggestions[to].label.label, suggestions[to].snippet.name);
}
if (to > i + 1) {
suggestions[i].label.name = localize('snippetSuggest.longLabel', "{0}, {1}", suggestions[i].label.name, suggestions[i].snippet.name);
suggestions[i].label.label = localize('snippetSuggest.longLabel', "{0}, {1}", suggestions[i].label.label, suggestions[i].snippet.name);
i = to;
}
}
Expand Down

0 comments on commit a2c4a0c

Please sign in to comment.