From cb64a1f34ffd23d0cc0a5420e7bd55aeaa2a314a Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Wed, 28 Dec 2022 12:08:24 +0800 Subject: [PATCH 1/3] (feat) completion label detail support --- packages/language-server/src/ls-config.ts | 3 ++- .../typescript/features/CompletionProvider.ts | 18 ++++++++++++++++++ packages/language-server/src/server.ts | 5 ++++- .../features/CompletionProvider.test.ts | 11 +++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/language-server/src/ls-config.ts b/packages/language-server/src/ls-config.ts index 49daa4564..b8ad15f8a 100644 --- a/packages/language-server/src/ls-config.ts +++ b/packages/language-server/src/ls-config.ts @@ -400,7 +400,8 @@ export class LSConfigManager { config.suggest?.includeCompletionsForImportStatements ?? true, includeAutomaticOptionalChainCompletions: config.suggest?.includeAutomaticOptionalChainCompletions ?? true, - includeCompletionsWithInsertText: true + includeCompletionsWithInsertText: true, + useLabelDetailsInCompletionEntries: true }; } diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index 46d8e4efe..bcb3dca39 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -455,6 +455,14 @@ export class CompletionsProviderImpl implements CompletionsProvider Date: Thu, 29 Dec 2022 09:30:36 +0800 Subject: [PATCH 2/3] typescript code action description for auto import --- .../typescript/features/CompletionProvider.ts | 20 ++++++++++--------- .../features/CompletionProvider.test.ts | 17 +++++++++------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index bcb3dca39..d942af167 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -679,17 +679,19 @@ export class CompletionsProviderImpl implements CompletionsProvider codeAction.description) ?? []; - if (sourceDisplay) { - let importPath = ts.displayPartsToString(sourceDisplay); - if (is$typeImport) { - // Take into account Node16 moduleResolution - importPath = `'./$types${importPath.endsWith('.js') ? '.js' : ''}'`; - } - detail = `Auto import from ${importPath}\n${detail}`; + if (sourceDisplay && is$typeImport) { + const importPath = ts.displayPartsToString(sourceDisplay); + + // Take into account Node16 moduleResolution + parts = parts.map((detail) => + detail.replace(importPath, `'./$types${importPath.endsWith('.js') ? '.js' : ''}'`) + ); } + parts.push(changeSvelteComponentName(ts.displayPartsToString(displayParts))); + const markdownDoc = getMarkdownDocumentation(tsDocumentation, tags); const documentation: MarkupContent | undefined = markdownDoc ? { value: markdownDoc, kind: MarkupKind.Markdown } @@ -697,7 +699,7 @@ export class CompletionsProviderImpl implements CompletionsProvider any): void' + 'Add import from "svelte"\n\nfunction onMount(fn: () => any): void' ); assert.strictEqual( @@ -844,7 +844,7 @@ function test(useNewTransformation: boolean) { assert.strictEqual( detail, - 'Auto import from ../imported-file.svelte\nclass ImportedFile' + 'Add import from "../imported-file.svelte"\n\nclass ImportedFile' ); assert.strictEqual( @@ -882,7 +882,7 @@ function test(useNewTransformation: boolean) { assert.strictEqual( detail, - 'Auto import from ../imported-file.svelte\nclass ImportedFile' + 'Add import from "../imported-file.svelte"\n\nclass ImportedFile' ); assert.strictEqual( @@ -1417,7 +1417,10 @@ function test(useNewTransformation: boolean) { const { detail } = await completionProvider.resolveCompletion(document, item!); - assert.strictEqual(detail, 'Auto import from random-package2\nfunction foo(): string'); + assert.strictEqual( + detail, + 'Add import from "random-package2"\n\nfunction foo(): string' + ); }); // Hacky, but it works. Needed due to testing both new and old transformation From c813a2cbbe4c4ac4048a9a0801461c04b45b2107 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Thu, 29 Dec 2022 14:56:57 +0800 Subject: [PATCH 3/3] there's also other caching apis --- .../src/plugins/typescript/features/CompletionProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index d942af167..9ff99d725 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -636,8 +636,8 @@ export class CompletionsProviderImpl implements CompletionsProvider