diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e095205f..543e509e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ #### :bug: Bug fix +- Fix Code Analyzer binary lookup for ReScript v12+ projects. - Take namespace into account for incremental cleanup. https://github.com/rescript-lang/rescript-vscode/pull/1164 - Potential race condition in incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/1167 - Fix extension crash triggered by incremental compilation. https://github.com/rescript-lang/rescript-vscode/pull/1169 diff --git a/client/src/commands/code_analysis.ts b/client/src/commands/code_analysis.ts index 61bb4f156..559f89c67 100644 --- a/client/src/commands/code_analysis.ts +++ b/client/src/commands/code_analysis.ts @@ -1,4 +1,5 @@ import * as cp from "child_process"; +import * as fs from "fs"; import * as path from "path"; import { window, @@ -216,12 +217,27 @@ export const runCodeAnalysisWithReanalyze = ( currentDocument.uri.fsPath, ); - // This little weird lookup is because in the legacy setup reanalyze needs to be - // run from the analysis binary, whereas in the new setup it's run from the tools - // binary. - let binaryPath = - getBinaryPath("rescript-tools.exe", projectRootPath) ?? - getBinaryPath("rescript-editor-analysis.exe"); + // Try v12+ path first: @rescript/{platform}-{arch}/bin/rescript-tools.exe + // Then fall back to legacy paths via getBinaryPath + let binaryPath: string | null = null; + if (projectRootPath != null) { + const v12Path = path.join( + projectRootPath, + "node_modules", + "@rescript", + `${process.platform}-${process.arch}`, + "bin", + "rescript-tools.exe", + ); + if (fs.existsSync(v12Path)) { + binaryPath = v12Path; + } + } + if (binaryPath == null) { + binaryPath = + getBinaryPath("rescript-tools.exe", projectRootPath) ?? + getBinaryPath("rescript-editor-analysis.exe", projectRootPath); + } if (binaryPath === null) { window.showErrorMessage("Binary executable not found.");