@@ -14,6 +14,7 @@ import * as tasks from "./tasks";
1414import { DenoTestController , TestingFeature } from "./testing" ;
1515import type {
1616 DenoExtensionContext ,
17+ DidChangeDenoConfigurationParams ,
1718 DidUpgradeCheckParams ,
1819 TestCommandOptions ,
1920} from "./types" ;
@@ -32,7 +33,7 @@ import * as semver from "semver";
3233import * as vscode from "vscode" ;
3334import { LanguageClient , ServerOptions } from "vscode-languageclient/node" ;
3435import type { Location , Position } from "vscode-languageclient/node" ;
35- import { getWorkspacesEnabledInfo } from "./enable" ;
36+ import { getWorkspacesEnabledInfo , setupCheckConfig } from "./enable" ;
3637import { denoUpgradePromptAndExecute } from "./upgrade" ;
3738
3839// deno-lint-ignore no-explicit-any
@@ -82,13 +83,15 @@ export function startLanguageServer(
8283 if ( extensionContext . client ) {
8384 const client = extensionContext . client ;
8485 extensionContext . client = undefined ;
85- extensionContext . testController ?. dispose ( ) ;
86- extensionContext . testController = undefined ;
86+ for ( const disposable of extensionContext . clientSubscriptions ?? [ ] ) {
87+ disposable . dispose ( ) ;
88+ }
8789 extensionContext . statusBar . refresh ( extensionContext ) ;
8890 vscode . commands . executeCommand ( "setContext" , ENABLEMENT_FLAG , false ) ;
8991 const timeoutMs = 10_000 ;
9092 await client . stop ( timeoutMs ) ;
9193 }
94+ extensionContext . clientSubscriptions = [ ] ;
9295
9396 // Start a new language server
9497 const command = await getDenoCommandPath ( ) ;
@@ -151,34 +154,76 @@ export function startLanguageServer(
151154 ) ;
152155 extensionContext . serverCapabilities = client . initializeResult ?. capabilities ;
153156 extensionContext . statusBar . refresh ( extensionContext ) ;
154- context . subscriptions . push ( extensionContext . client . onNotification (
155- "deno/didChangeDenoConfiguration" ,
156- ( ) => {
157- extensionContext . tasksSidebar . refresh ( ) ;
158- } ,
159- ) ) ;
160- context . subscriptions . push ( extensionContext . client . onNotification (
161- "deno/didUpgradeCheck" ,
162- ( params : DidUpgradeCheckParams ) => {
163- if ( extensionContext . serverInfo ) {
164- extensionContext . serverInfo . upgradeAvailable =
165- params . upgradeAvailable ;
166- extensionContext . statusBar . refresh ( extensionContext ) ;
167- }
168- } ,
169- ) ) ;
157+
158+ extensionContext . clientSubscriptions . push (
159+ extensionContext . client . onNotification (
160+ "deno/didUpgradeCheck" ,
161+ ( params : DidUpgradeCheckParams ) => {
162+ if ( extensionContext . serverInfo ) {
163+ extensionContext . serverInfo . upgradeAvailable =
164+ params . upgradeAvailable ;
165+ extensionContext . statusBar . refresh ( extensionContext ) ;
166+ }
167+ } ,
168+ ) ,
169+ ) ;
170170
171171 if ( testingFeature . enabled ) {
172- context . subscriptions . push ( new DenoTestController ( extensionContext ) ) ;
172+ extensionContext . clientSubscriptions . push (
173+ new DenoTestController ( extensionContext . client ) ,
174+ ) ;
173175 }
174176
175- context . subscriptions . push (
177+ extensionContext . clientSubscriptions . push (
176178 client . onNotification (
177179 registryState ,
178180 createRegistryStateHandler ( ) ,
179181 ) ,
180182 ) ;
181183
184+ // TODO(nayeemrmn): LSP version < 1.40.0 don't support the required API for
185+ // "deno/didChangeDenoConfiguration". Remove this eventually.
186+ if ( semver . lt ( extensionContext . serverInfo . version , "1.40.0" ) ) {
187+ extensionContext . scopesWithDenoJson = new Set ( ) ;
188+ extensionContext . clientSubscriptions . push (
189+ extensionContext . client . onNotification (
190+ "deno/didChangeDenoConfiguration" ,
191+ ( ) => {
192+ extensionContext . tasksSidebar . refresh ( ) ;
193+ } ,
194+ ) ,
195+ ) ;
196+ extensionContext . clientSubscriptions . push (
197+ await setupCheckConfig ( extensionContext ) ,
198+ ) ;
199+ } else {
200+ const scopesWithDenoJson = new Set < string > ( ) ;
201+ extensionContext . scopesWithDenoJson = scopesWithDenoJson ;
202+ extensionContext . clientSubscriptions . push (
203+ extensionContext . client . onNotification (
204+ "deno/didChangeDenoConfiguration" ,
205+ ( { changes } : DidChangeDenoConfigurationParams ) => {
206+ let changedScopes = false ;
207+ for ( const change of changes ) {
208+ if ( change . type == "added" ) {
209+ const scopePath = vscode . Uri . parse ( change . scopeUri ) . fsPath ;
210+ scopesWithDenoJson . add ( scopePath ) ;
211+ changedScopes = true ;
212+ } else if ( change . type == "removed" ) {
213+ const scopePath = vscode . Uri . parse ( change . scopeUri ) . fsPath ;
214+ scopesWithDenoJson . delete ( scopePath ) ;
215+ changedScopes = true ;
216+ }
217+ }
218+ if ( changedScopes ) {
219+ extensionContext . tsApi ?. refresh ( ) ;
220+ }
221+ extensionContext . tasksSidebar . refresh ( ) ;
222+ } ,
223+ ) ,
224+ ) ;
225+ }
226+
182227 extensionContext . tsApi . refresh ( ) ;
183228
184229 if (
0 commit comments