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

Commit 280112c

Browse files
author
Rusty Key
committed
add some checks
1 parent bf91e25 commit 280112c

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/client/index.ts

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

38+
async function isBucklescriptProject() {
39+
// TODO: we need to use workspace.workspaceFolders here and run LSP server per
40+
// root. For now we'll just run LSP per workspace.
41+
const root = vscode.workspace.rootPath;
42+
if (root == null) {
43+
return false;
44+
}
45+
46+
const bsconfigJson = path.join(root, "bsconfig.json");
47+
48+
if (await exists(bsconfigJson)) {
49+
return true;
50+
}
51+
52+
return false;
53+
}
54+
3855
async function isEsyProject() {
3956
const reasonConfig = vscode.workspace.getConfiguration("reason");
4057
const forceEsy = reasonConfig.get<boolean>("forceEsy", false);
@@ -68,9 +85,63 @@ async function isEsyProject() {
6885
return false;
6986
}
7087

88+
async function getEsyConfig() {
89+
const root = vscode.workspace.rootPath;
90+
if (root == null) {
91+
return false;
92+
}
93+
94+
let configFile = path.join(root, "esy.json");
95+
let isConfigFileExists = await exists(configFile);
96+
if (!isConfigFileExists) {
97+
configFile = path.join(root, "package.json");
98+
}
99+
100+
try {
101+
const data = await readFile(configFile, "utf8");
102+
return JSON.parse(data);
103+
} catch (_e) {
104+
return null;
105+
}
106+
}
107+
108+
async function isEsyConfiguredProperly() {
109+
const esyConfig = await getEsyConfig();
110+
const requiredDependencies = ["ocaml", "@opam/merlin-lsp"];
111+
112+
if (!esyConfig) {
113+
vscode.window.showInformationMessage("LSP is unable to start. Couldn't find esy configuration");
114+
return false;
115+
}
116+
117+
return requiredDependencies.every(dependency => {
118+
if (!esyConfig.devDependencies[dependency]) {
119+
vscode.window.showInformationMessage(`LSP is unable to start. Add "${dependency}" to your devDependencies`);
120+
return false;
121+
}
122+
123+
return true;
124+
});
125+
}
126+
127+
async function isConfuguredProperly(isEsyProject: boolean) {
128+
if (isEsyProject) {
129+
return await isEsyConfiguredProperly();
130+
}
131+
132+
if (isBucklescriptProject()) return true;
133+
134+
vscode.window.showInformationMessage(
135+
"LSP is unable to start. Extension couldn't detect type of the project. Provide esy or bucklescript configuration. More in README.",
136+
);
137+
return false;
138+
}
139+
71140
export async function launch(context: vscode.ExtensionContext): Promise<void> {
72141
const isEasyProject = await isEsyProject();
73142

143+
if (!isConfuguredProperly(isEasyProject)) return;
144+
74145
return launchMerlinLsp(context, {
75146
useEsy: isEasyProject,
76147
});

0 commit comments

Comments
 (0)