Skip to content

Work with the newest rescript package #106

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 1 commit into from
Apr 17, 2021
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
6 changes: 6 additions & 0 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export let bscExePartialPath = path.join(
process.platform,
"bsc.exe"
);
export let bscExeReScriptPartialPath = path.join(
"node_modules",
"rescript",
process.platform,
"bsc.exe"
);

// can't use the native bsb since we might need the watcher -w flag, which is only in the js wrapper
// export let bsbPartialPath = path.join('node_modules', 'bs-platform', process.platform, 'bsb.exe');
Expand Down
6 changes: 4 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ function onMessage(msg: m.Message) {
if (bscExeDir === null) {
let params: p.ShowMessageParams = {
type: p.MessageType.Error,
message: `Cannot find a nearby ${c.bscExePartialPath}. It's needed for formatting.`,
message: `Cannot find a nearby bsc.exe in bs-platform or rescript. It's needed for formatting.`,
};
let response: m.NotificationMessage = {
jsonrpc: c.jsonrpcVersion,
Expand All @@ -438,7 +438,9 @@ function onMessage(msg: m.Message) {
send(fakeSuccessResponse);
send(response);
} else {
let resolvedBscExePath = path.join(bscExeDir, c.bscExePartialPath);
let bscExePath1 = path.join(bscExeDir, c.bscExeReScriptPartialPath);
let bscExePath2 = path.join(bscExeDir, c.bscExePartialPath);
let resolvedBscExePath = fs.existsSync(bscExePath1) ? bscExePath1 : bscExePath2;
// code will always be defined here, even though technically it can be undefined
let code = getOpenedFileContent(params.textDocument.uri);
let formattedResult = utils.formatUsingValidBscExePath(
Expand Down
5 changes: 3 additions & 2 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export let findBscExeDirOfFile = (
source: p.DocumentUri
): null | p.DocumentUri => {
let dir = path.dirname(source);
let bscPath = path.join(dir, c.bscExePartialPath);
if (fs.existsSync(bscPath)) {
let bscExePath1 = path.join(dir, c.bscExeReScriptPartialPath);
let bscExePath2 = path.join(dir, c.bscExePartialPath);
if (fs.existsSync(bscExePath1) || fs.existsSync(bscExePath2)) {
return dir;
} else {
if (dir === source) {
Expand Down