Skip to content

Commit 6f32a31

Browse files
committed
Clean up
1 parent 04b169c commit 6f32a31

File tree

2 files changed

+54
-85
lines changed

2 files changed

+54
-85
lines changed

server/src/RescriptEditorSupport.ts

Lines changed: 39 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,33 @@
11
import { fileURLToPath } from "url";
22
import { RequestMessage } from "vscode-languageserver";
3-
import { CompletionItem, Hover, Location } from "vscode-languageserver-protocol";
3+
import {
4+
CompletionItem,
5+
Hover,
6+
Location,
7+
} from "vscode-languageserver-protocol";
48
import * as utils from "./utils";
5-
import * as path from "path";
69
import { execFileSync } from "child_process";
710
import fs from "fs";
8-
9-
let binariesFolder = path.join(
10-
path.dirname(__dirname),
11-
"analysis_binaries"
12-
)
13-
14-
// For local development and CI tests
15-
let currentPlatformBinaryPath = path.join(
16-
binariesFolder,
17-
"current-platform.exe"
18-
);
19-
// Platform-specific production binaries manually downloaded from CI
20-
let productionBinaryPath = path.join(
21-
binariesFolder,
22-
process.platform + ".exe"
23-
);
11+
import {
12+
analysisCurrentPlatformBinaryPath,
13+
analysisProductionBinaryPath,
14+
} from "./constants";
2415

2516
let findBinary = () => {
26-
if (fs.existsSync(currentPlatformBinaryPath)) {
27-
return currentPlatformBinaryPath
28-
} else if (fs.existsSync(productionBinaryPath)) {
29-
return productionBinaryPath
17+
if (fs.existsSync(analysisCurrentPlatformBinaryPath)) {
18+
return analysisCurrentPlatformBinaryPath;
19+
} else if (fs.existsSync(analysisProductionBinaryPath)) {
20+
return analysisProductionBinaryPath;
3021
} else {
31-
return null
22+
return null;
3223
}
33-
}
34-
35-
// export let binaryExists = fs.existsSync(binaryPath);
36-
37-
// let findExecutable = (uri: string) => {
38-
// let filePath = fileURLToPath(uri);
39-
// let projectRootPath = utils.findProjectRootOfFile(filePath);
40-
// if (projectRootPath == null || !binaryExists) {
41-
// return null;
42-
// } else {
43-
// return {
44-
// binaryPath: binaryPath,
45-
// filePath: filePath,
46-
// cwd: projectRootPath,
47-
// };
48-
// }
49-
// };
50-
51-
// type dumpCommandResult = {
52-
// hover?: string;
53-
// definition?: { uri?: string; range: any };
54-
// };
55-
// export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null {
56-
// let executable = findExecutable(msg.params.textDocument.uri);
57-
// if (executable == null) {
58-
// return null;
59-
// }
60-
61-
// let command =
62-
// executable.filePath +
63-
// ":" +
64-
// msg.params.position.line +
65-
// ":" +
66-
// msg.params.position.character;
67-
68-
// try {
69-
// let stdout = execFileSync(executable.binaryPath, ["dump", command], {
70-
// cwd: executable.cwd,
71-
// });
72-
// let parsed = JSON.parse(stdout.toString());
73-
// if (parsed && parsed[0]) {
74-
// return parsed[0];
75-
// } else {
76-
// return null;
77-
// }
78-
// } catch (error) {
79-
// // TODO: @cristianoc any exception possible?
80-
// return null;
81-
// }
82-
// }
24+
};
8325

8426
export function runCompletionCommand(
8527
msg: RequestMessage,
8628
code: string
8729
): CompletionItem[] | null {
88-
let filePath = fileURLToPath(msg.params.textDocument.uri)
30+
let filePath = fileURLToPath(msg.params.textDocument.uri);
8931
let projectRootPath = utils.findProjectRootOfFile(filePath);
9032
let binaryPath = findBinary();
9133
if (binaryPath == null || projectRootPath == null) {
@@ -97,7 +39,13 @@ export function runCompletionCommand(
9739
try {
9840
let stdout = execFileSync(
9941
binaryPath,
100-
["complete", filePath, msg.params.position.line, msg.params.position.character, tmpname],
42+
[
43+
"complete",
44+
filePath,
45+
msg.params.position.line,
46+
msg.params.position.character,
47+
tmpname,
48+
],
10149
{ cwd: projectRootPath }
10250
);
10351
return JSON.parse(stdout.toString());
@@ -109,10 +57,8 @@ export function runCompletionCommand(
10957
}
11058
}
11159

112-
export function runHoverCommand(
113-
msg: RequestMessage,
114-
): Hover | null {
115-
let filePath = fileURLToPath(msg.params.textDocument.uri)
60+
export function runHoverCommand(msg: RequestMessage): Hover | null {
61+
let filePath = fileURLToPath(msg.params.textDocument.uri);
11662
let projectRootPath = utils.findProjectRootOfFile(filePath);
11763
let binaryPath = findBinary();
11864
if (binaryPath == null || projectRootPath == null) {
@@ -122,7 +68,12 @@ export function runHoverCommand(
12268
try {
12369
let stdout = execFileSync(
12470
binaryPath,
125-
["hover", filePath, msg.params.position.line, msg.params.position.character],
71+
[
72+
"hover",
73+
filePath,
74+
msg.params.position.line,
75+
msg.params.position.character,
76+
],
12677
{ cwd: projectRootPath }
12778
);
12879
return JSON.parse(stdout.toString());
@@ -132,10 +83,8 @@ export function runHoverCommand(
13283
}
13384
}
13485

135-
export function runDefinitionCommand(
136-
msg: RequestMessage,
137-
): Location | null {
138-
let filePath = fileURLToPath(msg.params.textDocument.uri)
86+
export function runDefinitionCommand(msg: RequestMessage): Location | null {
87+
let filePath = fileURLToPath(msg.params.textDocument.uri);
13988
let projectRootPath = utils.findProjectRootOfFile(filePath);
14089
let binaryPath = findBinary();
14190
if (binaryPath == null || projectRootPath == null) {
@@ -145,7 +94,12 @@ export function runDefinitionCommand(
14594
try {
14695
let stdout = execFileSync(
14796
binaryPath,
148-
["definition", filePath, msg.params.position.line, msg.params.position.character],
97+
[
98+
"definition",
99+
filePath,
100+
msg.params.position.line,
101+
msg.params.position.character,
102+
],
149103
{ cwd: projectRootPath }
150104
);
151105
return JSON.parse(stdout.toString());

server/src/constants.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ export let bscExeReScriptPartialPath = path.join(
1616
"bsc.exe"
1717
);
1818

19+
let analysisBinariesFolder = path.join(
20+
path.dirname(__dirname),
21+
"analysis_binaries"
22+
);
23+
// For local development and CI tests
24+
export let analysisCurrentPlatformBinaryPath = path.join(
25+
analysisBinariesFolder,
26+
"current-platform.exe"
27+
);
28+
// Platform-specific production binaries manually downloaded from CI
29+
export let analysisProductionBinaryPath = path.join(
30+
analysisBinariesFolder,
31+
process.platform + ".exe"
32+
);
33+
1934
// can't use the native bsb since we might need the watcher -w flag, which is only in the js wrapper
2035
// export let bsbPartialPath = path.join('node_modules', 'bs-platform', process.platform, 'bsb.exe');
2136
export let bsbNodePartialPath = path.join("node_modules", ".bin", "bsb");

0 commit comments

Comments
 (0)