Skip to content

Commit cc7923e

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 cc7923e

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

server/src/server.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,32 @@ 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-
);
93+
let findPlatformPath = (projectRootPath: p.DocumentUri | null) => {
94+
if (extensionConfiguration.platformPath != null) {
95+
return extensionConfiguration.platformPath;
96+
}
10197

102-
let bscBinaryPath = path.join(rescriptDirPath, c.platformDir, c.bscExeName);
98+
let rescriptDir = utils.findFilePathFromProjectRoot(projectRootPath, path.join("node_modules", "rescript"));
99+
if (rescriptDir == null) {
100+
return null;
101+
}
103102

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-
}
103+
let platformPath = path.join(rescriptDir, c.platformDir)
116104

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

122120
interface CreateInterfaceRequestParams {
123121
uri: string;
@@ -718,12 +716,12 @@ function format(msg: p.RequestMessage): Array<p.Message> {
718716
} else {
719717
// code will always be defined here, even though technically it can be undefined
720718
let code = getOpenedFileContent(params.textDocument.uri);
719+
721720
let projectRootPath = utils.findProjectRootOfFile(filePath);
722-
let bscBinaryPath =
723-
projectRootPath === null ? null : findBscBinary(projectRootPath);
721+
let bscExeBinaryPath = findBscExeBinary(projectRootPath);
724722

725723
let formattedResult = utils.formatCode(
726-
bscBinaryPath,
724+
bscExeBinaryPath,
727725
filePath,
728726
code,
729727
extensionConfiguration.allowBuiltInFormatter

0 commit comments

Comments
 (0)