Skip to content

Commit 726ebeb

Browse files
committed
better packaging, dont ship the binary
1 parent 56a2849 commit 726ebeb

File tree

8 files changed

+90
-107
lines changed

8 files changed

+90
-107
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"git.ignoreLimitWarning": true,
66
"git.enabled": false,
77
"reason.path.bsb": "./node_modules/.bin/bsb",
8-
"editor.codeLens": true
8+
"editor.codeLens": true,
9+
"reason_language_server.location": "./lib/bs/native/bin.native",
10+
"reason_language_server.reloadOnChange": true
911
}

client/package-lock.json

Lines changed: 1 addition & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,14 @@
3030
"type": "object",
3131
"title": "Reason Language Server",
3232
"properties": {
33-
"reason_language_server.maxNumberOfProblems": {
34-
"scope": "resource",
35-
"type": "number",
36-
"default": 100,
37-
"description": "Controls the maximum number of problems produced by the server."
38-
},
39-
"reason_language_server.trace.server": {
40-
"scope": "window",
33+
"reason_language_server.location": {
4134
"type": "string",
42-
"enum": [
43-
"off",
44-
"messages",
45-
"verbose"
46-
],
47-
"default": "off",
48-
"description": "Traces the communication between VSCode and the language server."
35+
"description": "Provide a custom location for the language server binary"
36+
},
37+
"reason_language_server.reloadOnChange": {
38+
"type": "boolean",
39+
"default": false,
40+
"description": "Monitor the language server binary for updates, and restart it (for development)."
4941
}
5042
}
5143
},
@@ -75,7 +67,6 @@
7567
},
7668
"dependencies": {
7769
"vscode": "^1.1.17",
78-
"vscode-languageclient": "^4.1.3",
79-
"@jaredly/reason-language-server": "file:../"
70+
"vscode-languageclient": "^4.1.3"
8071
}
8172
}

client/src/index.js

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,38 @@ const vscode = require("vscode");
77
const {LanguageClient} = require("vscode-languageclient");
88
const path = require('path')
99
const fs = require('fs')
10-
const DEV = true;
10+
// const DEV = false;
11+
12+
const getLocation = () => {
13+
let config = vscode.workspace.getConfiguration('reason_language_server')
14+
15+
let binaryLocation = config.get('location')
16+
17+
if (!binaryLocation) {
18+
binaryLocation = path.join(vscode.workspace.rootPath, 'node_modules', '@jaredly', 'reason-language-server', 'lib', 'bs', 'native', 'bin.native')
19+
// binaryLocation = path.join(vscode.workspace.rootPath, '..', 'lib', 'bs', 'native', 'bin.native')
20+
} else {
21+
if (!binaryLocation.startsWith('/')) {
22+
binaryLocation = path.join(vscode.workspace.rootPath, binaryLocation)
23+
}
24+
}
25+
return binaryLocation
26+
}
27+
28+
const newClient = (clientOptions, location) => {
29+
return new LanguageClient(
30+
'reason-language-server',
31+
'Reason Language Server',
32+
serverOptions,
33+
clientOptions
34+
)
35+
}
36+
37+
const shouldReload = () => vscode.workspace.getConfiguration('reason_language_server').get('reloadOnChange')
1138

