Skip to content

Commit 2a77941

Browse files
committed
fix(language-plugin-pug): semantic tokens mapping failed
close #4070
1 parent 0dfe599 commit 2a77941

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/language-plugin-pug/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ const plugin: VueLanguagePlugin = ({ modules }) => {
3838
get(target, prop) {
3939
if (prop === 'offset') {
4040
const htmlOffset = target.offset;
41+
const nums: number[] = [];
4142
for (const mapped of map.getSourceOffsets(htmlOffset)) {
42-
return mapped[0];
43+
nums.push(mapped[0]);
4344
}
44-
return -1;
45+
return Math.max(-1, ...nums);
4546
}
4647
const value = target[prop];
4748
if (typeof value === 'object') {

packages/typescript-plugin/lib/common.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,17 @@ export function getComponentSpans(
129129
}
130130
if (node.type === 1 satisfies vue.CompilerDOM.NodeTypes.ELEMENT) {
131131
if (components.has(node.tag)) {
132+
let start = node.loc.start.offset;
133+
if (template.lang === 'html') {
134+
start += '<'.length;
135+
}
132136
result.push({
133-
start: node.loc.start.offset + node.loc.source.indexOf(node.tag),
137+
start,
134138
length: node.tag.length,
135139
});
136140
if (template.lang === 'html' && !node.isSelfClosing) {
137141
result.push({
138-
start: node.loc.start.offset + node.loc.source.lastIndexOf(node.tag),
142+
start: start + node.loc.source.lastIndexOf(node.tag),
139143
length: node.tag.length,
140144
});
141145
}

0 commit comments

Comments
 (0)