@@ -21,7 +21,7 @@ export function create(
2121
2222return {
2323
24- async provideInlayHints ( document ) {
24+ async provideInlayHints ( document , range , cancellationToken ) {
2525
2626if ( ! isSupportedDocument ( document ) ) {
2727return ;
@@ -68,29 +68,40 @@ export function create(
6868let current : {
6969unburnedRequiredProps : string [ ] ;
7070labelOffset : number ;
71- insertOffset : number ;
7271} | undefined ;
7372
7473while ( ( token = scanner . scan ( ) ) !== html . TokenType . EOS ) {
7574if ( 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 ( ) ;
8178const 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}
95106else if ( token === html . TokenType . AttributeName ) {
96107if ( current ) {
@@ -141,8 +152,8 @@ export function create(
141152kind : 2 satisfies typeof vscode . InlayHintKind . Parameter ,
142153textEdits : [ {
143154range : {
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} ,
147158newText : ` :${ casing . attr === AttrNameCasing . Kebab ? hyphenateAttr ( requiredProp ) : requiredProp } =` ,
148159} ] ,
@@ -151,11 +162,6 @@ export function create(
151162current = 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
161167return result ;
0 commit comments