Skip to content

Commit 6828f96

Browse files
committed
The binaryPath setting is using to find resctipt binary
1 parent 8108098 commit 6828f96

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

server/src/constants.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ export let analysisProdPath = path.join(
3232
"rescript-editor-analysis.exe"
3333
);
3434

35+
export let rescriptBinName = "rescript";
36+
37+
export let bsbBinName = "bsb";
38+
3539
export let bscBinName = "bsc";
3640

3741
// can't use the native bsb/rescript since we might need the watcher -w flag, which is only in the JS wrapper
3842
export let rescriptNodePartialPath = path.join(
3943
"node_modules",
4044
".bin",
41-
"rescript"
45+
rescriptBinName,
4246
);
43-
export let bsbNodePartialPath = path.join("node_modules", ".bin", "bsb");
47+
export let bsbNodePartialPath = path.join("node_modules", ".bin", bsbBinName);
4448

4549
export let bsbLock = ".bsb.lock";
4650
export let bsconfigPartialPath = "bsconfig.json";

server/src/server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ let codeActionsFromDiagnostics: codeActions.filesCodeActions = {};
6565
// will be properly defined later depending on the mode (stdio/node-rpc)
6666
let send: (msg: p.Message) => void = (_) => {};
6767

68+
let findBinary = (projectRootPath: p.DocumentUri) =>
69+
extensionConfiguration.binaryPath === null
70+
? utils.findNodeBuildOfProjectRoot(projectRootPath)
71+
: utils.findBinaryFromConfig(extensionConfiguration.binaryPath);
72+
6873
interface CreateInterfaceRequestParams {
6974
uri: string;
7075
}
@@ -235,7 +240,7 @@ let openedFile = (fileUri: string, fileContent: string) => {
235240
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
236241
// stale. Use that logic
237242
// TODO: close watcher when lang-server shuts down
238-
if (utils.findNodeBuildOfProjectRoot(projectRootPath) != null) {
243+
if (findBinary(projectRootPath) != null) {
239244
let payload: clientSentBuildAction = {
240245
title: c.startBuildAction,
241246
projectRootPath: projectRootPath,
@@ -1059,7 +1064,7 @@ function onMessage(msg: p.Message) {
10591064
// TODO: close watcher when lang-server shuts down. However, by Node's
10601065
// default, these subprocesses are automatically killed when this
10611066
// language-server process exits
1062-
let found = utils.findNodeBuildOfProjectRoot(projectRootPath);
1067+
let found = findBinary(projectRootPath);
10631068
if (found != null) {
10641069
let bsbProcess = utils.runBuildWatcherUsingValidBuildPath(
10651070
found.buildPath,

server/src/utils.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,33 @@ let findBscBinFromConfig = (
8484
};
8585

8686
// TODO: this doesn't handle file:/// scheme
87-
export let findNodeBuildOfProjectRoot = (
88-
projectRootPath: p.DocumentUri
89-
): null | { buildPath: p.DocumentUri; isReScript: boolean } => {
90-
let rescriptNodePath = path.join(projectRootPath, c.rescriptNodePartialPath);
91-
let bsbNodePath = path.join(projectRootPath, c.bsbNodePartialPath);
92-
93-
if (fs.existsSync(rescriptNodePath)) {
94-
return { buildPath: rescriptNodePath, isReScript: true };
95-
} else if (fs.existsSync(bsbNodePath)) {
96-
return { buildPath: bsbNodePath, isReScript: false };
87+
let findBinaryBase = ({
88+
rescriptPath,
89+
bsbPath,
90+
}: {
91+
rescriptPath: p.DocumentUri;
92+
bsbPath: p.DocumentUri;
93+
}): null | { buildPath: p.DocumentUri; isReScript: boolean } => {
94+
if (fs.existsSync(rescriptPath)) {
95+
return { buildPath: rescriptPath, isReScript: true };
96+
} else if (fs.existsSync(bsbPath)) {
97+
return { buildPath: bsbPath, isReScript: false };
9798
}
9899
return null;
99100
};
100101

102+
export let findBinaryFromConfig = (pathToBinFromConfig: p.DocumentUri) =>
103+
findBinaryBase({
104+
rescriptPath: path.join(pathToBinFromConfig, c.rescriptBinName),
105+
bsbPath: path.join(pathToBinFromConfig, c.bsbBinName),
106+
});
107+
108+
export let findNodeBuildOfProjectRoot = (projectRootPath: p.DocumentUri) =>
109+
findBinaryBase({
110+
rescriptPath: path.join(projectRootPath, c.rescriptNodePartialPath),
111+
bsbPath: path.join(projectRootPath, c.bsbNodePartialPath),
112+
});
113+
101114
type execResult =
102115
| {
103116
kind: "success";

0 commit comments

Comments
 (0)