Skip to content

Commit

Permalink
fix: cannot rename html tag in some cases
Browse files Browse the repository at this point in the history
close #1272
  • Loading branch information
johnsoncodehk committed May 10, 2022
1 parent 457ef3c commit 71f7436
Showing 1 changed file with 10 additions and 3 deletions.
@@ -1,20 +1,25 @@
import { getWordRange } from '@volar/shared';
import * as vscode from 'vscode-languageserver-protocol';
import type { LanguageServiceRuntimeContext } from '../types';
import { languageFeatureWorker } from '../utils/featureWorkers';

// https://github.com/microsoft/vscode/blob/dcf27391b7dd7c1cece483806af75b4f87188e70/extensions/html/language-configuration.json#L35
const htmlWordPatterns = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\\"\,\.\<\>\/\s]+)/g;

export function register(context: LanguageServiceRuntimeContext) {

return (uri: string, position: vscode.Position) => {
return async (uri: string, position: vscode.Position) => {

return languageFeatureWorker(
const document = context.getTextDocument(uri);
const result = await languageFeatureWorker(
context,
uri,
position,
function* (position, sourceMap) {
for (const [mappedRange] of sourceMap.getMappedRanges(
position,
position,
data => !!data.capabilities.rename,
data => typeof data.capabilities.rename === 'object' ? data.capabilities.rename.in : !!data.capabilities.rename,
)) {
yield mappedRange.start;
}
Expand All @@ -38,5 +43,7 @@ export function register(context: LanguageServiceRuntimeContext) {
return prepares[0];
},
);

return result ?? (document ? getWordRange(htmlWordPatterns, position, document) : undefined);
};
}

0 comments on commit 71f7436

Please sign in to comment.