Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#### :house: Internal

- Find `@rescript/runtime` for Rewatch compiler-args call. https://github.com/rescript-lang/rescript-vscode/pull/1125
- Use `prepareRename` command (when a new enough ReScript version is used) to speed up the `rename` command. https://github.com/rescript-lang/rescript-vscode/pull/1124

## 1.64.0

Expand Down
32 changes: 32 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as p from "vscode-languageserver-protocol";
import * as v from "vscode-languageserver";
import * as rpc from "vscode-jsonrpc/node";
import * as path from "path";
import semver from "semver";
import fs from "fs";
import {
DidChangeWatchedFilesNotification,
Expand Down Expand Up @@ -687,6 +688,37 @@ async function prepareRename(
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
let params = msg.params as p.PrepareRenameParams;
let filePath = fileURLToPath(params.textDocument.uri);

// `prepareRename` was introduced in 12.0.0-beta.10
let projectRootPath = utils.findProjectRootOfFile(filePath);
let rescriptVersion =
(projectRootPath && projectsFiles.get(projectRootPath)?.rescriptVersion) ||
(await utils.findReScriptVersionForProjectRoot(projectRootPath ?? null));

let shouldUsePrepareRenameCommand = false;
if (rescriptVersion != null) {
shouldUsePrepareRenameCommand =
semver.valid(rescriptVersion) != null &&
semver.satisfies(rescriptVersion, ">=12.0.0-beta.10", {
includePrerelease: true,
});
}

if (shouldUsePrepareRenameCommand) {
let analysisResult = await utils.runAnalysisAfterSanityCheck(filePath, [
"prepareRename",
filePath,
params.position.line,
params.position.character,
]);

return {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result: analysisResult as p.PrepareRenameResult,
};
}

let locations: null | p.Location[] = await utils.getReferencesForPosition(
filePath,
params.position,
Expand Down
Loading