Skip to content

Commit 3d9a6d9

Browse files
authored
Link up new prepareRename command (#1124)
* link up new prepareRename command * adjust * changelog
1 parent 0f4acf9 commit 3d9a6d9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#### :house: Internal
2525

2626
- Find `@rescript/runtime` for Rewatch compiler-args call. https://github.com/rescript-lang/rescript-vscode/pull/1125
27+
- 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
2728

2829
## 1.64.0
2930

server/src/server.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as p from "vscode-languageserver-protocol";
33
import * as v from "vscode-languageserver";
44
import * as rpc from "vscode-jsonrpc/node";
55
import * as path from "path";
6+
import semver from "semver";
67
import fs from "fs";
78
import {
89
DidChangeWatchedFilesNotification,
@@ -687,6 +688,37 @@ async function prepareRename(
687688
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
688689
let params = msg.params as p.PrepareRenameParams;
689690
let filePath = fileURLToPath(params.textDocument.uri);
691+
692+
// `prepareRename` was introduced in 12.0.0-beta.10
693+
let projectRootPath = utils.findProjectRootOfFile(filePath);
694+
let rescriptVersion =
695+
(projectRootPath && projectsFiles.get(projectRootPath)?.rescriptVersion) ||
696+
(await utils.findReScriptVersionForProjectRoot(projectRootPath ?? null));
697+
698+
let shouldUsePrepareRenameCommand = false;
699+
if (rescriptVersion != null) {
700+
shouldUsePrepareRenameCommand =
701+
semver.valid(rescriptVersion) != null &&
702+
semver.satisfies(rescriptVersion, ">=12.0.0-beta.10", {
703+
includePrerelease: true,
704+
});
705+
}
706+
707+
if (shouldUsePrepareRenameCommand) {
708+
let analysisResult = await utils.runAnalysisAfterSanityCheck(filePath, [
709+
"prepareRename",
710+
filePath,
711+
params.position.line,
712+
params.position.character,
713+
]);
714+
715+
return {
716+
jsonrpc: c.jsonrpcVersion,
717+
id: msg.id,
718+
result: analysisResult as p.PrepareRenameResult,
719+
};
720+
}
721+
690722
let locations: null | p.Location[] = await utils.getReferencesForPosition(
691723
filePath,
692724
params.position,

0 commit comments

Comments
 (0)