From f880c18b2784a1df9f06b2be516ce0211294df7e Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 3 Aug 2020 16:38:34 +0200 Subject: [PATCH] (fix) markdown in completion resolve #403 --- .../typescript/features/CompletionProvider.ts | 6 ++-- .../features/CompletionProvider.test.ts | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index 8a3c7b8e2..ec8fb3357 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -7,6 +7,8 @@ import { Range, TextDocumentIdentifier, TextEdit, + MarkupContent, + MarkupKind, } from 'vscode-languageserver'; import { Document, @@ -231,8 +233,8 @@ export class CompletionsProviderImpl implements CompletionsProvider { replacementSpan: undefined, sortText: '0', source: undefined, - uri: fileNameToAbosoluteUri(filename) + uri: fileNameToAbosoluteUri(filename), } as CompletionEntryWithIdentifer); }); @@ -135,7 +139,7 @@ describe('CompletionProviderImpl', () => { }); assert.deepStrictEqual(detail, '(alias) function foo(): boolean\nimport foo'); - assert.deepStrictEqual(documentation, 'bars'); + assert.deepStrictEqual(documentation, { value: 'bars', kind: MarkupKind.Markdown }); }); it('provides import completions for directory', async () => { @@ -179,15 +183,17 @@ describe('CompletionProviderImpl', () => { ts.Extension.Jsx, ts.Extension.Tsx, ts.Extension.Json, - '.svelte' + '.svelte', ]; const ignores = ['tsconfig.json', sourceFile]; const testfiles = readdirSync(testFilesDir, { withFileTypes: true }) - .filter((f) => f.isDirectory() - || (supportedExtensions.includes(extname(f.name)) - && !ignores.includes(f.name))) - .map(f => f.name); + .filter( + (f) => + f.isDirectory() || + (supportedExtensions.includes(extname(f.name)) && !ignores.includes(f.name)), + ) + .map((f) => f.name); const completions = await completionProvider.getCompletions( document, @@ -199,8 +205,11 @@ describe('CompletionProviderImpl', () => { ); assert.deepStrictEqual( - sortBy(completions?.items.map(item => item.label), x => x), - sortBy(testfiles, x => x) + sortBy( + completions?.items.map((item) => item.label), + (x) => x, + ), + sortBy(testfiles, (x) => x), ); }); @@ -375,7 +384,7 @@ describe('CompletionProviderImpl', () => { harmonizeNewLines(additionalTextEdits![0]?.newText), // " instead of ' because VSCode uses " by default when there are no other imports indicating otherwise `${newLine}`, + `${newLine}${newLine}${newLine}`, ); assert.deepEqual(