Skip to content

Commit f57d9cb

Browse files
author
Bart Schuurmans
committed
Rewrite algorithm to find bsc.exe based on platformPath
Should fix formatting in monorepos. Fixes #572
1 parent 07bc57e commit f57d9cb

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

server/src/server.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,28 @@ let findRescriptBinary = (projectRootPath: p.DocumentUri | null) =>
9090
? utils.findFilePathFromProjectRoot(projectRootPath, path.join(c.nodeModulesBinDir, c.rescriptBinName))
9191
: utils.findBinary(extensionConfiguration.binaryPath, c.rescriptBinName);
9292

93-
let findBscBinary = (projectRootPath: p.DocumentUri) => {
94-
let rescriptBinaryPath = findRescriptBinary(projectRootPath);
95-
if (rescriptBinaryPath !== null) {
96-
let rescriptDirPath = path.join(
97-
path.dirname(rescriptBinaryPath),
98-
"..",
99-
"rescript"
100-
);
101-
102-
let bscBinaryPath = path.join(rescriptDirPath, c.platformDir, c.bscExeName);
93+
let findPlatformPath = (projectRootPath: p.DocumentUri | null) => {
94+
if (extensionConfiguration.platformPath != null) {
95+
return extensionConfiguration.platformPath;
96+
}
10397

104-
// Workaround for darwinarm64 which has no folder yet in ReScript <= 9.1.4
105-
if (
106-
process.platform == "darwin" &&
107-
process.arch == "arm64" &&
108-
!fs.existsSync(bscBinaryPath)
109-
) {
110-
bscBinaryPath = path.join(
111-
rescriptDirPath,
112-
process.platform,
113-
c.bscExeName
114-
);
115-
}
98+
let rescriptDir = utils.findFilePathFromProjectRoot(projectRootPath, path.join("node_modules", "rescript"));
99+
let platformPath = path.join(rescriptDir, c.platformDir)
116100

117-
return bscBinaryPath;
101+
// Workaround for darwinarm64 which has no folder yet in ReScript <= 9.1.4
102+
if (
103+
process.platform == "darwin" &&
104+
process.arch == "arm64" &&
105+
!fs.existsSync(platformPath)
106+
) {
107+
platformPath = path.join(rescriptDir, process.platform);
118108
}
119-
return null;
120-
};
109+
110+
return platformPath;
111+
}
112+
113+
let findBscExeBinary = (projectRootPath: p.DocumentUri | null) =>
114+
utils.findBinary(findPlatformPath(projectRootPath), c.bscExeName)
121115

122116
interface CreateInterfaceRequestParams {
123117
uri: string;
@@ -718,12 +712,12 @@ function format(msg: p.RequestMessage): Array<p.Message> {
718712
} else {
719713
// code will always be defined here, even though technically it can be undefined
720714
let code = getOpenedFileContent(params.textDocument.uri);
715+
721716
let projectRootPath = utils.findProjectRootOfFile(filePath);
722-
let bscBinaryPath =
723-
projectRootPath === null ? null : findBscBinary(projectRootPath);
717+
let bscExeBinaryPath = findBscExeBinary(projectRootPath);
724718

725719
let formattedResult = utils.formatCode(
726-
bscBinaryPath,
720+
bscExeBinaryPath,
727721
filePath,
728722
code,
729723
extensionConfiguration.allowBuiltInFormatter

0 commit comments

Comments
 (0)