Skip to content

Fix Language Server and Tools --version command #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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

#### :nail_care: Polish

Expand Down
6 changes: 2 additions & 4 deletions server/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node
import fs from "fs";
import server from "./server";

const server = require("./server")
const args = process.argv.slice(2)

const help = `ReScript Language Server
Expand All @@ -23,7 +21,7 @@ Options:
return server(false);
case '--version':
case '-v':
console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version);
console.log(require('../package.json').version);
process.exit(0);
case '--help':
case '-h':
Expand Down
1 change: 1 addition & 0 deletions tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
#### :bug: Bug Fix

- Fix tagged variant for `Module` and add attr to interface files. https://github.com/rescript-lang/rescript-vscode/pull/866
- Fix `rescript-tools --version` command. https://github.com/rescript-lang/rescript-vscode/pull/853
- 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
6 changes: 3 additions & 3 deletions tools/src/Cli.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@@directive("#!/usr/bin/env node")

@module("fs") external readFileSync: string => string = "readFileSync"
@val external require: string => Js.Dict.t<string> = "require"
@variadic @module("path") external join: array<string> => string = "join"
@module("path") external dirname: string => string = "dirname"
@val external __dirname: string = "__dirname"
Expand Down Expand Up @@ -89,9 +89,9 @@ switch args->Belt.List.fromArray {
}
| list{"-h" | "--help"} => logAndExit(~log=help, ~code=0)
| list{"-v" | "--version"} =>
switch readFileSync("./package.json")->Js.Json.parseExn->Js.Json.decodeObject {
switch require("../package.json")->Js.Dict.get("version") {
| None => logAndExit(~log="error: failed to find version in package.json", ~code=1)
| Some(dict) => logAndExit(~log=dict->Js.Dict.unsafeGet("version"), ~code=0)
| Some(version) => logAndExit(~log=version, ~code=0)
}
| _ => logAndExit(~log=help, ~code=1)
}