From 5479ab56e4eb16fe455b4a712877fd4b1f52bf15 Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 11:26:44 +0300 Subject: [PATCH 1/7] improve autocomplete --- .../plugins/svelte/features/getCompletions.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/language-server/src/plugins/svelte/features/getCompletions.ts b/packages/language-server/src/plugins/svelte/features/getCompletions.ts index ddc3c90fd..3fa7b4769 100644 --- a/packages/language-server/src/plugins/svelte/features/getCompletions.ts +++ b/packages/language-server/src/plugins/svelte/features/getCompletions.ts @@ -4,10 +4,11 @@ import { CompletionList, CompletionItemKind, CompletionItem, + InsertTextFormat, } from 'vscode-languageserver'; import { SvelteTag, documentation, getLatestOpeningTag } from './SvelteTags'; import { isInTag } from '../../../lib/documents'; - +import { SnippetString } from 'vscode'; /** * Get completions for special svelte tags within moustache tags. */ @@ -54,9 +55,13 @@ function getCompletionsWithRegardToTriggerCharacter( if (triggerCharacter === '#') { return createCompletionItems([ - { tag: 'if', label: 'if' }, - { tag: 'each', label: 'each' }, - { tag: 'await', label: 'await' }, + { tag: 'if', label: 'if', insertText: 'if $1}\n\t$2\n{/if' }, + { tag: 'each', label: 'each', insertText: 'each $1 as $2}\n\t$3\n{/each' }, + { + tag: 'await', + label: 'await', + insertText: 'await $1}\n\t$2\n{:then $3} \n\t$4\n{/await', + }, ]); } @@ -133,12 +138,16 @@ function showCompletionWithRegardsToOpenedTags( /** * Create the completion items for given labels and tags. */ -function createCompletionItems(items: { label: string; tag: SvelteTag }[]): CompletionList { +function createCompletionItems( + items: { label: string; tag: SvelteTag; insertText?: string }[], +): CompletionList { return CompletionList.create( // add sortText/preselect so it is ranked higher than other completions and selected first items.map( (item) => { + insertTextFormat: InsertTextFormat.Snippet, + insertText: item.insertText, label: item.label, sortText: '-1', kind: CompletionItemKind.Keyword, From 292c7e141d3ad4ccbdb2836cdfdd123b0dd97965 Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 11:27:29 +0300 Subject: [PATCH 2/7] remove snippet string --- .../src/plugins/svelte/features/getCompletions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/language-server/src/plugins/svelte/features/getCompletions.ts b/packages/language-server/src/plugins/svelte/features/getCompletions.ts index 3fa7b4769..a15fb8382 100644 --- a/packages/language-server/src/plugins/svelte/features/getCompletions.ts +++ b/packages/language-server/src/plugins/svelte/features/getCompletions.ts @@ -8,7 +8,6 @@ import { } from 'vscode-languageserver'; import { SvelteTag, documentation, getLatestOpeningTag } from './SvelteTags'; import { isInTag } from '../../../lib/documents'; -import { SnippetString } from 'vscode'; /** * Get completions for special svelte tags within moustache tags. */ From f84875fe874d96fada6b2ea207a6c6e54e00250b Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 11:47:36 +0300 Subject: [PATCH 3/7] add the the other #await syntax --- .../src/plugins/svelte/features/getCompletions.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/language-server/src/plugins/svelte/features/getCompletions.ts b/packages/language-server/src/plugins/svelte/features/getCompletions.ts index a15fb8382..e2f634116 100644 --- a/packages/language-server/src/plugins/svelte/features/getCompletions.ts +++ b/packages/language-server/src/plugins/svelte/features/getCompletions.ts @@ -58,9 +58,14 @@ function getCompletionsWithRegardToTriggerCharacter( { tag: 'each', label: 'each', insertText: 'each $1 as $2}\n\t$3\n{/each' }, { tag: 'await', - label: 'await', + label: 'await :then', insertText: 'await $1}\n\t$2\n{:then $3} \n\t$4\n{/await', }, + { + tag: 'await', + label: 'await then', + insertText: 'await $1 then $2}\n\t\t$3\n{/await', + }, ]); } From 3879721536ab2ed981b8bc693caf16ef78716291 Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 11:49:32 +0300 Subject: [PATCH 4/7] remove one tab --- .../src/plugins/svelte/features/getCompletions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-server/src/plugins/svelte/features/getCompletions.ts b/packages/language-server/src/plugins/svelte/features/getCompletions.ts index e2f634116..a64e50989 100644 --- a/packages/language-server/src/plugins/svelte/features/getCompletions.ts +++ b/packages/language-server/src/plugins/svelte/features/getCompletions.ts @@ -64,7 +64,7 @@ function getCompletionsWithRegardToTriggerCharacter( { tag: 'await', label: 'await then', - insertText: 'await $1 then $2}\n\t\t$3\n{/await', + insertText: 'await $1 then $2}\n\t$3\n{/await', }, ]); } From 742291e0ad29f9bb38663dd36eb83d8221a10122 Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 11:55:55 +0300 Subject: [PATCH 5/7] adjust tests --- .../test/plugins/svelte/features/getHoverInfo.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts b/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts index 6a79fbbf0..dccbdc68e 100644 --- a/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts +++ b/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts @@ -66,7 +66,7 @@ describe('SveltePlugin#getHoverInfo', () => { }); describe('should return hover for #', () => { - (['if', 'each', 'await'] as const).forEach((tag) => { + (['if', 'each', 'await :then', 'await then'] as const).forEach((tag) => { it(`(#${tag})`, () => { expectHoverInfoFor(`{#${tag}}`, Position.create(0, 3)).toEqual(tag); expectHoverInfoFor(`{#${tag} `, Position.create(0, 3)).toEqual(tag); From 9ce3ec9cb564f2e48eb536ca1c07c094cb0236d4 Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 13:44:46 +0300 Subject: [PATCH 6/7] adjust correct tests --- .../test/plugins/svelte/features/getCompletions.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-server/test/plugins/svelte/features/getCompletions.test.ts b/packages/language-server/test/plugins/svelte/features/getCompletions.test.ts index 72fd55b20..9c9f28484 100644 --- a/packages/language-server/test/plugins/svelte/features/getCompletions.test.ts +++ b/packages/language-server/test/plugins/svelte/features/getCompletions.test.ts @@ -49,7 +49,7 @@ describe('SveltePlugin#getCompletions', () => { }); it('should return completions for #', () => { - expectCompletionsFor('{#').toEqual(['if', 'each', 'await']); + expectCompletionsFor('{#').toEqual(['if', 'each', 'await :then', 'await then']); }); it('should return completions for @', () => { From 18e7628cd9ca4129ebd4de6f5e19cc08f453bcd2 Mon Sep 17 00:00:00 2001 From: Gal Date: Mon, 27 Jul 2020 13:45:33 +0300 Subject: [PATCH 7/7] revert hover tests changes --- .../test/plugins/svelte/features/getHoverInfo.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts b/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts index dccbdc68e..6a79fbbf0 100644 --- a/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts +++ b/packages/language-server/test/plugins/svelte/features/getHoverInfo.test.ts @@ -66,7 +66,7 @@ describe('SveltePlugin#getHoverInfo', () => { }); describe('should return hover for #', () => { - (['if', 'each', 'await :then', 'await then'] as const).forEach((tag) => { + (['if', 'each', 'await'] as const).forEach((tag) => { it(`(#${tag})`, () => { expectHoverInfoFor(`{#${tag}}`, Position.create(0, 3)).toEqual(tag); expectHoverInfoFor(`{#${tag} `, Position.create(0, 3)).toEqual(tag);