Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as util from "util";

import * as vscode from "vscode";
import { registerSidebar } from "./tasks_sidebar";
import { getDenoInfoJson } from "./util";

function handleConfigurationChange(event: vscode.ConfigurationChangeEvent) {
if (
Expand Down Expand Up @@ -79,6 +80,9 @@ export async function activate(
): Promise<void> {
extensionContext.outputChannel = extensionContext.outputChannel ??
vscode.window.createOutputChannel(LANGUAGE_CLIENT_NAME);
extensionContext.denoInfoJson = await getDenoInfoJson(
extensionContext.outputChannel,
);
const p2cMap = new Map<string, string>();
extensionContext.clientOptions = {
documentSelector: [
Expand Down Expand Up @@ -228,6 +232,7 @@ export async function activate(
enableSettingsUnscoped: extensionContext.enableSettingsUnscoped,
enableSettingsByFolder: extensionContext.enableSettingsByFolder,
scopesWithDenoJson: Array.from(extensionContext.scopesWithDenoJson ?? []),
npmCache: extensionContext.denoInfoJson?.npmCache ?? null,
};
});

Expand Down
1 change: 1 addition & 0 deletions client/src/shared_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface PluginSettings {
enableSettingsUnscoped: EnableSettings;
enableSettingsByFolder: [string, EnableSettings][];
scopesWithDenoJson: string[];
npmCache: string | null;
}
5 changes: 5 additions & 0 deletions client/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface DenoExtensionContext {
| ServerCapabilities<DenoExperimental>
| undefined;
scopesWithDenoJson: Set<string> | undefined;
denoInfoJson: DenoInfoJson | null;
statusBar: DenoStatusBar;
tsApi: TsApi;
outputChannel: vscode.OutputChannel;
Expand All @@ -48,6 +49,10 @@ export interface TestCommandOptions {
inspect: boolean;
}

export interface DenoInfoJson {
npmCache?: string;
}

export interface UpgradeAvailable {
latestVersion: string;
isCanary: boolean;
Expand Down
34 changes: 34 additions & 0 deletions client/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
} from "vscode";
import * as jsoncParser from "jsonc-parser/lib/esm/main.js";
import { semver } from "./semver";
import type { DenoInfoJson } from "./types";
import { spawnSync } from "child_process";
import type * as vscode from "vscode";

/** Assert that the condition is "truthy", otherwise throw. */
export function assert(cond: unknown, msg = "Assertion failed."): asserts cond {
Expand Down Expand Up @@ -112,6 +115,37 @@ async function getDefaultDenoCommand() {
}
}

export async function getDenoInfoJson(
outputChannel: vscode.OutputChannel,
): Promise<DenoInfoJson | null> {
try {
const command = await getDenoCommandName();
const { stdout, stderr, status, error } = spawnSync(command, [
"info",
"--json",
], {
encoding: "utf-8",
stdio: ["ignore", "pipe", "pipe"],
env: {
...process.env,
"NO_COLOR": "1",
},
});
if (error) {
throw error;
}
if (status != 0) {
throw `Command failed: ${stderr}`;
}
return JSON.parse(stdout);
} catch (error) {
outputChannel.appendLine(
`Couldn't get 'deno info --json' output: ${error}`,
);
return null;
}
}

function fileExists(executableFilePath: string): Promise<boolean> {
return new Promise<boolean>((resolve) => {
fs.stat(executableFilePath, (err, stat) => {
Expand Down
5 changes: 5 additions & 0 deletions typescript-deno-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Plugin implements ts.server.PluginModule {
if (!pluginSettings) {
return false;
}
if (pluginSettings.npmCache) {
if (pathStartsWith(fileName, pluginSettings.npmCache)) {
return true;
}
}
const enableSettings =
pluginSettings.enableSettingsByFolder?.find(([workspace, _]) =>
pathStartsWith(fileName, workspace)
Expand Down