@@ -5,20 +5,13 @@ import { createLanguage, createParsedCommandLine, createVueLanguagePlugin, getDe
5
5
import { createLanguageService , createUriMap , getHybridModeLanguageServicePlugins , type LanguageService } from '@vue/language-service' ;
6
6
import * as ts from 'typescript' ;
7
7
import { URI } from 'vscode-uri' ;
8
- import type { VueInitializationOptions } from './lib/types' ;
9
8
10
9
const connection = createConnection ( ) ;
11
10
const server = createServer ( connection ) ;
12
11
13
12
connection . listen ( ) ;
14
13
15
14
connection . onInitialize ( params => {
16
- const options : VueInitializationOptions = params . initializationOptions ;
17
-
18
- if ( ! options . typescript ?. tsserverRequestCommand ) {
19
- connection . console . warn ( 'typescript.tsserverRequestCommand is required since >= 3.0 for complete TS features' ) ;
20
- }
21
-
22
15
const tsconfigProjects = createUriMap < LanguageService > ( ) ;
23
16
const file2ProjectInfo = new Map < string , Promise < ts . server . protocol . ProjectInfo | null > > ( ) ;
24
17
@@ -38,19 +31,17 @@ connection.onInitialize(params => {
38
31
39
32
const tsserverRequestHandlers = new Map < number , ( res : any ) => void > ( ) ;
40
33
41
- if ( Array . isArray ( options . typescript . tsserverRequestCommand ) ) {
42
- connection . onNotification ( options . typescript . tsserverRequestCommand [ 1 ] , ( [ id , res ] ) => {
43
- tsserverRequestHandlers . get ( id ) ?.( res ) ;
44
- tsserverRequestHandlers . delete ( id ) ;
45
- } ) ;
46
- }
34
+ connection . onNotification ( 'tsserver/response' , ( [ id , res ] ) => {
35
+ tsserverRequestHandlers . get ( id ) ?.( res ) ;
36
+ tsserverRequestHandlers . delete ( id ) ;
37
+ } ) ;
47
38
48
39
return server . initialize (
49
40
params ,
50
41
{
51
42
setup ( ) { } ,
52
43
async getLanguageService ( uri ) {
53
- if ( uri . scheme === 'file' && options . typescript . tsserverRequestCommand ) {
44
+ if ( uri . scheme === 'file' ) {
54
45
const fileName = uri . fsPath . replace ( / \\ / g, '/' ) ;
55
46
let projectInfoPromise = file2ProjectInfo . get ( fileName ) ;
56
47
if ( ! projectInfoPromise ) {
@@ -83,17 +74,17 @@ connection.onInitialize(params => {
83
74
] . filter ( promise => ! ! promise ) ) ;
84
75
} ,
85
76
reload ( ) {
86
- for ( const ls of [
87
- ...tsconfigProjects . values ( ) ,
88
- simpleLs ,
89
- ] ) {
90
- ls ?. dispose ( ) ;
77
+ for ( const ls of tsconfigProjects . values ( ) ) {
78
+ ls . dispose ( ) ;
91
79
}
92
80
tsconfigProjects . clear ( ) ;
93
- simpleLs = undefined ;
81
+ if ( simpleLs ) {
82
+ simpleLs . dispose ( ) ;
83
+ simpleLs = undefined ;
84
+ }
94
85
} ,
95
86
} ,
96
- getHybridModeLanguageServicePlugins ( ts , options . typescript . tsserverRequestCommand ? {
87
+ getHybridModeLanguageServicePlugins ( ts , {
97
88
collectExtractProps ( ...args ) {
98
89
return sendTsRequest ( 'vue:collectExtractProps' , args ) ;
99
90
} ,
@@ -142,20 +133,15 @@ connection.onInitialize(params => {
142
133
) ;
143
134
return ts . displayPartsToString ( result ?. displayParts ?? [ ] ) ;
144
135
} ,
145
- } : undefined )
136
+ } )
146
137
) ;
147
138
148
139
async function sendTsRequest < T > ( command : string , args : any ) : Promise < T | null > {
149
- if ( typeof options . typescript . tsserverRequestCommand === 'string' ) {
150
- return await connection . sendRequest < T > ( options . typescript . tsserverRequestCommand , [ command , args ] ) ;
151
- } else {
152
- const [ requestCommand ] = options . typescript . tsserverRequestCommand ! ;
153
- return await new Promise < T | null > ( resolve => {
154
- const requestId = ++ tsserverRequestId ;
155
- tsserverRequestHandlers . set ( requestId , resolve ) ;
156
- connection . sendNotification ( requestCommand , [ command , args , requestId ] ) ;
157
- } ) ;
158
- }
140
+ return await new Promise < T | null > ( resolve => {
141
+ const requestId = ++ tsserverRequestId ;
142
+ tsserverRequestHandlers . set ( requestId , resolve ) ;
143
+ connection . sendNotification ( 'tsserver/request' , [ requestId , command , args ] ) ;
144
+ } ) ;
159
145
}
160
146
161
147
function createLs ( server : LanguageServer , tsconfig : string | undefined ) {
0 commit comments