Skip to content

Commit d9e03ed

Browse files
fhammerschmidtcristianoc
authored andcommitted
Fix getBinaryDirPath for workspaces/monorepos
1 parent 98e3e94 commit d9e03ed

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

server/src/server.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ let send: (msg: p.Message) => void = (_) => {};
6767

6868
let getBinaryDirPath = (projectRootPath: p.DocumentUri) =>
6969
extensionConfiguration.binaryPath === null
70-
? path.join(projectRootPath, c.nodeModulesBinDir)
70+
? utils.findBinaryFromProjectRoot(projectRootPath)
7171
: extensionConfiguration.binaryPath;
7272

7373
let findRescriptBinary = (projectRootPath: p.DocumentUri) =>
@@ -618,7 +618,8 @@ function format(msg: p.RequestMessage): Array<p.Message> {
618618
// code will always be defined here, even though technically it can be undefined
619619
let code = getOpenedFileContent(params.textDocument.uri);
620620
let projectRootPath = utils.findProjectRootOfFile(filePath);
621-
let bscBinaryPath = projectRootPath === null ? null : findBscBinary(projectRootPath);
621+
let bscBinaryPath =
622+
projectRootPath === null ? null : findBscBinary(projectRootPath);
622623
let formattedResult = utils.formatCode(bscBinaryPath, filePath, code);
623624
if (formattedResult.kind === "success") {
624625
let max = code.length;

server/src/utils.ts

+16
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ export let findProjectRootOfFile = (
3838
}
3939
};
4040

41+
export let findBinaryFromProjectRoot = (
42+
source: p.DocumentUri
43+
): null | p.DocumentUri => {
44+
let dir = path.dirname(source);
45+
let bscNativeReScriptPath = path.join(dir, c.nodeModulesBinDir);
46+
47+
if (fs.existsSync(bscNativeReScriptPath)) {
48+
return bscNativeReScriptPath;
49+
} else if (dir === source) {
50+
// reached the top
51+
return null;
52+
} else {
53+
return findBinaryFromProjectRoot(dir);
54+
}
55+
};
56+
4157
export let findBinary = (
4258
binaryDirPath: p.DocumentUri | null,
4359
binaryName: string

0 commit comments

Comments
 (0)