|
1 | 1 | import path from "path"; |
| 2 | +import fs from "fs"; |
2 | 3 | import os from "os"; |
3 | 4 | import { performance as Perf } from "perf_hooks"; |
4 | 5 |
|
@@ -85,6 +86,7 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS. |
85 | 86 | const customBundleGemfile: string = config.get("bundleGemfile")!; |
86 | 87 | const useBundlerCompose: boolean = config.get("useBundlerCompose")!; |
87 | 88 | const bypassTypechecker: boolean = config.get("bypassTypechecker")!; |
| 89 | + const serverPath: string = config.get("serverPath")!; |
88 | 90 |
|
89 | 91 | const executableOptions: ExecutableOptions = { |
90 | 92 | cwd: workspaceFolder.uri.fsPath, |
@@ -119,13 +121,40 @@ function getLspExecutables(workspaceFolder: vscode.WorkspaceFolder, env: NodeJS. |
119 | 121 | options: executableOptions, |
120 | 122 | }; |
121 | 123 | } else { |
| 124 | + const args = []; |
122 | 125 | const workspacePath = workspaceFolder.uri.fsPath; |
123 | | - const command = |
124 | | - path.basename(workspacePath) === "ruby-lsp" && os.platform() !== "win32" |
125 | | - ? path.join(workspacePath, "exe", "ruby-lsp") |
126 | | - : "ruby-lsp"; |
| 126 | + let command: string; |
127 | 127 |
|
128 | | - const args = []; |
| 128 | + if (serverPath.length > 0 && branch.length > 0) { |
| 129 | + throw new Error( |
| 130 | + 'Invalid configuration: "rubyLsp.serverPath" and "rubyLsp.branch" cannot both be set. Please unset one of them.', |
| 131 | + ); |
| 132 | + } |
| 133 | + |
| 134 | + if (serverPath.length > 0) { |
| 135 | + const absoluteServerPath = path.isAbsolute(serverPath) ? serverPath : path.resolve(workspacePath, serverPath); |
| 136 | + const exists = fs.existsSync(absoluteServerPath); |
| 137 | + |
| 138 | + if (exists) { |
| 139 | + args.push("--path", absoluteServerPath); |
| 140 | + const stat = fs.statSync(absoluteServerPath); |
| 141 | + |
| 142 | + if (stat.isDirectory()) { |
| 143 | + command = os.platform() !== "win32" ? path.join(absoluteServerPath, "exe", "ruby-lsp") : "ruby-lsp"; |
| 144 | + } else { |
| 145 | + command = absoluteServerPath; |
| 146 | + } |
| 147 | + } else { |
| 148 | + throw new Error( |
| 149 | + `The configured rubyLsp.serverPath "${serverPath}" does not exist at "${absoluteServerPath}". `, |
| 150 | + ); |
| 151 | + } |
| 152 | + } else { |
| 153 | + command = |
| 154 | + path.basename(workspacePath) === "ruby-lsp" && os.platform() !== "win32" |
| 155 | + ? path.join(workspacePath, "exe", "ruby-lsp") |
| 156 | + : "ruby-lsp"; |
| 157 | + } |
129 | 158 |
|
130 | 159 | if (branch.length > 0) { |
131 | 160 | args.push("--branch", branch); |
|
0 commit comments