@@ -18,8 +18,8 @@ connection.onInitialize(params => {
18
18
if ( ! options . typescript ?. tsdk ) {
19
19
throw new Error ( 'typescript.tsdk is required' ) ;
20
20
}
21
- if ( ! options . typescript ?. tsserverRequestCommand ) {
22
- connection . console . warn ( 'typescript.tsserverRequestCommand is required since >= 3.0 for complete TS features' ) ;
21
+ if ( ! options . typescript ?. tsserverRequestCommand && ! options . typescript ?. tsserverNotificationCommands ) {
22
+ connection . console . warn ( 'typescript.tsserverRequestCommand/typescript.tsserverNotificationCommands is required since >= 3.0 for complete TS features' ) ;
23
23
}
24
24
25
25
const { typescript : ts } = loadTsdkByPath ( options . typescript . tsdk , params . locale ) ;
@@ -38,13 +38,23 @@ connection.onInitialize(params => {
38
38
} ) ;
39
39
40
40
let simpleLs : LanguageService | undefined ;
41
+ let tsserverRequestId = 0 ;
42
+
43
+ const tsserverRequestHandlers = new Map < number , ( res : any ) => void > ( ) ;
44
+
45
+ if ( options . typescript . tsserverNotificationCommands ) {
46
+ connection . onNotification ( options . typescript . tsserverNotificationCommands . response , ( [ id , res ] ) => {
47
+ tsserverRequestHandlers . get ( id ) ?.( res ) ;
48
+ tsserverRequestHandlers . delete ( id ) ;
49
+ } ) ;
50
+ }
41
51
42
52
return server . initialize (
43
53
params ,
44
54
{
45
55
setup ( ) { } ,
46
56
async getLanguageService ( uri ) {
47
- if ( uri . scheme === 'file' && options . typescript . tsserverRequestCommand ) {
57
+ if ( uri . scheme === 'file' && ( options . typescript . tsserverRequestCommand || options . typescript . tsserverNotificationCommands ) ) {
48
58
const fileName = uri . fsPath . replace ( / \\ / g, '/' ) ;
49
59
let projectInfoPromise = file2ProjectInfo . get ( fileName ) ;
50
60
if ( ! projectInfoPromise ) {
@@ -87,7 +97,7 @@ connection.onInitialize(params => {
87
97
simpleLs = undefined ;
88
98
} ,
89
99
} ,
90
- getHybridModeLanguageServicePlugins ( ts , options . typescript . tsserverRequestCommand ? {
100
+ getHybridModeLanguageServicePlugins ( ts , ( options . typescript . tsserverRequestCommand || options . typescript . tsserverNotificationCommands ) ? {
91
101
collectExtractProps ( ...args ) {
92
102
return sendTsRequest ( 'vue:collectExtractProps' , args ) ;
93
103
} ,
@@ -139,8 +149,16 @@ connection.onInitialize(params => {
139
149
} : undefined )
140
150
) ;
141
151
142
- function sendTsRequest < T > ( command : string , args : any ) : Promise < T | null > {
143
- return connection . sendRequest < T > ( options . typescript . tsserverRequestCommand ! , [ command , args ] ) ;
152
+ async function sendTsRequest < T > ( command : string , args : any ) : Promise < T | null > {
153
+ if ( options . typescript . tsserverNotificationCommands ) {
154
+ let resolve : ( res : T | null ) => void ;
155
+ const id = ++ tsserverRequestId ;
156
+ tsserverRequestHandlers . set ( id , res => resolve ( res ) ) ;
157
+ connection . sendNotification ( options . typescript . tsserverNotificationCommands . request , [ id , command , args ] ) ;
158
+ return new Promise < T | null > ( _resolve => resolve = _resolve ) ;
159
+ } else {
160
+ return await connection . sendRequest < T > ( options . typescript . tsserverRequestCommand ! , [ command , args ] ) ;
161
+ }
144
162
}
145
163
146
164
function createLs ( server : LanguageServer , tsconfig : string | undefined ) {
0 commit comments