@@ -21,7 +21,7 @@ export function create(
21
21
22
22
return {
23
23
24
- async provideInlayHints ( document ) {
24
+ async provideInlayHints ( document , range , cancellationToken ) {
25
25
26
26
if ( ! isSupportedDocument ( document ) ) {
27
27
return ;
@@ -68,29 +68,40 @@ export function create(
68
68
let current : {
69
69
unburnedRequiredProps : string [ ] ;
70
70
labelOffset : number ;
71
- insertOffset : number ;
72
71
} | undefined ;
73
72
74
73
while ( ( token = scanner . scan ( ) ) !== html . TokenType . EOS ) {
75
74
if ( token === html . TokenType . StartTag ) {
76
- const tagName = scanner . getTokenText ( ) ;
77
- if ( intrinsicElementNames . has ( tagName ) ) {
78
- continue ;
79
- }
80
75
76
+ const tagName = scanner . getTokenText ( ) ;
77
+ const tagOffset = scanner . getTokenOffset ( ) ;
81
78
const checkTag = tagName . includes ( '.' )
82
79
? tagName
83
80
: components . find ( component => component === tagName || hyphenateTag ( component ) === tagName ) ;
84
- if ( checkTag ) {
85
- componentProps [ checkTag ] ??= ( await tsPluginClient ?. getComponentProps ( root . fileName , checkTag ) ?? [ ] )
81
+
82
+ if ( intrinsicElementNames . has ( tagName ) || ! checkTag ) {
83
+ continue ;
84
+ }
85
+ if ( tagOffset < document . offsetAt ( range . start ) ) {
86
+ continue ;
87
+ }
88
+ if ( tagOffset > document . offsetAt ( range . end ) ) {
89
+ break ;
90
+ }
91
+
92
+ if ( ! componentProps [ checkTag ] ) {
93
+ if ( cancellationToken . isCancellationRequested ) {
94
+ break ;
95
+ }
96
+ componentProps [ checkTag ] = ( await tsPluginClient ?. getComponentProps ( root . fileName , checkTag ) ?? [ ] )
86
97
. filter ( prop => prop . required )
87
98
. map ( prop => prop . name ) ;
88
- current = {
89
- unburnedRequiredProps : [ ...componentProps [ checkTag ] ] ,
90
- labelOffset : scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ,
91
- insertOffset : scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ,
92
- } ;
93
99
}
100
+
101
+ current = {
102
+ unburnedRequiredProps : [ ...componentProps [ checkTag ] ] ,
103
+ labelOffset : scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ,
104
+ } ;
94
105
}
95
106
else if ( token === html . TokenType . AttributeName ) {
96
107
if ( current ) {
@@ -141,8 +152,8 @@ export function create(
141
152
kind : 2 satisfies typeof vscode . InlayHintKind . Parameter ,
142
153
textEdits : [ {
143
154
range : {
144
- start : document . positionAt ( current . insertOffset ) ,
145
- end : document . positionAt ( current . insertOffset ) ,
155
+ start : document . positionAt ( current . labelOffset ) ,
156
+ end : document . positionAt ( current . labelOffset ) ,
146
157
} ,
147
158
newText : ` :${ casing . attr === AttrNameCasing . Kebab ? hyphenateAttr ( requiredProp ) : requiredProp } =` ,
148
159
} ] ,
@@ -151,11 +162,6 @@ export function create(
151
162
current = undefined ;
152
163
}
153
164
}
154
- if ( token === html . TokenType . AttributeName || token === html . TokenType . AttributeValue ) {
155
- if ( current ) {
156
- current . insertOffset = scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ;
157
- }
158
- }
159
165
}
160
166
161
167
return result ;
0 commit comments