From f7a1cba6396a493d8a3d85c8d251b410044e0a73 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Wed, 8 Jan 2025 15:46:03 +0800 Subject: [PATCH] fix svelte 4 again --- .../features/DocumentHighlightProvider.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/language-server/src/plugins/typescript/features/DocumentHighlightProvider.ts b/packages/language-server/src/plugins/typescript/features/DocumentHighlightProvider.ts index 349daca9b..79beebdf3 100644 --- a/packages/language-server/src/plugins/typescript/features/DocumentHighlightProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/DocumentHighlightProvider.ts @@ -106,6 +106,7 @@ export class DocumentHighlightProviderImpl implements DocumentHighlightProvider private findCandidateSvelteTag(tsDoc: SvelteDocumentSnapshot, offset: number) { let candidate: TemplateNode | undefined; + const subBlocks = ['ThenBlock', 'CatchBlock', 'PendingBlock', 'ElseBlock']; tsDoc.walkSvelteAst({ enter(node, parent, key) { @@ -128,7 +129,21 @@ export class DocumentHighlightProviderImpl implements DocumentHighlightProvider return; } - if (node.type.endsWith('Block') || node.type.endsWith('Tag')) { + if (node.type.endsWith('Tag')) { + candidate = templateNode; + return; + } + + // don't use sub-blocks so we can highlight the whole block + if (node.type.endsWith('Block') && !subBlocks.includes(node.type)) { + if ( + // else if + node.type === 'IfBlock' && + parent.type === 'ElseBlock' && + parent.start === node.start + ) { + return; + } candidate = templateNode; return; }