Skip to content
Draft
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
12 changes: 10 additions & 2 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ import {
ErrorCodes,
} from "vscode-languageclient/node";

import { LSP_NAME, ClientInterface, Addon, SUPPORTED_LANGUAGE_IDS, FEATURE_FLAGS, featureEnabled } from "./common";
import {
LSP_NAME,
ClientInterface,
Addon,
SUPPORTED_LANGUAGE_IDS,
FEATURE_FLAGS,
featureEnabled,
isWindows,
} from "./common";
import { Ruby } from "./ruby";
import { WorkspaceChannel } from "./workspaceChannel";

Expand Down Expand Up @@ -121,7 +129,7 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS.
} else {
const workspacePath = workspaceFolder.uri.fsPath;
const command =
path.basename(workspacePath) === "ruby-lsp" && os.platform() !== "win32"
path.basename(workspacePath) === "ruby-lsp" && !isWindows()
? path.join(workspacePath, "exe", "ruby-lsp")
: "ruby-lsp";

Expand Down
6 changes: 6 additions & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exec } from "child_process";
import { createHash } from "crypto";
import { promisify } from "util";
import os from "os";

import * as vscode from "vscode";
import { State } from "vscode-languageclient";
Expand Down Expand Up @@ -150,3 +151,8 @@ export function featureEnabled(feature: keyof typeof FEATURE_FLAGS): boolean {
export function pathToUri(basePath: string, ...segments: string[]): vscode.Uri {
return vscode.Uri.joinPath(vscode.Uri.file(basePath), ...segments);
}

// Helper to check if running on Windows platform
export function isWindows(): boolean {
return os.platform() === "win32";
}
5 changes: 2 additions & 3 deletions vscode/src/debugger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import net from "net";
import os from "os";
import { ChildProcessWithoutNullStreams, spawn } from "child_process";

import * as vscode from "vscode";

import { LOG_CHANNEL, asyncExec } from "./common";
import { LOG_CHANNEL, asyncExec, isWindows } from "./common";
import { Workspace } from "./workspace";

class TerminalLogger {
Expand Down Expand Up @@ -220,7 +219,7 @@ export class Debugger implements vscode.DebugAdapterDescriptorFactory, vscode.De
const configuration = session.configuration;
const workspaceFolder = configuration.targetFolder;
const cwd = workspaceFolder.path;
const port = os.platform() === "win32" ? await this.availablePort() : undefined;
const port = isWindows() ? await this.availablePort() : undefined;

return new Promise((resolve, reject) => {
const args = ["exec", "rdbg"];
Expand Down
5 changes: 2 additions & 3 deletions vscode/src/rails.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os from "os";

import * as vscode from "vscode";

import { Workspace } from "./workspace";
import { isWindows } from "./common";

const BASE_COMMAND = os.platform() === "win32" ? "ruby bin/rails" : "bin/rails";
const BASE_COMMAND = isWindows() ? "ruby bin/rails" : "bin/rails";

export class Rails {
private readonly showWorkspacePick: () => Promise<Workspace | undefined>;
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as vscode from "vscode";

import { RubyInterface } from "./common";
import { WorkspaceChannel } from "./workspaceChannel";
import { Shadowenv, UntrustedWorkspaceError } from "./ruby/shadowenv";
import { Shadowenv } from "./ruby/shadowenv";
import { UntrustedWorkspaceError } from "./ruby/errors";
import { Chruby } from "./ruby/chruby";
import { VersionManager, DetectionResult } from "./ruby/versionManager";
import { Mise } from "./ruby/mise";
Expand Down
22 changes: 10 additions & 12 deletions vscode/src/ruby/asdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as vscode from "vscode";
import { VersionManager, ActivationResult, DetectionResult } from "./versionManager";
import { WorkspaceChannel } from "../workspaceChannel";
import { pathToUri } from "../common";
import { ExecutableNotFoundError } from "./errors";

// A tool to manage multiple runtime versions with a single CLI tool
//
Expand Down Expand Up @@ -75,12 +76,10 @@ export class Asdf extends VersionManager {
} else if (result.type === "semantic") {
// Use ASDF from PATH
} else {
throw new Error(
`Could not find ASDF installation. Searched in ${[
...Asdf.getPossibleExecutablePaths(),
...Asdf.getPossibleScriptPaths(),
].join(", ")}`,
);
throw new ExecutableNotFoundError("asdf", [
...Asdf.getPossibleExecutablePaths().map((uri) => uri.fsPath),
...Asdf.getPossibleScriptPaths().map((uri) => uri.fsPath),
]);
}
}

Expand Down Expand Up @@ -115,12 +114,11 @@ export class Asdf extends VersionManager {

const configuredPath = vscode.Uri.file(asdfPath);

try {
await vscode.workspace.fs.stat(configuredPath);
this.outputChannel.info(`Using configured ASDF executable path: ${asdfPath}`);
return configuredPath.fsPath;
} catch (_error: any) {
throw new Error(`ASDF executable configured as ${configuredPath.fsPath}, but that file doesn't exist`);
if (!(await VersionManager.pathExists(configuredPath))) {
throw new ExecutableNotFoundError("asdf", [configuredPath.fsPath], configuredPath.fsPath);
}

this.outputChannel.info(`Using configured ASDF executable path: ${asdfPath}`);
return configuredPath.fsPath;
}
}
Loading