@@ -2,12 +2,16 @@ import type { ServiceContext, VirtualCode } from '@volar/language-service';
22import type { CompilerDOM } from '@vue/language-core' ;
33import * as vue from '@vue/language-core' ;
44import { VueGeneratedCode , hyphenateAttr , hyphenateTag } from '@vue/language-core' ;
5- import * as namedPipeClient from '@vue/typescript-plugin/lib/client' ;
65import { computed } from 'computeds' ;
76import type * as vscode from 'vscode-languageserver-protocol' ;
87import { AttrNameCasing , TagNameCasing } from '../types' ;
98
10- export async function convertTagName ( context : ServiceContext , uri : string , casing : TagNameCasing ) {
9+ export async function convertTagName (
10+ context : ServiceContext ,
11+ uri : string ,
12+ casing : TagNameCasing ,
13+ tsPluginClient : typeof import ( '@vue/typescript-plugin/lib/client' ) ,
14+ ) {
1115
1216 const sourceFile = context . language . files . get ( uri ) ;
1317 if ( ! sourceFile )
@@ -24,7 +28,7 @@ export async function convertTagName(context: ServiceContext, uri: string, casin
2428 const template = desc . template ;
2529 const document = context . documents . get ( sourceFile . id , sourceFile . languageId , sourceFile . snapshot ) ;
2630 const edits : vscode . TextEdit [ ] = [ ] ;
27- const components = await namedPipeClient . getComponentNames ( rootCode . fileName ) ?? [ ] ;
31+ const components = await tsPluginClient . getComponentNames ( rootCode . fileName ) ?? [ ] ;
2832 const tags = getTemplateTagsAndAttrs ( rootCode ) ;
2933
3034 for ( const [ tagName , { offsets } ] of tags ) {
@@ -47,7 +51,12 @@ export async function convertTagName(context: ServiceContext, uri: string, casin
4751 return edits ;
4852}
4953
50- export async function convertAttrName ( context : ServiceContext , uri : string , casing : AttrNameCasing ) {
54+ export async function convertAttrName (
55+ context : ServiceContext ,
56+ uri : string ,
57+ casing : AttrNameCasing ,
58+ tsPluginClient : typeof import ( '@vue/typescript-plugin/lib/client' ) ,
59+ ) {
5160
5261 const sourceFile = context . language . files . get ( uri ) ;
5362 if ( ! sourceFile )
@@ -64,13 +73,13 @@ export async function convertAttrName(context: ServiceContext, uri: string, casi
6473 const template = desc . template ;
6574 const document = context . documents . get ( uri , sourceFile . languageId , sourceFile . snapshot ) ;
6675 const edits : vscode . TextEdit [ ] = [ ] ;
67- const components = await namedPipeClient . getComponentNames ( rootCode . fileName ) ?? [ ] ;
76+ const components = await tsPluginClient . getComponentNames ( rootCode . fileName ) ?? [ ] ;
6877 const tags = getTemplateTagsAndAttrs ( rootCode ) ;
6978
7079 for ( const [ tagName , { attrs } ] of tags ) {
7180 const componentName = components . find ( component => component === tagName || hyphenateTag ( component ) === tagName ) ;
7281 if ( componentName ) {
73- const props = await namedPipeClient . getComponentProps ( rootCode . fileName , componentName ) ?? [ ] ;
82+ const props = await tsPluginClient . getComponentProps ( rootCode . fileName , componentName ) ?? [ ] ;
7483 for ( const [ attrName , { offsets } ] of attrs ) {
7584 const propName = props . find ( prop => prop === attrName || hyphenateAttr ( prop ) === attrName ) ;
7685 if ( propName ) {
@@ -93,9 +102,13 @@ export async function convertAttrName(context: ServiceContext, uri: string, casi
93102 return edits ;
94103}
95104
96- export async function getNameCasing ( context : ServiceContext , uri : string ) {
105+ export async function getNameCasing (
106+ context : ServiceContext ,
107+ uri : string ,
108+ tsPluginClient ?: typeof import ( '@vue/typescript-plugin/lib/client' ) ,
109+ ) {
97110
98- const detected = await detect ( context , uri ) ;
111+ const detected = await detect ( context , uri , tsPluginClient ) ;
99112 const [ attr , tag ] = await Promise . all ( [
100113 context . env . getConfiguration ?.< 'autoKebab' | 'autoCamel' | 'kebab' | 'camel' > ( 'vue.complete.casing.props' , uri ) ,
101114 context . env . getConfiguration ?.< 'autoKebab' | 'autoPascal' | 'kebab' | 'pascal' > ( 'vue.complete.casing.tags' , uri ) ,
@@ -109,7 +122,11 @@ export async function getNameCasing(context: ServiceContext, uri: string) {
109122 } ;
110123}
111124
112- export async function detect ( context : ServiceContext , uri : string ) : Promise < {
125+ export async function detect (
126+ context : ServiceContext ,
127+ uri : string ,
128+ tsPluginClient ?: typeof import ( '@vue/typescript-plugin/lib/client' ) ,
129+ ) : Promise < {
113130 tag : TagNameCasing [ ] ,
114131 attr : AttrNameCasing [ ] ,
115132} > {
@@ -153,7 +170,7 @@ export async function detect(context: ServiceContext, uri: string): Promise<{
153170 }
154171 async function getTagNameCase ( file : VueGeneratedCode ) : Promise < TagNameCasing [ ] > {
155172
156- const components = await namedPipeClient . getComponentNames ( file . fileName ) ?? [ ] ;
173+ const components = await tsPluginClient ? .getComponentNames ( file . fileName ) ?? [ ] ;
157174 const tagNames = getTemplateTagsAndAttrs ( file ) ;
158175 const result : TagNameCasing [ ] = [ ] ;
159176
0 commit comments