-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathhelpers.ts
More file actions
90 lines (73 loc) · 2.7 KB
/
helpers.ts
File metadata and controls
90 lines (73 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import path from "path";
import os from "os";
import fs from "fs";
import * as vscode from "vscode";
import { MAJOR, MINOR, RUBY_VERSION } from "../rubyVersion";
export function createRubySymlinks() {
if (os.platform() === "linux") {
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") {
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 {
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);
}
}
}
class FakeWorkspaceState implements vscode.Memento {
private store: Record<string, any> = {};
keys(): ReadonlyArray<string> {
return Object.keys(this.store);
}
get<T>(key: string): T | undefined {
return this.store[key];
}
update(key: string, value: any): Thenable<void> {
this.store[key] = value;
return Promise.resolve();
}
}
export const LSP_WORKSPACE_PATH = path.dirname(path.dirname(path.dirname(path.dirname(__dirname))));
export const LSP_WORKSPACE_URI = vscode.Uri.file(LSP_WORKSPACE_PATH);
export const LSP_WORKSPACE_FOLDER: vscode.WorkspaceFolder = {
uri: LSP_WORKSPACE_URI,
name: path.basename(LSP_WORKSPACE_PATH),
index: 0,
};
export type FakeContext = vscode.ExtensionContext & { dispose: () => void };
export function createContext() {
const subscriptions: vscode.Disposable[] = [];
return {
extensionMode: vscode.ExtensionMode.Test,
subscriptions,
workspaceState: new FakeWorkspaceState(),
extensionUri: vscode.Uri.joinPath(LSP_WORKSPACE_URI, "vscode"),
dispose: () => {
subscriptions.forEach((subscription) => subscription.dispose());
},
} as unknown as FakeContext;
}
// Retries the given assertion function until it passes or the timeout (in ms) is exceeded.
// Polls every 500ms. If the assertion never passes, the last assertion error is thrown.
export async function retryForDuration(timeoutMs: number, fn: () => void) {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
try {
fn();
return;
} catch (_error) {
await new Promise((resolve) => setTimeout(resolve, 500));
}
}
// Final attempt — let it throw
fn();
}