Skip to content

Commit e045914

Browse files
authored
Async rewrite (#1093)
* Add semver dep * Create async version of utils.findBinary * Make findBscExeBinary and findEditorAnalysisBinary async * Remove unused constants * Make utils.runAnalysisAfterSanityCheck async * Make parseCompilerLogOutput async * Make server.sendUpdatedDiagnostics async * Make server.syncProjectConfigCache async * Make server.closedFile async * Make server.rename async * Make server.completionResolve async * Trim trailing whitespace * Use async allback to child_process.execFile in incrementalCompilation.compileContents * Make server.updateDiagnosticSyntax async * Make server.hover async * Make server.inlayHint async * Make server.codeLens async * Make server.signatureHelp async * Make server.definition async * Make server.typeDefinition async * Make server.documentSymbol async * Make server.semanticTokens async * Make server.completion async * Make server.codeAction async * Make server.createInterface async * Make utils.runAnalysisCommand async * Make utils.getReferencesForPosition async * Make server.references async * Make server.prepareRename async * Make utils.findReScriptVersionForProjectRoot async * Replace findReScriptVersion(filePath) with findReScriptVersionForProjectRoot(projectRootPath) * Remove unused utils.findPlatformPath * Make server.findRescriptBinary async * Remove unused constant * s/findBinaryAsync/findBinary * Fix rescript binary package import path * Move semver dependency from root package.json to server/package.json * Use semver package for version checks * Update typescript from v4.7.3 to v5.8.3 * Add CHANGELOG
1 parent e1d635a commit e045914

11 files changed

+238
-280
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ rescript-tools.exe
2323

2424
_opam/
2525
_build/
26+
27+
*.tsbuildinfo

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
- Fix: JSON from `rescript-code-editor-analysis` was not always escaped properly, which prevented code actions from being available in certain situations https://github.com/rescript-lang/rescript-vscode/pull/1089
3434

35+
#### :house: Internal
36+
37+
- Find binary paths asynchronously. On `>=12.0.0-alpha.13` we do this by dynamically importing the `@rescript/{target}` package in the project root. https://github.com/rescript-lang/rescript-vscode/pull/1093
38+
3539
## 1.62.0
3640

3741
#### :nail_care: Polish

package-lock.json

Lines changed: 23 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@
255255
},
256256
"devDependencies": {
257257
"@types/node": "^14.14.41",
258+
"@types/semver": "^7.7.0",
258259
"@types/vscode": "1.68.0",
259260
"esbuild": "^0.20.1",
260-
"semver": "^7.3.7",
261-
"typescript": "^4.7.3"
261+
"typescript": "^5.8.3"
262262
}
263263
}

