Skip to content

Commit cadf62e

Browse files
authored
fix: restrict emmet completion with emmet specific triggerCharacter (#2873)
* wip * test * changeset * format
1 parent 6ad05e5 commit cadf62e

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

.changeset/kind-carrots-pull.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"svelte-language-server": patch
2+
'svelte-language-server': patch
33
---
44

55
fix: support for @nativescript-community/svelte-native

.changeset/silent-cases-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-language-server': patch
3+
---
4+
5+
fix: restrict emmet completion with emmet specific triggerCharacter

packages/language-server/src/plugins/html/HTMLPlugin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,17 @@ export class HTMLPlugin
147147
completionContext?.triggerCharacter &&
148148
!this.htmlTriggerCharacters.includes(completionContext?.triggerCharacter)
149149
) {
150-
return doEmmetCompleteInner() ?? null;
150+
const node = html.findNodeAt(document.offsetAt(position));
151+
const offset = document.offsetAt(position);
152+
if (
153+
!node?.tag ||
154+
(offset > (node.startTagEnd ?? node.end) &&
155+
(node.endTagStart == null || offset <= node.endTagStart))
156+
) {
157+
return doEmmetCompleteInner() ?? null;
158+
}
159+
160+
return null;
151161
}
152162

153163
const results = this.isInComponentTag(html, document, position)

packages/language-server/src/plugins/typescript/service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,9 @@ async function createLanguageService(
794794
//override if we detect svelte-native
795795
if (workspacePath) {
796796
try {
797-
const svelteNativePkgInfo = getPackageInfo('@nativescript-community/svelte-native', workspacePath) || getPackageInfo('svelte-native', workspacePath);
797+
const svelteNativePkgInfo =
798+
getPackageInfo('@nativescript-community/svelte-native', workspacePath) ||
799+
getPackageInfo('svelte-native', workspacePath);
798800
if (svelteNativePkgInfo.path) {
799801
// For backwards compatibility
800802
parsedConfig.raw.svelteOptions = parsedConfig.raw.svelteOptions || {};

packages/language-server/test/plugins/html/HTMLPlugin.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ describe('HTML Plugin', () => {
190190
assert.strictEqual(completions?.items[0]?.label, 'div>');
191191
});
192192

193+
it('skip emmet completions right after start tag close', async () => {
194+
const { plugin, document } = setup('Test.a>');
195+
196+
const completions = await plugin.getCompletions(document, Position.create(0, 5), {
197+
triggerCharacter: '>',
198+
triggerKind: CompletionTriggerKind.TriggerCharacter
199+
});
200+
assert.strictEqual(completions, null);
201+
});
202+
193203
it('does not provide rename for element being uppercase', async () => {
194204
const { plugin, document } = setup('<Div></Div>');
195205

0 commit comments

Comments
 (0)