@@ -21,7 +21,7 @@ export function create(
2121
2222 return {
2323
24- async provideInlayHints ( document ) {
24+ async provideInlayHints ( document , range , cancellationToken ) {
2525
2626 if ( ! isSupportedDocument ( document ) ) {
2727 return ;
@@ -68,29 +68,40 @@ 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 ) {
76- const tagName = scanner . getTokenText ( ) ;
77- if ( intrinsicElementNames . has ( tagName ) ) {
78- continue ;
79- }
8075
76+ const tagName = scanner . getTokenText ( ) ;
77+ const tagOffset = scanner . getTokenOffset ( ) ;
8178 const checkTag = tagName . includes ( '.' )
8279 ? tagName
8380 : 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 ) ?? [ ] )
8697 . filter ( prop => prop . required )
8798 . map ( prop => prop . name ) ;
88- current = {
89- unburnedRequiredProps : [ ...componentProps [ checkTag ] ] ,
90- labelOffset : scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ,
91- insertOffset : scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ,
92- } ;
9399 }
100+
101+ current = {
102+ unburnedRequiredProps : [ ...componentProps [ checkTag ] ] ,
103+ labelOffset : scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ,
104+ } ;
94105 }
95106 else if ( token === html . TokenType . AttributeName ) {
96107 if ( current ) {
@@ -141,8 +152,8 @@ export function create(
141152 kind : 2 satisfies typeof vscode . InlayHintKind . Parameter ,
142153 textEdits : [ {
143154 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 ) ,
146157 } ,
147158 newText : ` :${ casing . attr === AttrNameCasing . Kebab ? hyphenateAttr ( requiredProp ) : requiredProp } =` ,
148159 } ] ,
@@ -151,11 +162,6 @@ export function create(
151162 current = undefined ;
152163 }
153164 }
154- if ( token === html . TokenType . AttributeName || token === html . TokenType . AttributeValue ) {
155- if ( current ) {
156- current . insertOffset = scanner . getTokenOffset ( ) + scanner . getTokenLength ( ) ;
157- }
158- }
159165 }
160166
161167 return result ;
0 commit comments