Skip to content

Commit 8bcb1fc

Browse files
committed
more work
1 parent 16415a5 commit 8bcb1fc

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

.vscodeignore

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ analysis.opam
1515
tools.opam
1616
.ocamlformat
1717
.ocamlformat-ignore
18+
_opam/
19+
_build/
20+
Makefile

client/src/extension.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ export function activate(context: ExtensionContext) {
294294
if (
295295
affectsConfiguration("rescript.settings.inlayHints") ||
296296
affectsConfiguration("rescript.settings.codeLens") ||
297-
affectsConfiguration("rescript.settings.signatureHelp") ||
298-
affectsConfiguration("rescript.settings.incrementalTypechecking")
297+
affectsConfiguration("rescript.settings.signatureHelp")
299298
) {
300299
commands.executeCommand("rescript-vscode.restart_language_server");
301300
} else {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@
169169
},
170170
"rescript.settings.incrementalTypechecking.enabled": {
171171
"type": "boolean",
172-
"default": true,
173-
"description": "Enable incremental type checking."
172+
"default": false,
173+
"description": "(beta/experimental) Enable incremental type checking."
174174
},
175175
"rescript.settings.binaryPath": {
176176
"type": ["string", "null"],

server/src/incrementalCompilation.ts

+41-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import * as c from "./constants";
1313
* TODO CMT stuff
1414
* - Compile resi
1515
* - Wait a certain threshold for compilation before using the old cmt
16+
* - Monorepos? Namespaces
17+
* Questions:
18+
* - We trigger no incremental compilation for other files. This might be problematic if we want to go across files. Track dependencies? What's supposed to be used when and where?
19+
* Improvements:
20+
* - Ask build system for complete build command for file X, instead of piecing together from build.ninja. Rewatch?
21+
* - Have build system communicate what was actually rebuilt after compilation finishes.
1622
*/
1723

1824
let debug = true;
@@ -22,6 +28,8 @@ let savedIncrementalFiles: Set<string> = new Set();
2228
let compileContentsCache: Map<string, { timeout: any; triggerToken: number }> =
2329
new Map();
2430
let compileContentsListeners: Map<string, Array<() => void>> = new Map();
31+
const incrementalFolderName = "___incremental";
32+
const incrementalFileFolderLocation = `lib/bs/${incrementalFolderName}`;
2533

2634
export function cleanupIncrementalFilesAfterCompilation(changedPath: string) {
2735
const projectRootPath = utils.findProjectRootOfFile(changedPath);
@@ -40,7 +48,7 @@ export function removeIncrementalFileFolder(
4048
onAfterRemove?: () => void
4149
) {
4250
fs.rm(
43-
path.resolve(projectRootPath, "lib/bs/___incremental"),
51+
path.resolve(projectRootPath, incrementalFileFolderLocation),
4452
{ force: true, recursive: true },
4553
(_) => {
4654
onAfterRemove?.();
@@ -50,7 +58,10 @@ export function removeIncrementalFileFolder(
5058

5159
export function recreateIncrementalFileFolder(projectRootPath: string) {
5260
removeIncrementalFileFolder(projectRootPath, () => {
53-
fs.mkdir(path.resolve(projectRootPath, "lib/bs/___incremental"), (_) => {});
61+
fs.mkdir(
62+
path.resolve(projectRootPath, incrementalFileFolderLocation),
63+
(_) => {}
64+
);
5465
});
5566
}
5667

@@ -59,7 +70,11 @@ export function fileIsIncrementallyCompiled(filePath: string): boolean {
5970
let fileName = path.basename(filePath, ".res");
6071
if (projectRootPath != null) {
6172
return fs.existsSync(
62-
path.resolve(projectRootPath, "lib/bs/___incremental", fileName + ".cmt")
73+
path.resolve(
74+
projectRootPath,
75+
incrementalFileFolderLocation,
76+
fileName + ".cmt"
77+
)
6378
);
6479
}
6580
return false;
@@ -77,7 +92,7 @@ export function cleanUpIncrementalFiles(
7792
path.basename(filePath),
7893
].forEach((file) => {
7994
fs.unlink(
80-
path.resolve(projectRootPath, "lib/bs/___incremental", file),
95+
path.resolve(projectRootPath, incrementalFileFolderLocation, file),
8196
(_) => {}
8297
);
8398
});
@@ -149,19 +164,24 @@ function argsFromCommandString(cmdString: string): Array<Array<string>> {
149164

150165
for (let i = 0; i <= s.length - 1; i++) {
151166
let item = s[i];
152-
let nextItem = s[i + 1] ?? "";
167+
let nextIndex = i + 1;
168+
let nextItem = s[nextIndex] ?? "";
153169
if (item.startsWith("-") && nextItem.startsWith("-")) {
154170
// Single entry arg
155171
args.push([item]);
156-
} else if (item.startsWith("-") && s[i + 1]?.startsWith("'")) {
157-
let nextIndex = i + 1;
172+
} else if (item.startsWith("-") && nextItem.startsWith("'")) {
158173
// Quoted arg, take until ending '
159-
let arg = [s[nextIndex]];
174+
let arg = [nextItem.slice(1)];
160175
for (let x = nextIndex + 1; x <= s.length - 1; x++) {
161-
let nextItem = s[x];
162-
arg.push(nextItem);
163-
if (nextItem.endsWith("'")) {
164-
i = x + 1;
176+
let subItem = s[x];
177+
let break_ = false;
178+
if (subItem.endsWith("'")) {
179+
subItem = subItem.slice(0, subItem.length - 1);
180+
i = x;
181+
break_ = true;
182+
}
183+
arg.push(subItem);
184+
if (break_) {
165185
break;
166186
}
167187
}
@@ -224,11 +244,15 @@ async function compileContents(
224244
if (debug) console.log("Did not find bsc.");
225245
return;
226246
}
227-
let incrementalFilePath = path.resolve(
247+
let incrementalFolderPath = path.resolve(
228248
projectRootPath,
229-
"lib/bs/___incremental",
230-
fileName
249+
incrementalFileFolderLocation
231250
);
251+
let incrementalFilePath = path.resolve(incrementalFolderPath, fileName);
252+
253+
if (!fs.existsSync(incrementalFolderPath)) {
254+
fs.mkdirSync(incrementalFolderPath);
255+
}
232256

233257
fs.writeFileSync(incrementalFilePath, fileContent);
234258

@@ -240,7 +264,7 @@ async function compileContents(
240264

241265
let callArgs: Array<string> = [
242266
"-I",
243-
path.resolve(projectRootPath, "lib/bs/___incremental"),
267+
path.resolve(projectRootPath, incrementalFileFolderLocation),
244268
];
245269

246270
buildArgs.forEach(([key, value]: Array<string>) => {
@@ -298,7 +322,7 @@ async function compileContents(
298322
.filter(
299323
(d) =>
300324
!d.message.startsWith("Uninterpreted extension 'rescript.") &&
301-
!d.message.includes(`/___incremental/${fileName}`)
325+
!d.message.includes(`/${incrementalFolderName}/${fileName}`)
302326
);
303327

304328
let notification: p.NotificationMessage = {

0 commit comments

Comments
 (0)