Skip to content

Commit

Permalink
fix(language-service): enhance provideInlayHints to support range par…
Browse files Browse the repository at this point in the history
…ameters
  • Loading branch information
johnsoncodehk committed Mar 7, 2025
1 parent 55becc4 commit 53dcbf9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/language-service/lib/plugins/vue-missing-props-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function create(

return {

async provideInlayHints(document) {
async provideInlayHints(document, range) {

if (!isSupportedDocument(document)) {
return;
Expand Down Expand Up @@ -68,15 +68,23 @@ export function create(
let current: {
unburnedRequiredProps: string[];
labelOffset: number;
insertOffset: number;
} | undefined;

while ((token = scanner.scan()) !== html.TokenType.EOS) {
if (token === html.TokenType.StartTag) {

const tagName = scanner.getTokenText();
const tagOffset = scanner.getTokenOffset();

if (intrinsicElementNames.has(tagName)) {
continue;
}
if (tagOffset < document.offsetAt(range.start)) {
continue;
}
if (tagOffset > document.offsetAt(range.end)) {
break;
}

const checkTag = tagName.includes('.')
? tagName
Expand All @@ -88,7 +96,6 @@ export function create(
current = {
unburnedRequiredProps: [...componentProps[checkTag]],
labelOffset: scanner.getTokenOffset() + scanner.getTokenLength(),
insertOffset: scanner.getTokenOffset() + scanner.getTokenLength(),
};
}
}
Expand Down Expand Up @@ -141,8 +148,8 @@ export function create(
kind: 2 satisfies typeof vscode.InlayHintKind.Parameter,
textEdits: [{
range: {
start: document.positionAt(current.insertOffset),
end: document.positionAt(current.insertOffset),
start: document.positionAt(current.labelOffset),
end: document.positionAt(current.labelOffset),
},
newText: ` :${casing.attr === AttrNameCasing.Kebab ? hyphenateAttr(requiredProp) : requiredProp}=`,
}],
Expand All @@ -151,11 +158,6 @@ export function create(
current = undefined;
}
}
if (token === html.TokenType.AttributeName || token === html.TokenType.AttributeValue) {
if (current) {
current.insertOffset = scanner.getTokenOffset() + scanner.getTokenLength();
}
}
}

return result;
Expand Down

0 comments on commit 53dcbf9

Please sign in to comment.