Skip to content

Commit e54c067

Browse files
authoredDec 18, 2023
Fix Language Server and Tools --version command (#853)
* fix(lsp): cli version * update CHANGELOG.md * fix cli tools --version * update CHANGELOG.md * move to commonjs * update CHANGELOG.md
1 parent 3817c6c commit e54c067

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
- Proper default for `"uncurried"` in V11 projects. https://github.com/rescript-lang/rescript-vscode/pull/867
2222
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
23+
- Fix `rescript-language-server --version` command. https://github.com/rescript-lang/rescript-vscode/pull/853
2324

2425
#### :nail_care: Polish
2526

‎server/src/cli.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env node
2-
import fs from "fs";
3-
import server from "./server";
4-
2+
const server = require("./server")
53
const args = process.argv.slice(2)
64

75
const help = `ReScript Language Server
@@ -23,7 +21,7 @@ Options:
2321
return server(false);
2422
case '--version':
2523
case '-v':
26-
console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version);
24+
console.log(require('../package.json').version);
2725
process.exit(0);
2826
case '--help':
2927
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/853
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@@directive("#!/usr/bin/env node")
22

3-
@module("fs") external readFileSync: string => string = "readFileSync"
3+
@val external require: string => Js.Dict.t<string> = "require"
44
@variadic @module("path") external join: array<string> => string = "join"
55
@module("path") external dirname: string => string = "dirname"
66
@val external __dirname: string = "__dirname"
@@ -89,9 +89,9 @@ switch args->Belt.List.fromArray {
8989
}
9090
| list{"-h" | "--help"} => logAndExit(~log=help, ~code=0)
9191
| list{"-v" | "--version"} =>
92-
switch readFileSync("./package.json")->Js.Json.parseExn->Js.Json.decodeObject {
92+
switch require("../package.json")->Js.Dict.get("version") {
9393
| 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)
94+
| Some(version) => logAndExit(~log=version, ~code=0)
9595
}
9696
| _ => logAndExit(~log=help, ~code=1)
9797
}

0 commit comments

Comments
 (0)
Please sign in to comment.