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..9ff99d725 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 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 } @@ -679,7 +699,7 @@ export class CompletionsProviderImpl implements CompletionsProvider any): void' + 'Add import from "svelte"\n\nfunction onMount(fn: () => any): void' ); assert.strictEqual( @@ -842,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( @@ -880,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( @@ -1169,6 +1171,9 @@ function test(useNewTransformation: boolean) { sortText: '11', commitCharacters: undefined, preselect: undefined, + labelDetails: { + description: '../definitions' + }, textEdit: { newText: '{ blubb } from "../definitions";', range: { @@ -1227,6 +1232,7 @@ function test(useNewTransformation: boolean) { sortText: '11', commitCharacters: ['.', ',', ';', '('], preselect: undefined, + labelDetails: undefined, textEdit: { newText: '.toString', range: { @@ -1267,6 +1273,7 @@ function test(useNewTransformation: boolean) { sortText: '11', preselect: undefined, insertText: undefined, + labelDetails: undefined, commitCharacters: ['.', ',', ';', '('], textEdit: { newText: '@hi', @@ -1410,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