Skip to content

Commit 53dcbf9

Browse files
committed
fix(language-service): enhance provideInlayHints to support range parameters
1 parent 55becc4 commit 53dcbf9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/language-service/lib/plugins/vue-missing-props-hints.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function create(
2121

2222
return {
2323

24-
async provideInlayHints(document) {
24+
async provideInlayHints(document, range) {
2525

2626
if (!isSupportedDocument(document)) {
2727
return;
@@ -68,15 +68,23 @@ export function create(
6868
let current: {
6969
unburnedRequiredProps: string[];
7070
labelOffset: number;
71-
insertOffset: number;
7271
} | undefined;
7372

7473
while ((token = scanner.scan()) !== html.TokenType.EOS) {
7574
if (token === html.TokenType.StartTag) {
75+
7676
const tagName = scanner.getTokenText();
77+
const tagOffset = scanner.getTokenOffset();
78+
7779
if (intrinsicElementNames.has(tagName)) {
7880
continue;
7981
}
82+
if (tagOffset < document.offsetAt(range.start)) {
83+
continue;
84+
}
85+
if (tagOffset > document.offsetAt(range.end)) {
86+
break;
87+
}
8088

8189
const checkTag = tagName.includes('.')
8290
? tagName
@@ -88,7 +96,6 @@ export function create(
8896
current = {
8997
unburnedRequiredProps: [...componentProps[checkTag]],
9098
labelOffset: scanner.getTokenOffset() + scanner.getTokenLength(),
91-
insertOffset: scanner.getTokenOffset() + scanner.getTokenLength(),
9299
};
93100
}
94101
}
@@ -141,8 +148,8 @@ export function create(
141148
kind: 2 satisfies typeof vscode.InlayHintKind.Parameter,
142149
textEdits: [{
143150
range: {
144-
start: document.positionAt(current.insertOffset),
145-
end: document.positionAt(current.insertOffset),
151+
start: document.positionAt(current.labelOffset),
152+
end: document.positionAt(current.labelOffset),
146153
},
147154
newText: ` :${casing.attr === AttrNameCasing.Kebab ? hyphenateAttr(requiredProp) : requiredProp}=`,
148155
}],
@@ -151,11 +158,6 @@ export function create(
151158
current = undefined;
152159
}
153160
}
154-
if (token === html.TokenType.AttributeName || token === html.TokenType.AttributeValue) {
155-
if (current) {
156-
current.insertOffset = scanner.getTokenOffset() + scanner.getTokenLength();
157-
}
158-
}
159161
}
160162

161163
return result;

0 commit comments

Comments
 (0)