server/package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
},
3232
"dependencies": {
3333
"chokidar": "^3.5.1",
34+
"semver": "^7.7.2",
3435
"vscode-jsonrpc": "^8.0.1",
3536
"vscode-languageserver": "^8.0.1",
3637
"vscode-languageserver-protocol": "^3.17.1"

server/src/codeActions.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ let takeUntil = (array: string[], startsWith: string): string[] => {
141141
return res;
142142
};
143143

144-
export let findCodeActionsInDiagnosticsMessage = ({
144+
export let findCodeActionsInDiagnosticsMessage = async ({
145145
diagnostic,
146146
diagnosticMessage,
147147
file,
148148
range,
149149
addFoundActionsHere: codeActions,
150150
}: findCodeActionsConfig) => {
151-
diagnosticMessage.forEach((line, index, array) => {
151+
for (const [index, line] of diagnosticMessage.entries()) {
152152
// Because of how actions work, there can only be one per diagnostic. So,
153153
// halt whenever a code action has been found.
154154
let codeActionExtractors = [
@@ -166,8 +166,8 @@ export let findCodeActionsInDiagnosticsMessage = ({
166166
let didFindAction = false;
167167

168168
try {
169-
didFindAction = extractCodeAction({
170-
array,
169+
didFindAction = await extractCodeAction({
170+
array: diagnosticMessage,
171171
codeActions,
172172
diagnostic,
173173
file,
@@ -183,7 +183,7 @@ export let findCodeActionsInDiagnosticsMessage = ({
183183
break;
184184
}
185185
}
186-
});
186+
}
187187
};
188188

189189
interface codeActionExtractorConfig {
@@ -196,12 +196,12 @@ interface codeActionExtractorConfig {
196196
codeActions: filesCodeActions;
197197
}
198198

199-
type codeActionExtractor = (config: codeActionExtractorConfig) => boolean;
199+
type codeActionExtractor = (config: codeActionExtractorConfig) => Promise<boolean>;
200200

201201
// This action extracts hints the compiler emits for misspelled identifiers, and
202202
// offers to replace the misspelled name with the correct name suggested by the
203203
// compiler.
204-
let didYouMeanAction: codeActionExtractor = ({
204+
let didYouMeanAction: codeActionExtractor = async ({
205205
codeActions,
206206
diagnostic,
207207
file,
@@ -245,7 +245,7 @@ let didYouMeanAction: codeActionExtractor = ({
245245
};
246246

247247
// This action offers to wrap patterns that aren't option in Some.
248-
let wrapInSome: codeActionExtractor = ({
248+
let wrapInSome: codeActionExtractor = async ({
249249
codeActions,
250250
diagnostic,
251251
file,
@@ -425,7 +425,7 @@ let handleUndefinedRecordFieldsAction = ({
425425
// being undefined. We then offers an action that inserts all of the record
426426
// fields, with an `assert false` dummy value. `assert false` is so applying the
427427
// code action actually compiles.
428-
let addUndefinedRecordFieldsV10: codeActionExtractor = ({
428+
let addUndefinedRecordFieldsV10: codeActionExtractor = async ({
429429
array,
430430
codeActions,
431431
diagnostic,
@@ -459,7 +459,7 @@ let addUndefinedRecordFieldsV10: codeActionExtractor = ({
459459
return false;
460460
};
461461

462-
let addUndefinedRecordFieldsV11: codeActionExtractor = ({
462+
let addUndefinedRecordFieldsV11: codeActionExtractor = async ({
463463
array,
464464
codeActions,
465465
diagnostic,
@@ -508,7 +508,7 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({
508508

509509
// This action detects suggestions of converting between mismatches in types
510510
// that the compiler tells us about.
511-
let simpleConversion: codeActionExtractor = ({
511+
let simpleConversion: codeActionExtractor = async ({
512512
line,
513513
codeActions,
514514
file,
@@ -554,7 +554,7 @@ let simpleConversion: codeActionExtractor = ({
554554

555555
// This action will apply a curried function (essentially inserting a dot in the
556556
// correct place).
557-
let applyUncurried: codeActionExtractor = ({
557+
let applyUncurried: codeActionExtractor = async ({
558558
line,
559559
codeActions,
560560
file,
@@ -608,7 +608,7 @@ let applyUncurried: codeActionExtractor = ({
608608

609609
// This action detects missing cases for exhaustive pattern matches, and offers
610610
// to insert dummy branches (using `failwith("TODO")`) for those branches.
611-
let simpleAddMissingCases: codeActionExtractor = ({
611+
let simpleAddMissingCases: codeActionExtractor = async ({
612612
line,
613613
codeActions,
614614
file,
@@ -629,7 +629,7 @@ let simpleAddMissingCases: codeActionExtractor = ({
629629

630630
let filePath = fileURLToPath(file);
631631

632-
let newSwitchCode = utils.runAnalysisAfterSanityCheck(filePath, [
632+
let newSwitchCode = await utils.runAnalysisAfterSanityCheck(filePath, [
633633
"codemod",
634634
filePath,
635635
range.start.line,
@@ -665,7 +665,7 @@ let simpleAddMissingCases: codeActionExtractor = ({
665665
// This detects concrete variables or values put in a position which expects an
666666
// optional of that same type, and offers to wrap the value/variable in
667667
// `Some()`.
668-
let simpleTypeMismatches: codeActionExtractor = ({
668+
let simpleTypeMismatches: codeActionExtractor = async ({
669669
line,
670670
codeActions,
671671
file,

server/src/constants.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,8 @@ export let platformDir =
77
// See https://microsoft.github.io/language-server-protocol/specification Abstract Message
88
// version is fixed to 2.0
99
export let jsonrpcVersion = "2.0";
10-
export let platformPath = path.join("rescript", platformDir);
11-
export let nodeModulesPlatformPath = path.join("node_modules", platformPath);
12-
export let bscExeName = "bsc.exe";
13-
export let editorAnalysisName = "rescript-editor-analysis.exe";
14-
export let bscNativeReScriptPartialPath = path.join(
15-
nodeModulesPlatformPath,
16-
bscExeName
17-
);
1810

11+
export let editorAnalysisName = "rescript-editor-analysis.exe";
1912
export let builtinAnalysisDevPath = path.join(
2013
path.dirname(__dirname),
2114
"..",
@@ -34,12 +27,6 @@ export let bscBinName = "bsc";
3427

3528
export let nodeModulesBinDir = path.join("node_modules", ".bin");
3629

37-
// can't use the native bsb/rescript since we might need the watcher -w flag, which is only in the JS wrapper
38-
export let rescriptNodePartialPath = path.join(
39-
nodeModulesBinDir,
40-
rescriptBinName
41-
);
42-
4330
export let bsbLock = ".bsb.lock";
4431
export let bsconfigPartialPath = "bsconfig.json";
4532
export let rescriptJsonPartialPath = "rescript.json";

0 commit comments

Comments
 (0)