Skip to content

Commit

Permalink
fix(vscode): let linkedEditing work when tag name contains .
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Nov 7, 2024
1 parent 6180537 commit e56c5b0
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/language-server/src/plugins/html/HTMLPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
})
);
Expand Down Expand Up @@ -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[] {
Expand Down

0 comments on commit e56c5b0

Please sign in to comment.