Skip to content

Commit ac37dd7

Browse files
committed
better error messages
1 parent 834726e commit ac37dd7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

client/src/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,28 @@ const path = require('path')
99
const fs = require('fs')
1010

1111
const getLocation = (context) => {
12-
let config = vscode.workspace.getConfiguration('reason_language_server')
13-
14-
let binaryLocation = config.get('location')
12+
let binaryLocation = vscode.workspace.getConfiguration('reason_language_server').get('location')
1513

1614
if (!binaryLocation) {
1715
// see if it's bundled with the extension
1816
// hmm actually I could bundle one for each platform & probably be fine
1917
// I guess it's 9mb binary. I wonder if I can cut that down?
20-
binaryLocation = context.asAbsolutePath('../bin.native')
18+
binaryLocation = path.join(vscode.workspace.rootPath, 'node_modules', '@jaredly', 'reason-language-server', 'lib', 'bs', 'native', 'bin.native')
2119
if (!fs.existsSync(binaryLocation)) {
22-
binaryLocation = path.join(vscode.workspace.rootPath, 'node_modules', '@jaredly', 'reason-language-server', 'lib', 'bs', 'native', 'bin.native')
20+
binaryLocation = context.asAbsolutePath('../bin.native')
21+
if (!fs.existsSync(binaryLocation)) {
22+
vscode.window.showErrorMessage('Reason Language Server not found! Please install the npm package @jaredly/reason-language-server to enable IDE functionality');
23+
return null
24+
}
2325
}
2426
} else {
2527
if (!binaryLocation.startsWith('/')) {
2628
binaryLocation = path.join(vscode.workspace.rootPath, binaryLocation)
2729
}
30+
if (!fs.existsSync(binaryLocation)) {
31+
vscode.window.showErrorMessage('Reason Language Server not found! You specified ' + binaryLocation);
32+
return null
33+
}
2834
}
2935
return binaryLocation
3036
}
@@ -87,6 +93,7 @@ function activate(context) {
8793
client.stop();
8894
}
8995
const location = getLocation()
96+
if (!location) return
9097
client = new LanguageClient(
9198
'reason-language-server',
9299
'Reason Language Server',
@@ -110,6 +117,12 @@ function activate(context) {
110117
}
111118
}
112119

120+
vscode.workspace.onDidChangeConfiguration(evt => {
121+
if (evt.affectsConfiguration('reason_language_server.location')) {
122+
restart()
123+
}
124+
})
125+
113126
restart();
114127

115128
vscode.commands.registerCommand('reason-language-server.restart', restart);

0 commit comments

Comments
 (0)