From e56c5b013b29287f665ab7265bd0bb526f2be23e Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 7 Nov 2024 09:09:52 -0500 Subject: [PATCH] fix(vscode): let `linkedEditing` work when tag name contains `.` --- .../src/plugins/html/HTMLPlugin.ts | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/language-server/src/plugins/html/HTMLPlugin.ts b/packages/language-server/src/plugins/html/HTMLPlugin.ts index 4e6cf47ec..a0108a269 100644 --- a/packages/language-server/src/plugins/html/HTMLPlugin.ts +++ b/packages/language-server/src/plugins/html/HTMLPlugin.ts @@ -44,12 +44,11 @@ import { indentBasedFoldingRangeForTag } from '../../lib/foldingRange/indentFold export class HTMLPlugin implements - HoverProvider, - CompletionsProvider, - RenameProvider, - LinkedEditingRangesProvider, - FoldingRangeProvider -{ + HoverProvider, + CompletionsProvider, + RenameProvider, + LinkedEditingRangesProvider, + FoldingRangeProvider { __name = 'html'; private lang = getLanguageService({ customDataProviders: this.getCustomDataProviders(), @@ -142,20 +141,20 @@ export class HTMLPlugin const results = this.isInComponentTag(html, document, position) ? // Only allow emmet inside component element tags. - // Other attributes/events would be false positives. - CompletionList.create([]) + // Other attributes/events would be false positives. + CompletionList.create([]) : this.lang.doComplete(document, position, html); const items = this.toCompletionItems(results.items); const filePath = document.getFilePath(); const prettierConfig = filePath && - items.some((item) => item.label.startsWith('on:') || item.label.startsWith('bind:')) + items.some((item) => item.label.startsWith('on:') || item.label.startsWith('bind:')) ? this.configManager.getMergedPrettierConfig( - await importPrettier(filePath).resolveConfig(filePath, { - editorconfig: true - }) - ) + await importPrettier(filePath).resolveConfig(filePath, { + editorconfig: true + }) + ) : null; const svelteStrictMode = prettierConfig?.svelteStrictMode; @@ -242,9 +241,9 @@ export class HTMLPlugin textEdit: existingCompletion.textEdit && TextEdit.is(existingCompletion.textEdit) ? { - range: existingCompletion.textEdit.range, - newText: `${existingCompletion.textEdit.newText} lang="${lang}"` - } + range: existingCompletion.textEdit.range, + newText: `${existingCompletion.textEdit.newText} lang="${lang}"` + } : undefined }) ); @@ -333,7 +332,12 @@ export class HTMLPlugin return null; } - return { ranges }; + // Note that `.` is excluded from the word pattern. This is intentional to support property access in Svelte component tags. + return { + ranges, + wordPattern: + '(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\^\\&\\*\\(\\)\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\\'\\"\\,\\<\\>\\/\\s]+)' + }; } getFoldingRanges(document: Document): FoldingRange[] {