Skip to content

Commit

Permalink
Fix file paths for exec launcher on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 16, 2025
1 parent bbd0c84 commit 2824afe
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 118 deletions.
2 changes: 1 addition & 1 deletion exe/ruby-lsp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if ENV["BUNDLE_GEMFILE"].nil?
# which gives us the opportunity to control which specs are activated and enter degraded mode if any gems failed to
# install rather than failing to boot the server completely
if options[:launcher]
command = +"#{Gem.ruby} #{File.expand_path("ruby-lsp-launcher", __dir__)}"
command = +"#{File.realpath(Gem.ruby)} #{File.realpath(File.expand_path("ruby-lsp-launcher", __dir__))}"
command << " --debug" if options[:debug]
exit exec(command)
end
Expand Down
88 changes: 4 additions & 84 deletions vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,12 @@ import {
} from "vscode-languageclient/node";
import { after, afterEach, before } from "mocha";

import { Ruby, ManagerIdentifier } from "../../ruby";
import { Ruby } from "../../ruby";
import Client from "../../client";
import { WorkspaceChannel } from "../../workspaceChannel";
import { RUBY_VERSION, MAJOR, MINOR } from "../rubyVersion";
import { MAJOR, MINOR } from "../rubyVersion";

import { FAKE_TELEMETRY } from "./fakeTelemetry";

