Skip to content

Commit c443d4c

Browse files
committed
link up new prepareRename command
1 parent a6d57a4 commit c443d4c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

server/src/server.ts

Lines changed: 33 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,38 @@ 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+
// Gate analysis prepareRename behind >= 12.0.0-beta.9
693+
// This needs to be adjusted to the actual version prepareRename is released in
694+
let projectRootPath = utils.findProjectRootOfFile(filePath);
695+
let rescriptVersion =
696+
(projectRootPath && projectsFiles.get(projectRootPath)?.rescriptVersion) ||
697+
(await utils.findReScriptVersionForProjectRoot(projectRootPath ?? null));
698+
699+
let shouldUsePrepareRenameCommand = false;
700+
if (rescriptVersion != null) {
701+
shouldUsePrepareRenameCommand =
702+
semver.valid(rescriptVersion) != null &&
703+
semver.satisfies(rescriptVersion, ">=12.0.0-beta.9", {
704+
includePrerelease: true,
705+
});
706+
}
707+
708+
if (shouldUsePrepareRenameCommand) {
709+
let analysisResult = await utils.runAnalysisAfterSanityCheck(filePath, [
710+
"prepareRename",
711+
filePath,
712+
params.position.line,
713+
params.position.character,
714+
]);
715+
716+
return {
717+
jsonrpc: c.jsonrpcVersion,
718+
id: msg.id,
719+
result: analysisResult as p.PrepareRenameResult,
720+
};
721+
}
722+
690723
let locations: null | p.Location[] = await utils.getReferencesForPosition(
691724
filePath,
692725
params.position,

0 commit comments

Comments
 (0)