Skip to content

Fix Language Server and Tools --version command #873

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 3 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 @@ -22,6 +22,7 @@
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
- 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
- Fix crash when trying to print recursive polymorphic variants without a concrete definition. https://github.com/rescript-lang/rescript-vscode/pull/851
- Fix `rescript-language-server --version` command. https://github.com/rescript-lang/rescript-vscode/pull/873

#### :nail_care: Polish

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

const args = process.argv.slice(2)
Expand All @@ -23,7 +24,8 @@ Options:
return server(false);
case '--version':
case '-v':
console.log(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' })).version);
const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json")).toString())
console.log(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/873
- 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
21 changes: 8 additions & 13 deletions tools/src/Cli.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@
@module("path") external dirname: string => string = "dirname"
@val external __dirname: string = "__dirname"

module Buffer = {
type t

@send external toString: t => string = "toString"
}

type processEnvOptions = {stdio?: string}
type spawnSyncResult = {
stdout: Buffer.t,
stderr: Buffer.t,
status: Js.Null.t<int>,
}
type spawnSyncResult = {status: Js.Null.t<int>}

@module("child_process")
external spawnSync: (string, array<string>, option<processEnvOptions>) => spawnSyncResult =
Expand Down Expand Up @@ -89,9 +79,14 @@ 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 {
let packageJson = join([__dirname, "..", "package.json"])
switch readFileSync(packageJson)->Js.Json.parseExn->Js.Json.decodeObject {
| 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(dict) =>
switch dict->Js.Dict.get("version") {
| Some(version) => logAndExit(~log=version, ~code=0)
| None => logAndExit(~log="error: failed to find version in package.json", ~code=1)
}
}
| _ => logAndExit(~log=help, ~code=1)
}