Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 7000de8

Browse files
author
Rusty Key
committed
prebuild merlin-lsp/merlin-reason and use them for reason projects
1 parent 8bd13e5 commit 7000de8

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

executables/darwin/ocamlmerlin-lsp

8.88 MB
Binary file not shown.
11.4 MB
Binary file not shown.

executables/linux/ocamlmerlin-lsp

6.86 MB
Binary file not shown.
11.4 MB
Binary file not shown.

src/client/index.ts

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ class ErrorHandler {
3535
}
3636
}
3737

38-
export async function launch(context: vscode.ExtensionContext): Promise<void> {
39-
const isEasyProject = await isEsyProject();
40-
return launchMerlinLsp(context, { useEsy: isEasyProject });
41-
}
42-
4338
async function isEsyProject() {
4439
const reasonConfig = vscode.workspace.getConfiguration("reason");
4540
const forceEsy = reasonConfig.get<boolean>("forceEsy", false);
@@ -73,23 +68,74 @@ async function isEsyProject() {
7368
return false;
7469
}
7570

76-
function getMerlinLspOptions(options: { useEsy: boolean }) {
71+
async function isBSProject() {
72+
// TODO: we need to use workspace.workspaceFolders here and run LSP server per
73+
// root. For now we'll just run LSP per workspace.
74+
const root = vscode.workspace.rootPath;
75+
if (root == null) {
76+
return false;
77+
}
78+
79+
const bsconfigJson = path.join(root, "bsconfig.json");
80+
81+
if (await exists(bsconfigJson)) {
82+
return true;
83+
}
84+
85+
return false;
86+
}
87+
88+
export async function launch(context: vscode.ExtensionContext): Promise<void> {
89+
const isEasyProject = await isEsyProject();
90+
const isBucklescriptProject = await isBSProject();
91+
return launchMerlinLsp(context, {
92+
isBucklescriptProject,
93+
useEsy: isEasyProject,
94+
});
95+
}
96+
97+
function getPrebuiltExecutablesPath() {
98+
return path.join(__dirname, `../../../executables/${process.platform}`);
99+
}
100+
101+
function getMerlinLspPath(isBucklescriptProject: boolean) {
77102
const reasonConfig = vscode.workspace.getConfiguration("reason");
78-
let ocamlmerlinLsp = reasonConfig.get<string | null>("path.ocamlmerlin-lsp", null);
79-
if (ocamlmerlinLsp == null) {
80-
ocamlmerlinLsp = isWin ? "ocamlmerlin-lsp.exe" : "ocamlmerlin-lsp";
103+
let merlinLspPath = reasonConfig.get<string | null>("path.ocamlmerlin-lsp", null);
104+
105+
if (merlinLspPath == null) {
106+
merlinLspPath = isWin ? "ocamlmerlin-lsp.exe" : "ocamlmerlin-lsp";
107+
108+
if (isBucklescriptProject) {
109+
merlinLspPath = path.join(getPrebuiltExecutablesPath(), merlinLspPath);
110+
}
81111
}
82112

113+
return merlinLspPath;
114+
}
115+
116+
function getMerlinReasonDir() {
117+
const reasonConfig = vscode.workspace.getConfiguration("reason");
118+
const merlinReasonPath = reasonConfig.get<string | null>("path.ocamlmerlin-reason", null);
119+
120+
if (merlinReasonPath == null) return getPrebuiltExecutablesPath();
121+
122+
return path.dirname(merlinReasonPath);
123+
}
124+
125+
function getMerlinLspOptions(options: { useEsy: boolean; isBucklescriptProject: boolean }) {
126+
const merlinLsp = getMerlinLspPath(options.isBucklescriptProject);
127+
const merlinReasonDir = getMerlinReasonDir();
128+
83129
let run;
84130
if (options.useEsy) {
85131
run = {
86-
args: ["exec-command", "--include-current-env", ocamlmerlinLsp],
132+
args: ["exec-command", "--include-current-env", merlinLsp],
87133
command: process.platform === "win32" ? "esy.cmd" : "esy",
88134
};
89135
} else {
90136
run = {
91137
args: [],
92-
command: ocamlmerlinLsp,
138+
command: merlinLsp,
93139
};
94140
}
95141

@@ -101,6 +147,7 @@ function getMerlinLspOptions(options: { useEsy: boolean }) {
101147
...process.env,
102148
MERLIN_LOG: "-",
103149
OCAMLRUNPARAM: "b",
150+
PATH: merlinReasonDir,
104151
},
105152
},
106153
},
@@ -111,14 +158,18 @@ function getMerlinLspOptions(options: { useEsy: boolean }) {
111158
...process.env,
112159
MERLIN_LOG: "-",
113160
OCAMLRUNPARAM: "b",
161+
PATH: merlinReasonDir,
114162
},
115163
},
116164
},
117165
};
118166
return serverOptions;
119167
}
120168

121-
export async function launchMerlinLsp(context: vscode.ExtensionContext, options: { useEsy: boolean }): Promise<void> {
169+
export async function launchMerlinLsp(
170+
context: vscode.ExtensionContext,
171+
options: { useEsy: boolean; isBucklescriptProject: boolean },
172+
): Promise<void> {
122173
const serverOptions = getMerlinLspOptions(options);
123174
const reasonConfig = vscode.workspace.getConfiguration("reason");
124175

0 commit comments

Comments
 (0)