Skip to content

Commit a89b1e1

Browse files
fhammerschmidtcristianoc
authored andcommitted
Base bsc.exe lookup on rescript binary lookup
1 parent 472f691 commit a89b1e1

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

server/src/constants.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ let platformDir =
66
// See https://microsoft.github.io/language-server-protocol/specification Abstract Message
77
// version is fixed to 2.0
88
export let jsonrpcVersion = "2.0";
9-
export let platformPath = path.join("node_modules", "rescript", platformDir);
10-
export let bscNativeReScriptPartialPath = path.join(platformPath, "bsc.exe");
9+
export let platformPath = path.join("rescript", platformDir);
10+
export let nodeModulesPlatformPath = path.join("node_modules", platformPath);
11+
export let bscExeName = "bsc.exe";
12+
export let bscNativeReScriptPartialPath = path.join(
13+
nodeModulesPlatformPath,
14+
bscExeName
15+
);
1116

1217
export let analysisDevPath = path.join(
1318
path.dirname(__dirname),
@@ -25,7 +30,6 @@ export let analysisProdPath = path.join(
2530
export let rescriptBinName = "rescript";
2631

2732
export let bscBinName = "bsc";
28-
export let bscExeName = "bsc.exe";
2933

3034
export let nodeModulesBinDir = path.join("node_modules", ".bin");
3135

server/src/server.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ let codeActionsFromDiagnostics: codeActions.filesCodeActions = {};
7979
// will be properly defined later depending on the mode (stdio/node-rpc)
8080
let send: (msg: p.Message) => void = (_) => {};
8181

82-
let findBinaryFromProjectDirRec = (
83-
directory: p.DocumentUri, // This must be a directory and not a file!
84-
targetDir: p.DocumentUri,
85-
binaryName: p.DocumentUri
82+
let findBinaryPathFromProjectRoot = (
83+
directory: p.DocumentUri // This must be a directory and not a file!
8684
): null | p.DocumentUri => {
87-
let binaryDirPath = path.join(directory, targetDir);
88-
let binaryPath = path.join(binaryDirPath, binaryName);
85+
let binaryDirPath = path.join(directory, c.nodeModulesBinDir);
86+
let binaryPath = path.join(binaryDirPath, c.rescriptBinName);
8987

9088
if (fs.existsSync(binaryPath)) {
9189
return binaryPath;
@@ -97,22 +95,26 @@ let findBinaryFromProjectDirRec = (
9795
return null;
9896
}
9997

100-
return findBinaryFromProjectDirRec(parentDir, targetDir, binaryName);
98+
return findBinaryPathFromProjectRoot(parentDir);
10199
};
102100

103101
let findRescriptBinary = (projectRootPath: p.DocumentUri) =>
104102
extensionConfiguration.binaryPath == null
105-
? findBinaryFromProjectDirRec(
106-
projectRootPath,
107-
c.nodeModulesBinDir,
108-
c.rescriptBinName
109-
)
103+
? findBinaryPathFromProjectRoot(projectRootPath)
110104
: utils.findRescriptBinary(extensionConfiguration.binaryPath);
111105

112-
let findBscBinary = (projectRootPath: p.DocumentUri) =>
113-
extensionConfiguration.binaryPath == null
114-
? findBinaryFromProjectDirRec(projectRootPath, c.platformPath, c.bscExeName)
115-
: utils.findBscBinary(extensionConfiguration.binaryPath);
106+
let findBscBinary = (projectRootPath: p.DocumentUri) => {
107+
let rescriptBinaryPath = findRescriptBinary(projectRootPath);
108+
if (rescriptBinaryPath !== null) {
109+
return path.join(
110+
path.dirname(rescriptBinaryPath),
111+
"..",
112+
c.platformPath,
113+
c.bscExeName
114+
);
115+
}
116+
return null;
117+
};
116118

117119
interface CreateInterfaceRequestParams {
118120
uri: string;

0 commit comments

Comments
 (0)