Skip to content

Async rewrite #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0b1fc72
Add semver dep
mediremi May 15, 2025
4af5bd7
Create async version of utils.findBinary
mediremi May 15, 2025
cecf7c4
Make findBscExeBinary and findEditorAnalysisBinary async
mediremi May 15, 2025
df29b18
Remove unused constants
mediremi May 15, 2025
f4cde5a
Make utils.runAnalysisAfterSanityCheck async
mediremi May 15, 2025
d729e3a
Make parseCompilerLogOutput async
mediremi May 15, 2025
f77e6dd
Make server.sendUpdatedDiagnostics async
mediremi May 15, 2025
4612504
Make server.syncProjectConfigCache async
mediremi May 15, 2025
f642b24
Make server.closedFile async
mediremi May 15, 2025
e944890
Make server.rename async
mediremi May 15, 2025
8ee0994
Make server.completionResolve async
mediremi May 15, 2025
015adaf
Trim trailing whitespace
mediremi May 15, 2025
74178cb
Use async allback to child_process.execFile in incrementalCompilation…
mediremi May 15, 2025
f187e08
Make server.updateDiagnosticSyntax async
mediremi May 15, 2025
82b7cdb
Make server.hover async
mediremi May 15, 2025
9430597
Make server.inlayHint async
mediremi May 15, 2025
8150858
Make server.codeLens async
mediremi May 15, 2025
a3b5d14
Make server.signatureHelp async
mediremi May 15, 2025
9e9058e
Make server.definition async
mediremi May 15, 2025
f0de0d1
Make server.typeDefinition async
mediremi May 15, 2025
743dfcf
Make server.documentSymbol async
mediremi May 15, 2025
490dd35
Make server.semanticTokens async
mediremi May 15, 2025
2f85bc5
Make server.completion async
mediremi May 15, 2025
379a116
Make server.codeAction async
mediremi May 15, 2025
95ca8da
Make server.createInterface async
mediremi May 15, 2025
cbe1239
Make utils.runAnalysisCommand async
mediremi May 15, 2025
28226f5
Make utils.getReferencesForPosition async
mediremi May 15, 2025
90a573e
Make server.references async
mediremi May 15, 2025
032026e
Make server.prepareRename async
mediremi May 15, 2025
d7bc10a
Make utils.findReScriptVersionForProjectRoot async
mediremi May 15, 2025
a037a23
Replace findReScriptVersion(filePath) with findReScriptVersionForProj…
mediremi May 15, 2025
190696d
Remove unused utils.findPlatformPath
mediremi May 15, 2025
2258d8e
Make server.findRescriptBinary async
mediremi May 15, 2025
628dc75
Remove unused constant
mediremi May 15, 2025
b3b26bf
s/findBinaryAsync/findBinary
mediremi May 15, 2025
40ecf3d
Fix rescript binary package import path
mediremi May 15, 2025
da67038
Move semver dependency from root package.json to server/package.json
mediremi May 18, 2025
d4cc19d
Use semver package for version checks
mediremi May 18, 2025
22bff6d
Update typescript from v4.7.3 to v5.8.3
mediremi May 18, 2025
aa78b00
Add CHANGELOG
mediremi May 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ rescript-tools.exe

_opam/
_build/

*.tsbuildinfo
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

- 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

#### :house: Internal

- 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

## 1.62.0

#### :nail_care: Polish
Expand Down
89 changes: 23 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@
},
"devDependencies": {
"@types/node": "^14.14.41",
"@types/semver": "^7.7.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added semver to make parsing the rescript version easier.

If adding this dependency is fine, then I can also refactor incrementalCompilation.figureOutBscArgs and utils.runAnalysisAfterSanityCheck to use it.

if (parseInt(project.rescriptVersion.split(".")[0] ?? "10") >= 11) {

let shouldUseBuiltinAnalysis =
rescriptVersion?.startsWith("9.") ||
rescriptVersion?.startsWith("10.") ||
rescriptVersion?.startsWith("11.") ||
[
"12.0.0-alpha.1",
"12.0.0-alpha.2",
"12.0.0-alpha.3",
"12.0.0-alpha.4",
].includes(rescriptVersion ?? "");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done the proposed refactoring in this commit: d4cc19d

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 👍

"@types/vscode": "1.68.0",
"esbuild": "^0.20.1",
"semver": "^7.3.7",
"typescript": "^4.7.3"
"typescript": "^5.8.3"
}
}
18 changes: 18 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"chokidar": "^3.5.1",
"semver": "^7.7.2",
"vscode-jsonrpc": "^8.0.1",
"vscode-languageserver": "^8.0.1",
"vscode-languageserver-protocol": "^3.17.1"
Expand Down
30 changes: 15 additions & 15 deletions server/src/codeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ let takeUntil = (array: string[], startsWith: string): string[] => {
return res;
};

