-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix file paths for exec launcher on Windows
- Loading branch information
Showing
9 changed files
with
231 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.