@@ -2,6 +2,7 @@ import type { Disposable, LanguageServiceContext, LanguageServicePluginInstance
22import { VueVirtualCode , hyphenateAttr , hyphenateTag , tsCodegen } from '@vue/language-core' ;
33import { camelize , capitalize } from '@vue/shared' ;
44import { getComponentSpans } from '@vue/typescript-plugin/lib/common' ;
5+ import type { ComponentPropInfo } from '@vue/typescript-plugin/lib/requests/componentInfos' ;
56import { create as createHtmlService } from 'volar-service-html' ;
67import { create as createPugService } from 'volar-service-pug' ;
78import * as html from 'vscode-html-languageservice' ;
@@ -44,7 +45,7 @@ export function create(
4445 let extraCustomData : html . IHTMLDataProvider [ ] = [ ] ;
4546 let lastCompletionComponentNames = new Set < string > ( ) ;
4647
47- const tsDocumentations = new Map < string , string > ( ) ;
48+ const cachedPropInfos = new Map < string , ComponentPropInfo > ( ) ;
4849 const onDidChangeCustomDataListeners = new Set < ( ) => void > ( ) ;
4950 const onDidChangeCustomData = ( listener : ( ) => void ) : Disposable => {
5051 onDidChangeCustomDataListeners . add ( listener ) ;
@@ -488,15 +489,15 @@ export function create(
488489 const promises : Promise < void > [ ] = [ ] ;
489490 const tagInfos = new Map < string , {
490491 attrs : string [ ] ;
491- propsInfo : { name : string , commentMarkdown ?: string ; } [ ] ;
492+ propInfos : ComponentPropInfo [ ] ;
492493 events : string [ ] ;
493494 directives : string [ ] ;
494495 } > ( ) ;
495496
496497 let version = 0 ;
497498 let components : string [ ] | undefined ;
498499
499- tsDocumentations . clear ( ) ;
500+ cachedPropInfos . clear ( ) ;
500501
501502 updateExtraCustomData ( [
502503 html . newHTMLDataProvider ( 'vue-template-built-in' , builtInData ) ,
@@ -557,12 +558,12 @@ export function create(
557558 if ( ! tagInfo ) {
558559 promises . push ( ( async ( ) => {
559560 const attrs = await tsPluginClient ?. getElementAttrs ( vueCode . fileName , tag ) ?? [ ] ;
560- const propsInfo = await tsPluginClient ?. getComponentProps ( vueCode . fileName , tag ) ?? [ ] ;
561+ const propInfos = await tsPluginClient ?. getComponentProps ( vueCode . fileName , tag ) ?? [ ] ;
561562 const events = await tsPluginClient ?. getComponentEvents ( vueCode . fileName , tag ) ?? [ ] ;
562563 const directives = await tsPluginClient ?. getComponentDirectives ( vueCode . fileName ) ?? [ ] ;
563564 tagInfos . set ( tag , {
564565 attrs,
565- propsInfo : propsInfo . filter ( prop =>
566+ propInfos : propInfos . filter ( prop =>
566567 ! prop . name . startsWith ( 'ref_' )
567568 ) ,
568569 events,
@@ -573,8 +574,8 @@ export function create(
573574 return [ ] ;
574575 }
575576
576- const { attrs, propsInfo , events, directives } = tagInfo ;
577- const props = propsInfo . map ( prop =>
577+ const { attrs, propInfos , events, directives } = tagInfo ;
578+ const props = propInfos . map ( prop =>
578579 hyphenateTag ( prop . name ) . startsWith ( 'on-vnode-' )
579580 ? 'onVue:' + prop . name . slice ( 'onVnode' . length )
580581 : prop . name
@@ -611,14 +612,14 @@ export function create(
611612 else {
612613
613614 const propName = name ;
614- const propKey = generateItemKey ( 'componentProp' , isGlobal ? '*' : tag , propName ) ;
615- const propDescription = propsInfo . find ( prop => {
615+ const propInfo = propInfos . find ( prop => {
616616 const name = casing . attr === AttrNameCasing . Camel ? prop . name : hyphenateAttr ( prop . name ) ;
617617 return name === propName ;
618- } ) ?. commentMarkdown ;
618+ } ) ;
619+ const propKey = generateItemKey ( 'componentProp' , isGlobal ? '*' : tag , propName , propInfo ?. deprecated ) ;
619620
620- if ( propDescription ) {
621- tsDocumentations . set ( propName , propDescription ) ;
621+ if ( propInfo ) {
622+ cachedPropInfos . set ( propName , propInfo ) ;
622623 }
623624
624625 attributes . push (
@@ -792,7 +793,7 @@ export function create(
792793
793794 for ( const item of completionList . items ) {
794795 const documentation = typeof item . documentation === 'string' ? item . documentation : item . documentation ?. value ;
795- if ( documentation && ! isItemKey ( documentation ) && item . documentation ) {
796+ if ( documentation && ! isItemKey ( documentation ) ) {
796797 htmlDocumentations . set ( item . label , documentation ) ;
797798 }
798799 }
@@ -819,11 +820,14 @@ export function create(
819820 const itemKeyStr = typeof item . documentation === 'string' ? item . documentation : item . documentation ?. value ;
820821
821822 let parsedItemKey = itemKeyStr ? parseItemKey ( itemKeyStr ) : undefined ;
823+ let propInfo : ComponentPropInfo | undefined ;
824+
822825 if ( parsedItemKey ) {
823826 const documentations : string [ ] = [ ] ;
824827
825- if ( tsDocumentations . has ( parsedItemKey . prop ) ) {
826- documentations . push ( tsDocumentations . get ( parsedItemKey . prop ) ! ) ;
828+ propInfo = cachedPropInfos . get ( parsedItemKey . prop ) ;
829+ if ( propInfo ?. commentMarkdown ) {
830+ documentations . push ( propInfo . commentMarkdown ) ;
827831 }
828832
829833 let { isEvent, propName } = getPropName ( parsedItemKey ) ;
@@ -861,22 +865,28 @@ export function create(
861865 type : 'componentProp' ,
862866 tag : '^' ,
863867 prop : propName ,
868+ deprecated : false ,
864869 leadingSlash : false
865870 } ;
866871 }
867872
868- if ( tsDocumentations . has ( propName ) ) {
873+ propInfo = cachedPropInfos . get ( propName ) ;
874+ if ( propInfo ?. commentMarkdown ) {
869875 const originalDocumentation = typeof item . documentation === 'string' ? item . documentation : item . documentation ?. value ;
870876 item . documentation = {
871877 kind : 'markdown' ,
872878 value : [
873- tsDocumentations . get ( propName ) ! ,
879+ propInfo . commentMarkdown ,
874880 originalDocumentation ,
875881 ] . filter ( str => ! ! str ) . join ( '\n\n' ) ,
876882 } ;
877883 }
878884 }
879885
886+ if ( propInfo ?. deprecated ) {
887+ item . tags = [ 1 satisfies typeof vscode . CompletionItemTag . Deprecated ] ;
888+ }
889+
880890 const tokens : string [ ] = [ ] ;
881891
882892 if (
@@ -1019,8 +1029,8 @@ function parseLabel(label: string) {
10191029 } ;
10201030}
10211031
1022- function generateItemKey ( type : InternalItemId , tag : string , prop : string ) {
1023- return ' __VLS_data=' + type + ',' + tag + ',' + prop ;
1032+ function generateItemKey ( type : InternalItemId , tag : string , prop : string , deprecated ?: boolean ) {
1033+ return ` __VLS_data=${ type } , ${ tag } , ${ prop } , ${ Number ( deprecated ) } ` ;
10241034}
10251035
10261036function isItemKey ( key : string ) {
@@ -1035,6 +1045,7 @@ function parseItemKey(key: string) {
10351045 type : strs [ 0 ] as InternalItemId ,
10361046 tag : strs [ 1 ] ,
10371047 prop : strs [ 2 ] ,
1048+ deprecated : strs [ 3 ] === '1' ,
10381049 leadingSlash
10391050 } ;
10401051 }
0 commit comments