Skip to content

Commit 40887dc

Browse files
authored
Incremental typechecking (#939)
* basic PoC of doing a sort of incremental typechecking * move incremental compilation stuff to its own file * reset back version * more work * refactor * fixes and adjustments for namespaced packages * adjust watching * make incremental compilation of resi work * report error when incremental typechecking fails * config tweaks * more guard rails * debug logging switch * robustness * changelog
1 parent 839349a commit 40887dc

File tree

9 files changed

+792
-95
lines changed

9 files changed

+792
-95
lines changed

Diff for: .vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"--extensionDevelopmentPath=${workspaceRoot}"
1212
],
1313
"outFiles": [
14-
"${workspaceRoot}/client/out/*.js"
14+
"${workspaceRoot}/client/out/**/*.js"
1515
],
1616
"preLaunchTask": {
1717
"type": "npm",
@@ -25,7 +25,7 @@
2525
"port": 6009,
2626
"restart": true,
2727
"outFiles": [
28-
"${workspaceRoot}/server/out/*.js"
28+
"${workspaceRoot}/server/out/**/*.js"
2929
]
3030
},
3131
{

Diff for: .vscodeignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ tools.opam
1818
client/node_modules
1919
server/node_modules
2020
_opam
21-
_build
21+
_build
22+
Makefile

Diff for: CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
1313
## master
1414

15-
## 1.42.0
15+
#### :rocket: New Feature
1616

17-
#### :bug: Bug Fix
17+
- Experimental support for type checking without saving the file :tada:. https://github.com/rescript-lang/rescript-vscode/pull/939
1818

19-
- Fix issue with unlabelled arg code swallowing completions. https://github.com/rescript-lang/rescript-vscode/pull/937
19+
## 1.42.0
2020

2121
#### :bug: Bug Fix
2222

23+
- Fix issue with unlabelled arg code swallowing completions. https://github.com/rescript-lang/rescript-vscode/pull/937
2324
- Fix issue where completion inside of switch expression would not work in some cases. https://github.com/rescript-lang/rescript-vscode/pull/936
2425
- Fix bug that made empty prop expressions in JSX not complete if in the middle of a JSX element. https://github.com/rescript-lang/rescript-vscode/pull/935
2526

Diff for: analysis/src/Cmt.ml

+19-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,25 @@ let fullFromUri ~uri =
1616
let moduleName =
1717
BuildSystem.namespacedName package.namespace (FindFiles.getName path)
1818
in
19-
match Hashtbl.find_opt package.pathsForModule moduleName with
20-
| Some paths ->
21-
let cmt = getCmtPath ~uri paths in
22-
fullForCmt ~moduleName ~package ~uri cmt
23-
| None ->
24-
prerr_endline ("can't find module " ^ moduleName);
25-
None)
19+
let incrementalCmtPath =
20+
package.rootPath ^ "/lib/bs/___incremental" ^ "/" ^ moduleName
21+
^
22+
match Files.classifySourceFile path with
23+
| Resi -> ".cmti"
24+
| _ -> ".cmt"
25+
in
26+
match fullForCmt ~moduleName ~package ~uri incrementalCmtPath with
27+
| Some cmtInfo ->
28+
if Debug.verbose () then Printf.printf "[cmt] Found incremental cmt\n";
29+
Some cmtInfo
30+
| None -> (
31+
match Hashtbl.find_opt package.pathsForModule moduleName with
32+
| Some paths ->
33+
let cmt = getCmtPath ~uri paths in
34+
fullForCmt ~moduleName ~package ~uri cmt
35+
| None ->
36+
prerr_endline ("can't find module " ^ moduleName);
37+
None))
2638

2739
let fullsFromModule ~package ~moduleName =
2840
if Hashtbl.mem package.pathsForModule moduleName then

Diff for: package.json

+18-3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@
176176
"default": true,
177177
"description": "Enable signature help for function calls."
178178
},
179+
"rescript.settings.incrementalTypechecking.enabled": {
180+
"type": "boolean",
181+
"default": false,
182+
"description": "(beta/experimental) Enable incremental type checking."
183+
},
184+
"rescript.settings.incrementalTypechecking.acrossFiles": {
185+
"type": "boolean",
186+
"default": false,
187+
"description": "(beta/experimental) Enable incremental type checking across files, so that unsaved file A gets access to unsaved file B."
188+
},
189+
"rescript.settings.incrementalTypechecking.debugLogging": {
190+
"type": "boolean",
191+
"default": false,
192+
"description": "(debug) Enable debug logging (ends up in the extension output)."
193+
},
179194
"rescript.settings.binaryPath": {
180195
"type": [
181196
"string",
@@ -230,9 +245,9 @@
230245
},
231246
"scripts": {
232247
"clean": "rm -rf client/out server/out",
233-
"vscode:prepublish": "npm run clean && npm run compile && npm run bundle",
234-
"compile": "tsc",
235-
"watch": "tsc -w",
248+
"vscode:prepublish": "npm run clean && npm run bundle",
249+
"compile": "tsc -b",
250+
"watch": "tsc -b -w",
236251
"postinstall": "cd server && npm i && cd ../client && npm i && cd ../tools && npm i && cd ../tools/tests && npm i && cd ../../analysis/tests && npm i && cd ../reanalyze/examples/deadcode && npm i && cd ../termination && npm i",
237252
"bundle-server": "esbuild server/src/cli.ts --bundle --sourcemap --outfile=server/out/cli.js --format=cjs --platform=node --loader:.node=file --minify",
238253
"bundle-client": "esbuild client/src/extension.ts --bundle --external:vscode --sourcemap --outfile=client/out/extension.js --format=cjs --platform=node --loader:.node=file --minify",

Diff for: server/src/config.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Message } from "vscode-languageserver-protocol";
2+
3+
export type send = (msg: Message) => void;
4+
5+
export interface extensionConfiguration {
6+
allowBuiltInFormatter: boolean;
7+
askToStartBuild: boolean;
8+
inlayHints: {
9+
enable: boolean;
10+
maxLength: number | null;
11+
};
12+
codeLens: boolean;
13+
binaryPath: string | null;
14+
platformPath: string | null;
15+
signatureHelp: {
16+
enabled: boolean;
17+
};
18+
incrementalTypechecking: {
19+
enabled: boolean;
20+
acrossFiles: boolean;
21+
debugLogging: boolean;
22+
};
23+
}
24+
25+
// All values here are temporary, and will be overridden as the server is
26+
// initialized, and the current config is received from the client.
27+
let config: { extensionConfiguration: extensionConfiguration } = {
28+
extensionConfiguration: {
29+
allowBuiltInFormatter: false,
30+
askToStartBuild: true,
31+
inlayHints: {
32+
enable: false,
33+
maxLength: 25,
34+
},
35+
codeLens: false,
36+
binaryPath: null,
37+
platformPath: null,
38+
signatureHelp: {
39+
enabled: true,
40+
},
41+
incrementalTypechecking: {
42+
enabled: false,
43+
acrossFiles: true,
44+
debugLogging: true,
45+
},
46+
},
47+
};
48+
49+
export default config;

0 commit comments

Comments
 (0)