1239
function activate(context) {
1340
// The server is implemented in reason
14-
let binaryLocation = DEV
15-
? context.asAbsolutePath(path.join('..', 'lib', 'bs', 'native', 'bin.native'))
16-
: context.asAbsolutePath(path.join('node_modules', '@jaredly', 'reason-language-server', 'lib', 'bs', 'native', 'bin.native'));
1741

18-
let serverOptions = {
19-
command: binaryLocation,
20-
args: [],
21-
};
2242
let clientOptions = {
2343
documentSelector: [{scheme: 'file', language: 'reason'}],
2444
synchronize: {
@@ -28,35 +48,16 @@ function activate(context) {
2848
fileEvents: vscode.workspace.createFileSystemWatcher('**/bsconfig.json')
2949
}
3050
};
31-
let client = new LanguageClient(
32-
'reason-language-server',
33-
'Reason Language Server',
34-
serverOptions,
35-
clientOptions
36-
)
37-
// Push the disposable to the context's subscriptions so that the
38-
// client can be deactivated on extension deactivation
39-
context.subscriptions.push(client.start());
4051

41-
let lastStartTime = Date.now();
42-
const restart = () => {
43-
client.stop();
44-
client = new LanguageClient(
45-
'reason-language-server',
46-
'Reason Language Server',
47-
serverOptions,
48-
clientOptions
49-
);
50-
lastStartTime = Date.now()
51-
context.subscriptions.push(client.start());
52-
vscode.window.showInformationMessage('Reason language server restarted');
53-
}
52+
let client = null
53+
let lastStartTime = null
54+
let interval = null
5455

55-
if (DEV) {
56+
const startChecking = (location) => {
5657
vscode.window.showInformationMessage('DEBUG MODE: Will auto-restart the reason language server if it recompiles');
57-
const checkForBinaryChagne = setInterval(() => {
58+
interval = setInterval(() => {
5859
try {
59-
const stat = fs.statSync(binaryLocation)
60+
const stat = fs.statSync(location)
6061
const mtime = stat.mtime.getTime()
6162
if (mtime > lastStartTime) {
6263
restart()
@@ -68,6 +69,36 @@ function activate(context) {
6869
context.subscriptions.push({dispose: () => clearInterval(checkForBinaryChange)})
6970
}
7071

72+
const restart = () => {
73+
if (client) {
74+
client.stop();
75+
}
76+
const location = getLocation()
77+
client = new LanguageClient(
78+
'reason-language-server',
79+
'Reason Language Server',
80+
{
81+
command: location,
82+
args: [],
83+
},
84+
clientOptions
85+
);
86+
lastStartTime = Date.now()
87+
context.subscriptions.push(client.start());
88+
vscode.window.showInformationMessage('Reason language server restarted');
89+
if (shouldReload()) {
90+
if (!interval) {
91+
startChecking(location)
92+
}
93+
} else if (interval) {
94+
vscode.window.showInformationMessage('DEBUG MODE OFF - no longer monitoring reason-language-server binary');
95+
clearInterval(interval)
96+
interval = null
97+
}
98+
}
99+
100+
restart();
101+
71102
vscode.commands.registerCommand('reason-language-server.restart', restart);
72103
}
73104
exports.activate = activate;

example-project/.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"editor.codeLens": true
2+
"editor.codeLens": true,
3+
"reason_language_server.location": "../lib/bs/native/bin.native",
4+
"reason_language_server.reloadOnChange": false
35
}

example-project/src/Hello.re

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ string_of_bool; */
77
module Something = {
88
open Other;
99

10-
let m = {firstName: "Me", age: 0};
11-
let animal = Wolf(10);
12-
let other = Wolf(2);
10+
let m = {name: "Me", age: 0};
11+
let animal = Dogz(10);
12+
let other = Dogz(2);
1313
let me = Cat("Hie");
1414
let x = something + 10;
1515
};

example-project/src/Other.re

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
let something = 10;
77

8-
type person = {firstName: string, age: int};
8+
type person = {name: string, age: int};
99

10-
type animals = Wolf(int) | Cat(string) | Mouse;
10+
type animals = Dogz(int) | Cat(string) | Mouse;
1111

12-
let m = Wolf(1);
12+
let m = Dogz(1);
1313

14-
let z = {firstName: "hi", age: 20};
14+
let z = {name: "hi", age: 20};
1515

1616
/* let e = z.name; */

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"start": "bsb -make-world -backend native",
66
"clean": "bsb -clean-world",
77
"watch": "bsb -make-world -backend native -w",
8-
"package": "npm run package:cp && npm run package:remap && npm run package:bundle && npm run package:done",
9-
"package:cp": "rm -rf tmp; mkdir tmp; cp -r bsconfig.json package.json src omd odoc_parser bin lib tmp; mkdir tmp/node_modules; cp package.thin.json tmp/package.json",
10-
"package:remap": "sed -i .bak 's/file:\\.\\.\\//file:..\\/tmp/' client/package.json",
8+
"package": "npm run package:bundle",
9+
"// package:cp": "rm -rf tmp; mkdir tmp; cp -r bsconfig.json package.json src omd odoc_parser bin lib tmp; mkdir tmp/node_modules; cp package.thin.json tmp/package.json",
10+
"// package:remap": "sed -i .bak 's/file:\\.\\.\\//file:..\\/tmp/' client/package.json",
1111
"package:bundle": "cd client && npm i && vsce package",
12-
"package:done": "mv client/package.json.bak client/package.json && rm -rf tmp",
12+
"// package:done": "mv client/package.json.bak client/package.json && rm -rf tmp",
1313
"postinstall": "bsb -make-world -backend native"
1414
},
1515
"keywords": [

0 commit comments

Comments
 (0)