|
1 | 1 | import * as path from "path"; |
| 2 | +import * as fs from "fs"; |
2 | 3 | import { |
3 | 4 | workspace, |
4 | 5 | ExtensionContext, |
@@ -91,29 +92,26 @@ export function activate(context: ExtensionContext) { |
91 | 92 | "rescript", |
92 | 93 | ); |
93 | 94 |
|
94 | | - function createExperimentalLanguageClient() { |
95 | | - const binaryPathFromNodeModules = Uri.joinPath( |
96 | | - context.extensionUri, |
97 | | - "node_modules", |
98 | | - ".bin", |
99 | | - "rescript-language-server", |
100 | | - ).fsPath; |
| 95 | + const useExperimentalServer = workspace |
| 96 | + .getConfiguration("rescript") |
| 97 | + .get<string | null>("experimentalServerPath", null); |
101 | 98 |
|
102 | | - const userServerPath = workspace |
103 | | - .getConfiguration("rescript") |
104 | | - .get<string | null>("experimentalServerPath", null); |
105 | | - |
106 | | - const binaryPath = userServerPath |
107 | | - ? userServerPath |
108 | | - : binaryPathFromNodeModules; |
| 99 | + function createExperimentalLanguageClient(serverPath: string) { |
| 100 | + if (!fs.existsSync(serverPath)) { |
| 101 | + const message = `The experimental server is enabled with \`experimentalServerPath\`, but no language server was found at ${serverPath}. See the instructions for using the experimental server in [ADD_LINK_TO_DOCS_HERE].`; |
| 102 | + outputChannel.appendLine(message); |
| 103 | + window.showErrorMessage(message); |
| 104 | + outputChannel.show(); |
| 105 | + throw new Error(message); |
| 106 | + } |
109 | 107 |
|
110 | 108 | let serverOptions: ServerOptions = { |
111 | 109 | run: { |
112 | | - command: binaryPath, |
| 110 | + command: serverPath, |
113 | 111 | transport: TransportKind.stdio, |
114 | 112 | }, |
115 | 113 | debug: { |
116 | | - command: binaryPath, |
| 114 | + command: serverPath, |
117 | 115 | transport: TransportKind.stdio, |
118 | 116 | }, |
119 | 117 | }; |
@@ -194,12 +192,8 @@ export function activate(context: ExtensionContext) { |
194 | 192 | } |
195 | 193 |
|
196 | 194 | function createClient() { |
197 | | - const useExperimentalServer = workspace |
198 | | - .getConfiguration("rescript") |
199 | | - .get<boolean>("useExperimentalServer", false); |
200 | | - |
201 | | - return useExperimentalServer |
202 | | - ? createExperimentalLanguageClient() |
| 195 | + return useExperimentalServer != null |
| 196 | + ? createExperimentalLanguageClient(useExperimentalServer) |
203 | 197 | : createLanguageClient(); |
204 | 198 | } |
205 | 199 |
|
|
0 commit comments