class FakeLogger {
receivedMessages = "";

trace(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

debug(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

info(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

warn(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

error(error: string | Error, ..._args: any[]): void {
this.receivedMessages += error.toString();
}

append(value: string): void {
this.receivedMessages += value;
}

appendLine(value: string): void {
this.receivedMessages += value;
}
}
import { createSymlinksForCi, FAKE_TELEMETRY, FakeLogger } from "./testHelpers";

async function launchClient(workspaceUri: vscode.Uri) {
const workspaceFolder: vscode.WorkspaceFolder = {
Expand Down Expand Up @@ -94,55 +62,7 @@ async function launchClient(workspaceUri: vscode.Uri) {
.getConfiguration("rubyLsp")
.update("linters", ["rubocop_internal"], true);

if (os.platform() === "linux") {
await vscode.workspace
.getConfiguration("rubyLsp")
.update(
"rubyVersionManager",
{ identifier: ManagerIdentifier.Chruby },
true,
);

fs.mkdirSync(path.join(os.homedir(), ".rubies"), { recursive: true });
fs.symlinkSync(
`/opt/hostedtoolcache/Ruby/${RUBY_VERSION}/x64`,
path.join(os.homedir(), ".rubies", RUBY_VERSION),
);
} else if (os.platform() === "darwin") {
await vscode.workspace
.getConfiguration("rubyLsp")
.update(
"rubyVersionManager",
{ identifier: ManagerIdentifier.Chruby },
true,
);

fs.mkdirSync(path.join(os.homedir(), ".rubies"), { recursive: true });
fs.symlinkSync(
`/Users/runner/hostedtoolcache/Ruby/${RUBY_VERSION}/arm64`,
path.join(os.homedir(), ".rubies", RUBY_VERSION),
);
} else {
await vscode.workspace
.getConfiguration("rubyLsp")
.update(
"rubyVersionManager",
{ identifier: ManagerIdentifier.RubyInstaller },
true,
);

fs.symlinkSync(
path.join(
"C:",
"hostedtoolcache",
"windows",
"Ruby",
RUBY_VERSION,
"x64",
),
path.join("C:", `Ruby${MAJOR}${MINOR}-${os.arch()}`),
);
}
await createSymlinksForCi();
}

const ruby = new Ruby(
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/test/suite/debugger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { WorkspaceChannel } from "../../workspaceChannel";
import { LOG_CHANNEL, asyncExec } from "../../common";
import { RUBY_VERSION } from "../rubyVersion";

import { FAKE_TELEMETRY } from "./fakeTelemetry";
import { FAKE_TELEMETRY } from "./testHelpers";

suite("Debugger", () => {
test("Provide debug configurations returns the default configs", () => {
Expand Down
29 changes: 0 additions & 29 deletions vscode/src/test/suite/fakeTelemetry.ts

This file was deleted.

93 changes: 93 additions & 0 deletions vscode/src/test/suite/launch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable no-process-env */
import assert from "assert";
import path from "path";

import * as vscode from "vscode";
import { State } from "vscode-languageclient/node";
import { before } from "mocha";
import sinon from "sinon";

import { Ruby } from "../../ruby";
import Client from "../../client";
import { WorkspaceChannel } from "../../workspaceChannel";
import * as common from "../../common";

import { createSymlinksForCi, FAKE_TELEMETRY, FakeLogger } from "./testHelpers";

suite("Launch integrations", () => {
before(async () => {
// Ensure that we're activating the correct Ruby version on CI
if (process.env.CI) {
await createSymlinksForCi();
}
});

const workspacePath = path.dirname(
path.dirname(path.dirname(path.dirname(__dirname))),
);
const workspaceUri = vscode.Uri.file(workspacePath);
const workspaceFolder: vscode.WorkspaceFolder = {
uri: workspaceUri,
name: path.basename(workspaceUri.fsPath),
index: 0,
};

const context = {
extensionMode: vscode.ExtensionMode.Test,
subscriptions: [],
workspaceState: {
get: (_name: string) => undefined,
update: (_name: string, _value: any) => Promise.resolve(),
},
} as unknown as vscode.ExtensionContext;
const fakeLogger = new FakeLogger();
const outputChannel = new WorkspaceChannel("fake", fakeLogger as any);

async function createClient() {
const ruby = new Ruby(
context,
workspaceFolder,
outputChannel,
FAKE_TELEMETRY,
);
await ruby.activateRuby();

const client = new Client(
context,
FAKE_TELEMETRY,
ruby,
() => {},
workspaceFolder,
outputChannel,
new Map<string, string>(),
);

client.clientOptions.initializationFailedHandler = (error) => {
assert.fail(
`Failed to start server ${error.message}\n${fakeLogger.receivedMessages}`,
);
};
return client;
}

test("with launcher mode enabled", async () => {
const featureStub = sinon.stub(common, "featureEnabled").returns(true);
const client = await createClient();
featureStub.restore();

try {
await client.start();
} catch (error: any) {
assert.fail(`Failed to start server ${error.message}`);
}

assert.strictEqual(client.state, State.Running);

try {
await client.stop();
await client.dispose();
} catch (error: any) {
assert.fail(`Failed to stop server: ${error.message}`);
}
}).timeout(60000);
});
2 changes: 1 addition & 1 deletion vscode/src/test/suite/ruby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LOG_CHANNEL } from "../../common";
import * as common from "../../common";
import { ACTIVATION_SEPARATOR } from "../../ruby/versionManager";

import { FAKE_TELEMETRY } from "./fakeTelemetry";
import { FAKE_TELEMETRY } from "./testHelpers";

suite("Ruby environment activation", () => {
const workspacePath = path.dirname(
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/test/suite/testController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CodeLens } from "vscode-languageclient/node";
import { TestController } from "../../testController";
import { Command } from "../../common";

import { FAKE_TELEMETRY } from "./fakeTelemetry";
import { FAKE_TELEMETRY } from "./testHelpers";

suite("TestController", () => {
const context = {
Expand Down
129 changes: 129 additions & 0 deletions vscode/src/test/suite/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import os from "os";
import path from "path";
import fs from "fs";

import * as vscode from "vscode";

import { MAJOR, MINOR, RUBY_VERSION } from "../rubyVersion";
import { ManagerIdentifier } from "../../ruby";

class FakeSender implements vscode.TelemetrySender {
public receivedEvents: any[];
public receivedErrors: any[];

constructor() {
this.receivedEvents = [];
this.receivedErrors = [];
}

sendEventData(
eventName: string,
data?: Record<string, any> | undefined,
): void {
this.receivedEvents.push({ eventName, data });
}

sendErrorData(error: Error, data?: Record<string, any> | undefined): void {
this.receivedErrors.push({ error, data });
}
}

export const FAKE_TELEMETRY = vscode.env.createTelemetryLogger(
new FakeSender(),
{
ignoreUnhandledErrors: true,
},
);

export class FakeLogger {
receivedMessages = "";

trace(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

debug(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

info(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

warn(message: string, ..._args: any[]): void {
this.receivedMessages += message;
}

error(error: string | Error, ..._args: any[]): void {
this.receivedMessages += error.toString();
}

append(value: string): void {
this.receivedMessages += value;
}

appendLine(value: string): void {
this.receivedMessages += value;
}
}

export async function createSymlinksForCi() {
if (os.platform() === "linux") {
await vscode.workspace
.getConfiguration("rubyLsp")
.update(
"rubyVersionManager",
{ identifier: ManagerIdentifier.Chruby },
true,
);

const linkPath = path.join(os.homedir(), ".rubies", RUBY_VERSION);

if (!fs.existsSync(linkPath)) {
fs.mkdirSync(path.join(os.homedir(), ".rubies"), { recursive: true });
fs.symlinkSync(`/opt/hostedtoolcache/Ruby/${RUBY_VERSION}/x64`, linkPath);
}
} else if (os.platform() === "darwin") {
await vscode.workspace
.getConfiguration("rubyLsp")
.update(
"rubyVersionManager",
{ identifier: ManagerIdentifier.Chruby },
true,
);

const linkPath = path.join(os.homedir(), ".rubies", RUBY_VERSION);

if (!fs.existsSync(linkPath)) {
fs.mkdirSync(path.join(os.homedir(), ".rubies"), { recursive: true });
fs.symlinkSync(
`/Users/runner/hostedtoolcache/Ruby/${RUBY_VERSION}/arm64`,
linkPath,
);
}
} else {
await vscode.workspace
.getConfiguration("rubyLsp")
.update(
"rubyVersionManager",
{ identifier: ManagerIdentifier.RubyInstaller },
true,
);

const linkPath = path.join("C:", `Ruby${MAJOR}${MINOR}-${os.arch()}`);

if (!fs.existsSync(linkPath)) {
fs.symlinkSync(
path.join(
"C:",
"hostedtoolcache",
"windows",
"Ruby",
RUBY_VERSION,
"x64",
),
linkPath,
);
}
}
}
Loading

0 comments on commit 2824afe

Please sign in to comment.