use label, detail, and description for CompletionItemLabel, tweak rendering, https://github.com/microsoft/vscode/issues/39441

This commit is contained in:
Johannes Rieken
2021-06-22 13:59:29 +02:00
parent 9cfc4bcb5c
commit a2c4a0ca8c
10 changed files with 30 additions and 69 deletions
+3 -19
View File
@@ -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 {
@@ -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;
@@ -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;
+2 -2
View File
@@ -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();
@@ -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);
@@ -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) {
@@ -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;
+3 -16
View File
@@ -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 {
+8 -13
View File
@@ -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;
label: string;
/**
* The signature of this completion item. Will be rendered right after the
* {@link CompletionItemLabel.name name}.
* 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.
*/
signature?: string;
detail?: string;
/**
* The fully qualified name, like package name or file path. Rendered after `signature`.
* The fully qualified name, like package name or file path. Rendered after `detail`.
*/
//todo@API find better name
qualifier?: string;
/**
* The return-type of a function or type of a property/variable. Rendered rightmost.
*/
type?: string;
description?: string;
}
//#endregion
@@ -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;
}
+3 -5
View File
@@ -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 {
@@ -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;
@@ -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);
}
}
@@ -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;
}
}