Skip to content

Commit f34a51a

Browse files
committed
add label details to completion entry
1 parent af7de76 commit f34a51a

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

src/server/protocol.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,10 @@ namespace ts.server.protocol {
22902290
* Human-readable description of the `source`.
22912291
*/
22922292
sourceDisplay?: SymbolDisplayPart[];
2293+
/**
2294+
* Additional details for the label.
2295+
*/
2296+
labelDetails?: CompletionEntryLabelDetails;
22932297
/**
22942298
* If true, this completion should be highlighted as recommended. There will only be one of these.
22952299
* 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.
@@ -2319,6 +2323,21 @@ namespace ts.server.protocol {
23192323
data?: unknown;
23202324
}
23212325

2326+
export interface CompletionEntryLabelDetails {
2327+
/**
2328+
* An optional string which is rendered less prominently directly after
2329+
* {@link CompletionEntry.name name}, without any spacing. Should be
2330+
* used for function signatures or type annotations.
2331+
*/
2332+
detail?: string;
2333+
/**
2334+
* An optional string which is rendered less prominently after
2335+
* {@link CompletionEntryLabelDetails.detail}. Should be used for fully qualified
2336+
* names or file path.
2337+
*/
2338+
description?: string;
2339+
}
2340+
23222341
/**
23232342
* Additional completion entry details, available on demand
23242343
*/

src/server/session.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,10 +1837,41 @@ namespace ts.server {
18371837
const prefix = args.prefix || "";
18381838
const entries = mapDefined<CompletionEntry, protocol.CompletionEntry>(completions.entries, entry => {
18391839
if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) {
1840-
const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, sourceDisplay, isSnippet, isRecommended, isPackageJsonImport, isImportStatementCompletion, data } = entry;
1840+
const {
1841+
name,
1842+
kind,
1843+
kindModifiers,
1844+
sortText,
1845+
insertText,
1846+
replacementSpan,
1847+
hasAction,
1848+
source,
1849+
sourceDisplay,
1850+
labelDetails,
1851+
isSnippet,
1852+
isRecommended,
1853+
isPackageJsonImport,
1854+
isImportStatementCompletion,
1855+
data } = entry;
18411856
const convertedSpan = replacementSpan ? toProtocolTextSpan(replacementSpan, scriptInfo) : undefined;
18421857
// Use `hasAction || undefined` to avoid serializing `false`.
1843-
return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, isSnippet, hasAction: hasAction || undefined, source, sourceDisplay, isRecommended, isPackageJsonImport, isImportStatementCompletion, data };
1858+
return {
1859+
name,
1860+
kind,
1861+
kindModifiers,
1862+
sortText,
1863+
insertText,
1864+
replacementSpan: convertedSpan,
1865+
isSnippet,
1866+
hasAction: hasAction || undefined,
1867+
source,
1868+
sourceDisplay,
1869+
labelDetails,
1870+
isRecommended,
1871+
isPackageJsonImport,
1872+
isImportStatementCompletion,
1873+
data
1874+
};
18441875
}
18451876
});
18461877

src/services/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ namespace ts {
12321232
hasAction?: true;
12331233
source?: string;
12341234
sourceDisplay?: SymbolDisplayPart[];
1235+
labelDetails?: CompletionEntryLabelDetails;
12351236
isRecommended?: true;
12361237
isFromUncheckedFile?: true;
12371238
isPackageJsonImport?: true;
@@ -1247,6 +1248,11 @@ namespace ts {
12471248
data?: CompletionEntryData;
12481249
}
12491250

1251+
export interface CompletionEntryLabelDetails {
1252+
detail?: string;
1253+
description?: string;
1254+
}
1255+
12501256
export interface CompletionEntryDetails {
12511257
name: string;
12521258
kind: ScriptElementKind;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6485,6 +6485,7 @@ declare namespace ts {
64856485
hasAction?: true;
64866486
source?: string;
64876487
sourceDisplay?: SymbolDisplayPart[];
6488+
labelDetails?: CompletionEntryLabelDetails;
64886489
isRecommended?: true;
64896490
isFromUncheckedFile?: true;
64906491
isPackageJsonImport?: true;
@@ -6499,6 +6500,10 @@ declare namespace ts {
64996500
*/
65006501
data?: CompletionEntryData;
65016502
}
6503+
interface CompletionEntryLabelDetails {
6504+
detail?: string;
6505+
description?: string;
6506+
}
65026507
interface CompletionEntryDetails {
65036508
name: string;
65046509
kind: ScriptElementKind;
@@ -8708,6 +8713,10 @@ declare namespace ts.server.protocol {
87088713
* Human-readable description of the `source`.
87098714
*/
87108715
sourceDisplay?: SymbolDisplayPart[];
8716+
/**
8717+
* Additional details for the label.
8718+
*/
8719+
labelDetails?: CompletionEntryLabelDetails;
87118720
/**
87128721
* If true, this completion should be highlighted as recommended. There will only be one of these.
87138722
* 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.
@@ -8736,6 +8745,20 @@ declare namespace ts.server.protocol {
87368745
*/
87378746
data?: unknown;
87388747
}
8748+
interface CompletionEntryLabelDetails {
8749+
/**
8750+
* An optional string which is rendered less prominently directly after
8751+
* {@link CompletionEntry.name name}, without any spacing. Should be
8752+
* used for function signatures or type annotations.
8753+
*/
8754+
detail?: string;
8755+
/**
8756+
* An optional string which is rendered less prominently after
8757+
* {@link CompletionEntryLabelDetails.detail}. Should be used for fully qualified
8758+
* names or file path.
8759+
*/
8760+
description?: string;
8761+
}
87398762
/**
87408763
* Additional completion entry details, available on demand
87418764
*/

tests/baselines/reference/api/typescript.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6485,6 +6485,7 @@ declare namespace ts {
64856485
hasAction?: true;
64866486
source?: string;
64876487
sourceDisplay?: SymbolDisplayPart[];
6488+
labelDetails?: CompletionEntryLabelDetails;
64886489
isRecommended?: true;
64896490
isFromUncheckedFile?: true;
64906491
isPackageJsonImport?: true;
@@ -6499,6 +6500,10 @@ declare namespace ts {
64996500
*/
65006501
data?: CompletionEntryData;
65016502
}
6503+
interface CompletionEntryLabelDetails {
6504+
detail?: string;
6505+
description?: string;
6506+
}
65026507
interface CompletionEntryDetails {
65036508
name: string;
65046509
kind: ScriptElementKind;

0 commit comments

Comments
 (0)