Skip to content

Commit 155255f

Browse files
authored
feat: unstable setting as list (#1159)
1 parent 2c5964d commit 155255f

File tree

6 files changed

+83
-106
lines changed

6 files changed

+83
-106
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ extension has the following configuration options:
224224
To see which versions of this extension can be used with each version of the
225225
Deno CLI, consult the following table.
226226

227-
| Deno CLI | vscode-deno |
228-
| -------------- | --------------- |
229-
| 1.37.2 onwards | 3.34.0 onwards |
230-
| 1.37.1 | 3.32.0 - 3.33.3 |
231-
| 1.37.0 | 3.28.0 - 3.31.0 |
232-
| ? - 1.36.4 | 3.27.0 |
227+
| Deno CLI | vscode-deno |
228+
| --------------- | --------------- |
229+
| 1.40.0 onwards | TODO onwards |
230+
| 1.37.2 - 1.39.4 | 3.34.0 - 3.39.0 |
231+
| 1.37.1 | 3.32.0 - 3.33.3 |
232+
| 1.37.0 | 3.28.0 - 3.31.0 |
233+
| ? - 1.36.4 | 3.27.0 |
233234

234235
Version ranges are inclusive. Incompatibilites prior to 3.27.0 were not tracked.
235236

client/src/commands.ts

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import * as semver from "semver";
3434
import * as vscode from "vscode";
3535
import { LanguageClient, ServerOptions } from "vscode-languageclient/node";
3636
import type { Location, Position } from "vscode-languageclient/node";
37-
import { getWorkspacesEnabledInfo, setupCheckConfig } from "./enable";
37+
import { getWorkspacesEnabledInfo } from "./enable";
3838
import { denoUpgradePromptAndExecute } from "./upgrade";
3939
import { join } from "path";
4040
import { readFileSync } from "fs";
@@ -171,6 +171,20 @@ export function startLanguageServer(
171171
serverOptions,
172172
{
173173
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+
},
174188
...extensionContext.clientOptions,
175189
},
176190
);
@@ -214,51 +228,34 @@ export function startLanguageServer(
214228
),
215229
);
216230

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;
253241
}
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;
256250
}
257-
extensionContext.tasksSidebar.refresh();
258-
},
259-
),
260-
);
261-
}
251+
}
252+
if (changedScopes) {
253+
extensionContext.tsApi?.refresh();
254+
}
255+
extensionContext.tasksSidebar.refresh();
256+
},
257+
),
258+
);
262259

263260
extensionContext.tsApi.refresh();
264261

@@ -308,6 +305,20 @@ function notifyServerSemver(serverVersion: string) {
308305
);
309306
}
310307

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+
311322
function showWelcomePageIfFirstUse(
312323
context: vscode.ExtensionContext,
313324
extensionContext: DenoExtensionContext,
@@ -363,8 +374,12 @@ export function test(
363374
const testArgs: string[] = [
364375
...(config.get<string[]>("codeLens.testArgs") ?? []),
365376
];
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+
}
368383
}
369384
if (options?.inspect) {
370385
testArgs.push(getInspectArg(extensionContext.serverInfo?.version));

client/src/enable.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -87,49 +87,6 @@ export function refreshEnableSettings(extensionContext: DenoExtensionContext) {
8787
extensionContext.enableSettingsByFolder.reverse();
8888
}
8989

90-
/** Check the current workspace */
91-
export async function setupCheckConfig(
92-
extensionContext: DenoExtensionContext,
93-
): Promise<vscode.Disposable> {
94-
async function updateHasDenoConfig() {
95-
const uri = vscode.workspace.workspaceFolders?.[0]?.uri;
96-
if (!uri) {
97-
return;
98-
}
99-
extensionContext.scopesWithDenoJson = new Set();
100-
if (
101-
await exists(vscode.Uri.joinPath(uri, "./deno.json")) ||
102-
await exists(vscode.Uri.joinPath(uri, "./deno.jsonc"))
103-
) {
104-
extensionContext.scopesWithDenoJson.add(uri.fsPath);
105-
}
106-
extensionContext.tsApi?.refresh();
107-
}
108-
109-
await updateHasDenoConfig();
110-
111-
const subscriptions: vscode.Disposable[] = [];
112-
// create a file watcher, so if a config file is added to the workspace we
113-
// will check enablement
114-
const configFileWatcher = vscode.workspace.createFileSystemWatcher(
115-
"**/deno.{json,jsonc}",
116-
false,
117-
true,
118-
false,
119-
);
120-
subscriptions.push(configFileWatcher);
121-
subscriptions.push(configFileWatcher.onDidCreate(updateHasDenoConfig));
122-
subscriptions.push(configFileWatcher.onDidDelete(updateHasDenoConfig));
123-
124-
return {
125-
dispose() {
126-
for (const disposable of subscriptions) {
127-
disposable.dispose();
128-
}
129-
},
130-
};
131-
}
132-
13390
async function exists(uri: vscode.Uri): Promise<boolean> {
13491
try {
13592
await vscode.workspace.fs.stat(uri);

client/src/extension.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ export async function activate(
138138
},
139139
diagnosticCollectionName: "deno",
140140
initializationOptions: () => {
141+
const denoConfiguration = vscode.workspace.getConfiguration().get(
142+
EXTENSION_NS,
143+
) as Record<string, unknown>;
144+
commands.transformDenoConfiguration(extensionContext, denoConfiguration);
141145
return {
142-
...vscode.workspace.getConfiguration().get(EXTENSION_NS),
146+
...denoConfiguration,
143147
javascript: vscode.workspace.getConfiguration().get("javascript"),
144148
typescript: vscode.workspace.getConfiguration().get("typescript"),
145149
enableBuiltinCommands: true,

client/src/upgrade.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export async function denoUpgradePromptAndExecute(
2626
return;
2727
}
2828
const args = ["upgrade"];
29-
if (config.get("unstable")) {
30-
args.push("--unstable");
29+
const unstable = config.get("unstable") as string[] ?? [];
30+
for (const unstableFeature of unstable) {
31+
args.push(`--unstable-${unstableFeature}`);
3132
}
3233
if (isCanary) {
3334
args.push("--canary");

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,13 @@
508508
"scope": "window"
509509
},
510510
"deno.unstable": {
511-
"type": "boolean",
512-
"default": false,
513-
"markdownDescription": "Controls if tests will be run with the the `--unstable` flag when running tests via the explorer.\n\n**Not recommended to be enabled globally.**",
514-
"scope": "resource",
515-
"examples": [
516-
true,
517-
false
518-
]
511+
"type": "array",
512+
"items": {
513+
"type": "string"
514+
},
515+
"default": [],
516+
"markdownDescription": "Controls which `--unstable-*` features tests will be run with when running them via the explorer.\n\n**Not recommended to be enabled globally.**",
517+
"scope": "resource"
519518
},
520519
"deno.lint": {
521520
"type": "boolean",

0 commit comments

Comments
 (0)