export let findCodeActionsInDiagnosticsMessage = ({
export let findCodeActionsInDiagnosticsMessage = async ({
diagnostic,
diagnosticMessage,
file,
range,
addFoundActionsHere: codeActions,
}: findCodeActionsConfig) => {
diagnosticMessage.forEach((line, index, array) => {
for (const [index, line] of diagnosticMessage.entries()) {
// Because of how actions work, there can only be one per diagnostic. So,
// halt whenever a code action has been found.
let codeActionExtractors = [
Expand All @@ -166,8 +166,8 @@ export let findCodeActionsInDiagnosticsMessage = ({
let didFindAction = false;

try {
didFindAction = extractCodeAction({
array,
didFindAction = await extractCodeAction({
array: diagnosticMessage,
codeActions,
diagnostic,
file,
Expand All @@ -183,7 +183,7 @@ export let findCodeActionsInDiagnosticsMessage = ({
break;
}
}
});
}
};

interface codeActionExtractorConfig {
Expand All @@ -196,12 +196,12 @@ interface codeActionExtractorConfig {
codeActions: filesCodeActions;
}

type codeActionExtractor = (config: codeActionExtractorConfig) => boolean;
type codeActionExtractor = (config: codeActionExtractorConfig) => Promise<boolean>;

// This action extracts hints the compiler emits for misspelled identifiers, and
// offers to replace the misspelled name with the correct name suggested by the
// compiler.
let didYouMeanAction: codeActionExtractor = ({
let didYouMeanAction: codeActionExtractor = async ({
codeActions,
diagnostic,
file,
Expand Down Expand Up @@ -245,7 +245,7 @@ let didYouMeanAction: codeActionExtractor = ({
};

// This action offers to wrap patterns that aren't option in Some.
let wrapInSome: codeActionExtractor = ({
let wrapInSome: codeActionExtractor = async ({
codeActions,
diagnostic,
file,
Expand Down Expand Up @@ -425,7 +425,7 @@ let handleUndefinedRecordFieldsAction = ({
// being undefined. We then offers an action that inserts all of the record
// fields, with an `assert false` dummy value. `assert false` is so applying the
// code action actually compiles.
let addUndefinedRecordFieldsV10: codeActionExtractor = ({
let addUndefinedRecordFieldsV10: codeActionExtractor = async ({
array,
codeActions,
diagnostic,
Expand Down Expand Up @@ -459,7 +459,7 @@ let addUndefinedRecordFieldsV10: codeActionExtractor = ({
return false;
};

let addUndefinedRecordFieldsV11: codeActionExtractor = ({
let addUndefinedRecordFieldsV11: codeActionExtractor = async ({
array,
codeActions,
diagnostic,
Expand Down Expand Up @@ -508,7 +508,7 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({

// This action detects suggestions of converting between mismatches in types
// that the compiler tells us about.
let simpleConversion: codeActionExtractor = ({
let simpleConversion: codeActionExtractor = async ({
line,
codeActions,
file,
Expand Down Expand Up @@ -554,7 +554,7 @@ let simpleConversion: codeActionExtractor = ({

// This action will apply a curried function (essentially inserting a dot in the
// correct place).
let applyUncurried: codeActionExtractor = ({
let applyUncurried: codeActionExtractor = async ({
line,
codeActions,
file,
Expand Down Expand Up @@ -608,7 +608,7 @@ let applyUncurried: codeActionExtractor = ({

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

let filePath = fileURLToPath(file);

let newSwitchCode = utils.runAnalysisAfterSanityCheck(filePath, [
let newSwitchCode = await utils.runAnalysisAfterSanityCheck(filePath, [
"codemod",
filePath,
range.start.line,
Expand Down Expand Up @@ -665,7 +665,7 @@ let simpleAddMissingCases: codeActionExtractor = ({
// This detects concrete variables or values put in a position which expects an
// optional of that same type, and offers to wrap the value/variable in
// `Some()`.
let simpleTypeMismatches: codeActionExtractor = ({
let simpleTypeMismatches: codeActionExtractor = async ({
line,
codeActions,
file,
Expand Down
15 changes: 1 addition & 14 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ export let platformDir =
// See https://microsoft.github.io/language-server-protocol/specification Abstract Message
// version is fixed to 2.0
export let jsonrpcVersion = "2.0";
export let platformPath = path.join("rescript", platformDir);
export let nodeModulesPlatformPath = path.join("node_modules", platformPath);
export let bscExeName = "bsc.exe";
export let editorAnalysisName = "rescript-editor-analysis.exe";
export let bscNativeReScriptPartialPath = path.join(
nodeModulesPlatformPath,
bscExeName
);

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

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

// can't use the native bsb/rescript since we might need the watcher -w flag, which is only in the JS wrapper
export let rescriptNodePartialPath = path.join(
nodeModulesBinDir,
rescriptBinName
);

export let bsbLock = ".bsb.lock";
export let bsconfigPartialPath = "bsconfig.json";
export let rescriptJsonPartialPath = "rescript.json";
Expand Down
Loading