Skip to content

Commit

Permalink
fix(language-plugin-pug): semantic tokens mapping failed
Browse files Browse the repository at this point in the history
close #4070
  • Loading branch information
johnsoncodehk committed Mar 20, 2024
1 parent 0dfe599 commit 2a77941
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/language-plugin-pug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ const plugin: VueLanguagePlugin = ({ modules }) => {
get(target, prop) {
if (prop === 'offset') {
const htmlOffset = target.offset;
const nums: number[] = [];
for (const mapped of map.getSourceOffsets(htmlOffset)) {
return mapped[0];
nums.push(mapped[0]);
}
return -1;
return Math.max(-1, ...nums);
}
const value = target[prop];
if (typeof value === 'object') {
Expand Down
8 changes: 6 additions & 2 deletions packages/typescript-plugin/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ export function getComponentSpans(
}
if (node.type === 1 satisfies vue.CompilerDOM.NodeTypes.ELEMENT) {
if (components.has(node.tag)) {
let start = node.loc.start.offset;
if (template.lang === 'html') {
start += '<'.length;
}
result.push({
start: node.loc.start.offset + node.loc.source.indexOf(node.tag),
start,
length: node.tag.length,
});
if (template.lang === 'html' && !node.isSelfClosing) {
result.push({
start: node.loc.start.offset + node.loc.source.lastIndexOf(node.tag),
start: start + node.loc.source.lastIndexOf(node.tag),
length: node.tag.length,
});
}
Expand Down

0 comments on commit 2a77941

Please sign in to comment.