mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 06:35:35 -05:00
Support a 'recommended' completion entry (#20020)
* Support a 'recommended' completion entry * Code review * Restore duplicate comments
This commit is contained in:
@@ -180,14 +180,15 @@ namespace ts.server {
|
||||
isGlobalCompletion: false,
|
||||
isMemberCompletion: false,
|
||||
isNewIdentifierLocation: false,
|
||||
entries: response.body.map(entry => {
|
||||
|
||||
entries: response.body.map<CompletionEntry>(entry => {
|
||||
if (entry.replacementSpan !== undefined) {
|
||||
const { name, kind, kindModifiers, sortText, replacementSpan } = entry;
|
||||
return { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName) };
|
||||
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended } = entry;
|
||||
// TODO: GH#241
|
||||
const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended };
|
||||
return res;
|
||||
}
|
||||
|
||||
return entry as { name: string, kind: ScriptElementKind, kindModifiers: string, sortText: string };
|
||||
return entry as { name: string, kind: ScriptElementKind, kindModifiers: string, sortText: string }; // TODO: GH#18217
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1701,8 +1701,9 @@ namespace ts.server.protocol {
|
||||
*/
|
||||
sortText: string;
|
||||
/**
|
||||
* An optional span that indicates the text to be replaced by this completion item. If present,
|
||||
* this span should be used instead of the default one.
|
||||
* An optional span that indicates the text to be replaced by this completion item.
|
||||
* If present, this span should be used instead of the default one.
|
||||
* It will be set if the required span differs from the one generated by the default replacement behavior.
|
||||
*/
|
||||
replacementSpan?: TextSpan;
|
||||
/**
|
||||
@@ -1714,6 +1715,12 @@ namespace ts.server.protocol {
|
||||
* Identifier (not necessarily human-readable) identifying where this completion came from.
|
||||
*/
|
||||
source?: string;
|
||||
/**
|
||||
* If true, this completion should be highlighted as recommended. There will only be one of these.
|
||||
* This will be set when we know the user should write an expression with a certain type and that type is an enum or constructable class.
|
||||
* Then either that enum/class or a namespace containing it will be the recommended symbol.
|
||||
*/
|
||||
isRecommended?: true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1207,10 +1207,10 @@ namespace ts.server {
|
||||
if (simplifiedResult) {
|
||||
return mapDefined<CompletionEntry, protocol.CompletionEntry>(completions && completions.entries, entry => {
|
||||
if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) {
|
||||
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source } = entry;
|
||||
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended } = entry;
|
||||
const convertedSpan = replacementSpan ? this.toLocationTextSpan(replacementSpan, scriptInfo) : undefined;
|
||||
// Use `hasAction || undefined` to avoid serializing `false`.
|
||||
return { name, kind, kindModifiers, sortText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source };
|
||||
return { name, kind, kindModifiers, sortText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended };
|
||||
}
|
||||
}).sort((a, b) => compareStringsCaseSensitiveUI(a.name, b.name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user