@@ -34,7 +34,7 @@ import * as semver from "semver";
34
34
import * as vscode from "vscode" ;
35
35
import { LanguageClient , ServerOptions } from "vscode-languageclient/node" ;
36
36
import type { Location , Position } from "vscode-languageclient/node" ;
37
- import { getWorkspacesEnabledInfo , setupCheckConfig } from "./enable" ;
37
+ import { getWorkspacesEnabledInfo } from "./enable" ;
38
38
import { denoUpgradePromptAndExecute } from "./upgrade" ;
39
39
import { join } from "path" ;
40
40
import { readFileSync } from "fs" ;
@@ -171,6 +171,20 @@ export function startLanguageServer(
171
171
serverOptions ,
172
172
{
173
173
outputChannel : extensionContext . outputChannel ,
174
+ middleware : {
175
+ workspace : {
176
+ configuration : ( params , token , next ) => {
177
+ const response = next ( params , token ) as Record < string , unknown > [ ] ;
178
+ for ( let i = 0 ; i < response . length ; i ++ ) {
179
+ const item = params . items [ i ] ;
180
+ if ( item . section == "deno" ) {
181
+ transformDenoConfiguration ( extensionContext , response [ i ] ) ;
182
+ }
183
+ }
184
+ return response ;
185
+ } ,
186
+ } ,
187
+ } ,
174
188
...extensionContext . clientOptions ,
175
189
} ,
176
190
) ;
@@ -214,51 +228,34 @@ export function startLanguageServer(
214
228
) ,
215
229
) ;
216
230
217
- // TODO(nayeemrmn): LSP version < 1.40.0 don't support the required API for
218
- // "deno/didChangeDenoConfiguration". Remove this eventually.
219
- if ( semver . lt ( extensionContext . serverInfo . version , "1.40.0" ) ) {
220
- extensionContext . scopesWithDenoJson = new Set ( ) ;
221
- extensionContext . clientSubscriptions . push (
222
- extensionContext . client . onNotification (
223
- "deno/didChangeDenoConfiguration" ,
224
- ( ) => {
225
- extensionContext . tasksSidebar . refresh ( ) ;
226
- } ,
227
- ) ,
228
- ) ;
229
- extensionContext . clientSubscriptions . push (
230
- await setupCheckConfig ( extensionContext ) ,
231
- ) ;
232
- } else {
233
- const scopesWithDenoJson = new Set < string > ( ) ;
234
- extensionContext . scopesWithDenoJson = scopesWithDenoJson ;
235
- extensionContext . clientSubscriptions . push (
236
- extensionContext . client . onNotification (
237
- "deno/didChangeDenoConfiguration" ,
238
- ( { changes } : DidChangeDenoConfigurationParams ) => {
239
- let changedScopes = false ;
240
- for ( const change of changes ) {
241
- if ( change . configurationType != "denoJson" ) {
242
- continue ;
243
- }
244
- if ( change . type == "added" ) {
245
- const scopePath = vscode . Uri . parse ( change . scopeUri ) . fsPath ;
246
- scopesWithDenoJson . add ( scopePath ) ;
247
- changedScopes = true ;
248
- } else if ( change . type == "removed" ) {
249
- const scopePath = vscode . Uri . parse ( change . scopeUri ) . fsPath ;
250
- scopesWithDenoJson . delete ( scopePath ) ;
251
- changedScopes = true ;
252
- }
231
+ const scopesWithDenoJson = new Set < string > ( ) ;
232
+ extensionContext . scopesWithDenoJson = scopesWithDenoJson ;
233
+ extensionContext . clientSubscriptions . push (
234
+ extensionContext . client . onNotification (
235
+ "deno/didChangeDenoConfiguration" ,
236
+ ( { changes } : DidChangeDenoConfigurationParams ) => {
237
+ let changedScopes = false ;
238
+ for ( const change of changes ) {
239
+ if ( change . configurationType != "denoJson" ) {
240
+ continue ;
253
241
}
254
- if ( changedScopes ) {
255
- extensionContext . tsApi ?. refresh ( ) ;
242
+ if ( change . type == "added" ) {
243
+ const scopePath = vscode . Uri . parse ( change . scopeUri ) . fsPath ;
244
+ scopesWithDenoJson . add ( scopePath ) ;
245
+ changedScopes = true ;
246
+ } else if ( change . type == "removed" ) {
247
+ const scopePath = vscode . Uri . parse ( change . scopeUri ) . fsPath ;
248
+ scopesWithDenoJson . delete ( scopePath ) ;
249
+ changedScopes = true ;
256
250
}
257
- extensionContext . tasksSidebar . refresh ( ) ;
258
- } ,
259
- ) ,
260
- ) ;
261
- }
251
+ }
252
+ if ( changedScopes ) {
253
+ extensionContext . tsApi ?. refresh ( ) ;
254
+ }
255
+ extensionContext . tasksSidebar . refresh ( ) ;
256
+ } ,
257
+ ) ,
258
+ ) ;
262
259
263
260
extensionContext . tsApi . refresh ( ) ;
264
261
@@ -308,6 +305,20 @@ function notifyServerSemver(serverVersion: string) {
308
305
) ;
309
306
}
310
307
308
+ /** Mutates the `config` parameter. For compatibility currently. */
309
+ export function transformDenoConfiguration (
310
+ extensionContext : DenoExtensionContext ,
311
+ config : Record < string , unknown > ,
312
+ ) {
313
+ // TODO(nayeemrmn): Deno > 2.0.0-rc.1 expects `deno.unstable` as
314
+ // an array of features. Remove this eventually.
315
+ if (
316
+ semver . lte ( extensionContext . serverInfo ?. version || "1.0.0" , "2.0.0-rc.1" )
317
+ ) {
318
+ config . unstable = ! ! config . unstable ;
319
+ }
320
+ }
321
+
311
322
function showWelcomePageIfFirstUse (
312
323
context : vscode . ExtensionContext ,
313
324
extensionContext : DenoExtensionContext ,
@@ -363,8 +374,12 @@ export function test(
363
374
const testArgs : string [ ] = [
364
375
...( config . get < string [ ] > ( "codeLens.testArgs" ) ?? [ ] ) ,
365
376
] ;
366
- if ( config . get ( "unstable" ) ) {
367
- testArgs . push ( "--unstable" ) ;
377
+ const unstable = config . get ( "unstable" ) as string [ ] ?? [ ] ;
378
+ for ( const unstableFeature of unstable ) {
379
+ const flag = `--unstable-${ unstableFeature } ` ;
380
+ if ( ! testArgs . includes ( flag ) ) {
381
+ testArgs . push ( flag ) ;
382
+ }
368
383
}
369
384
if ( options ?. inspect ) {
370
385
testArgs . push ( getInspectArg ( extensionContext . serverInfo ?. version ) ) ;
0 commit comments