@@ -1611,7 +1611,7 @@ function getContentDocumentSelectorFromConfigFile(
1611
1611
}
1612
1612
1613
1613
class TW {
1614
- private initialized = false
1614
+ private initPromise : Promise < void >
1615
1615
private lspHandlersAdded = false
1616
1616
private workspaces : Map < string , { name : string ; workspaceFsPath : string } >
1617
1617
private projects : Map < string , ProjectService >
@@ -1631,12 +1631,15 @@ class TW {
1631
1631
}
1632
1632
1633
1633
async init ( ) : Promise < void > {
1634
- if ( this . initialized ) return
1634
+ if ( ! this . initPromise ) {
1635
+ this . initPromise = this . _init ( )
1636
+ }
1637
+ await this . initPromise
1638
+ }
1635
1639
1640
+ private async _init ( ) : Promise < void > {
1636
1641
clearRequireCache ( )
1637
1642
1638
- this . initialized = true
1639
-
1640
1643
let base : string
1641
1644
if ( this . initializeParams . rootUri ) {
1642
1645
base = URI . parse ( this . initializeParams . rootUri ) . fsPath
@@ -2131,7 +2134,7 @@ class TW {
2131
2134
}
2132
2135
}
2133
2136
2134
- private setupLSPHandlers ( ) {
2137
+ setupLSPHandlers ( ) {
2135
2138
if ( this . lspHandlersAdded ) {
2136
2139
return
2137
2140
}
@@ -2147,6 +2150,10 @@ class TW {
2147
2150
}
2148
2151
2149
2152
private updateCapabilities ( ) {
2153
+ if ( ! supportsDynamicRegistration ( this . initializeParams ) ) {
2154
+ return
2155
+ }
2156
+
2150
2157
if ( this . registrations ) {
2151
2158
this . registrations . then ( ( r ) => r . dispose ( ) )
2152
2159
}
@@ -2221,30 +2228,37 @@ class TW {
2221
2228
}
2222
2229
2223
2230
async onDocumentColor ( params : DocumentColorParams ) : Promise < ColorInformation [ ] > {
2231
+ await this . init ( )
2224
2232
return this . getProject ( params . textDocument ) ?. onDocumentColor ( params ) ?? [ ]
2225
2233
}
2226
2234
2227
2235
async onColorPresentation ( params : ColorPresentationParams ) : Promise < ColorPresentation [ ] > {
2236
+ await this . init ( )
2228
2237
return this . getProject ( params . textDocument ) ?. onColorPresentation ( params ) ?? [ ]
2229
2238
}
2230
2239
2231
2240
async onHover ( params : TextDocumentPositionParams ) : Promise < Hover > {
2241
+ await this . init ( )
2232
2242
return this . getProject ( params . textDocument ) ?. onHover ( params ) ?? null
2233
2243
}
2234
2244
2235
2245
async onCompletion ( params : CompletionParams ) : Promise < CompletionList > {
2246
+ await this . init ( )
2236
2247
return this . getProject ( params . textDocument ) ?. onCompletion ( params ) ?? null
2237
2248
}
2238
2249
2239
2250
async onCompletionResolve ( item : CompletionItem ) : Promise < CompletionItem > {
2251
+ await this . init ( )
2240
2252
return this . projects . get ( item . data ?. _projectKey ) ?. onCompletionResolve ( item ) ?? null
2241
2253
}
2242
2254
2243
- onCodeAction ( params : CodeActionParams ) : Promise < CodeAction [ ] > {
2255
+ async onCodeAction ( params : CodeActionParams ) : Promise < CodeAction [ ] > {
2256
+ await this . init ( )
2244
2257
return this . getProject ( params . textDocument ) ?. onCodeAction ( params ) ?? null
2245
2258
}
2246
2259
2247
- onDocumentLinks ( params : DocumentLinkParams ) : DocumentLink [ ] {
2260
+ async onDocumentLinks ( params : DocumentLinkParams ) : Promise < DocumentLink [ ] > {
2261
+ await this . init ( )
2248
2262
return this . getProject ( params . textDocument ) ?. onDocumentLinks ( params ) ?? null
2249
2263
}
2250
2264
@@ -2274,7 +2288,7 @@ class TW {
2274
2288
restart ( ) : void {
2275
2289
console . log ( '----------\nRESTARTING\n----------' )
2276
2290
this . dispose ( )
2277
- this . initialized = false
2291
+ this . initPromise = undefined
2278
2292
this . init ( )
2279
2293
}
2280
2294
}
@@ -2306,9 +2320,8 @@ class DocumentService {
2306
2320
}
2307
2321
}
2308
2322
2309
- function supportsDynamicRegistration ( connection : Connection , params : InitializeParams ) : boolean {
2323
+ function supportsDynamicRegistration ( params : InitializeParams ) : boolean {
2310
2324
return (
2311
- connection . onInitialized &&
2312
2325
params . capabilities . textDocument . hover ?. dynamicRegistration &&
2313
2326
params . capabilities . textDocument . colorProvider ?. dynamicRegistration &&
2314
2327
params . capabilities . textDocument . codeAction ?. dynamicRegistration &&
@@ -2322,15 +2335,15 @@ const tw = new TW(connection)
2322
2335
connection . onInitialize ( async ( params : InitializeParams ) : Promise < InitializeResult > => {
2323
2336
tw . initializeParams = params
2324
2337
2325
- if ( supportsDynamicRegistration ( connection , params ) ) {
2338
+ if ( supportsDynamicRegistration ( params ) ) {
2326
2339
return {
2327
2340
capabilities : {
2328
2341
textDocumentSync : TextDocumentSyncKind . Full ,
2329
2342
} ,
2330
2343
}
2331
2344
}
2332
2345
2333
- await tw . init ( )
2346
+ tw . setupLSPHandlers ( )
2334
2347
2335
2348
return {
2336
2349
capabilities : {
0 commit comments