Skip to content

Commit 3d7b23e

Browse files
authored
Fix Language Server and Tools --version command (#873)
* fix Language Server and Tools --version command * update CHANGELOG.md
1 parent de25a65 commit 3d7b23e

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
2323
- Fix infinite loop when resolving inferred completions when several values in scope has the same name. https://github.com/rescript-lang/rescript-vscode/pull/869
2424
- Fix crash when trying to print recursive polymorphic variants without a concrete definition. https://github.com/rescript-lang/rescript-vscode/pull/851
25+
- Fix `rescript-language-server --version` command. https://github.com/rescript-lang/rescript-vscode/pull/873
2526

2627
#### :nail_care: Polish
2728

server/src/cli.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
import fs from "fs";
3+
import path from "path";
34
import server from "./server";
45

56
const args = process.argv.slice(2)
@@ -23,7 +24,8 @@ Options:
2324
return server(false);
2425
case '--version':
2526
case '-v':
26-
console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version);
27+
const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json")).toString())
28+
console.log(version);
2729
process.exit(0);
2830
case '--help':
2931
case '-h':

tools/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
#### :bug: Bug Fix
2424

2525
- Fix tagged variant for `Module` and add attr to interface files. https://github.com/rescript-lang/rescript-vscode/pull/866
26+
- Fix `rescript-tools --version` command. https://github.com/rescript-lang/rescript-vscode/pull/873
2627
- Fix output truncate when run `rescript-tools doc path/to/file.res` in a separate process. https://github.com/rescript-lang/rescript-vscode/pull/868

tools/src/Cli.res

+8-13
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@
55
@module("path") external dirname: string => string = "dirname"
66
@val external __dirname: string = "__dirname"
77

8-
module Buffer = {
9-
type t
10-
11-
@send external toString: t => string = "toString"
12-
}
13-
148
type processEnvOptions = {stdio?: string}
15-
type spawnSyncResult = {
16-
stdout: Buffer.t,
17-
stderr: Buffer.t,
18-
status: Js.Null.t<int>,
19-
}
9+
type spawnSyncResult = {status: Js.Null.t<int>}
2010

2111
@module("child_process")
2212
external spawnSync: (string, array<string>, option<processEnvOptions>) => spawnSyncResult =
@@ -89,9 +79,14 @@ switch args->Belt.List.fromArray {
8979
}
9080
| list{"-h" | "--help"} => logAndExit(~log=help, ~code=0)
9181
| list{"-v" | "--version"} =>
92-
switch readFileSync("./package.json")->Js.Json.parseExn->Js.Json.decodeObject {
82+
let packageJson = join([__dirname, "..", "package.json"])
83+
switch readFileSync(packageJson)->Js.Json.parseExn->Js.Json.decodeObject {
9384
| None => logAndExit(~log="error: failed to find version in package.json", ~code=1)
94-
| Some(dict) => logAndExit(~log=dict->Js.Dict.unsafeGet("version"), ~code=0)
85+
| Some(dict) =>
86+
switch dict->Js.Dict.get("version") {
87+
| Some(version) => logAndExit(~log=version, ~code=0)
88+
| None => logAndExit(~log="error: failed to find version in package.json", ~code=1)
89+
}
9590
}
9691
| _ => logAndExit(~log=help, ~code=1)
9792
}

0 commit comments

Comments
 (0)