@@ -3,6 +3,7 @@ import * as p from "vscode-languageserver-protocol";
3
3
import * as v from "vscode-languageserver" ;
4
4
import * as rpc from "vscode-jsonrpc/node" ;
5
5
import * as path from "path" ;
6
+ import semver from "semver" ;
6
7
import fs from "fs" ;
7
8
import {
8
9
DidChangeWatchedFilesNotification ,
@@ -687,6 +688,38 @@ async function prepareRename(
687
688
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
688
689
let params = msg . params as p . PrepareRenameParams ;
689
690
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
+
690
723
let locations : null | p . Location [ ] = await utils . getReferencesForPosition (
691
724
filePath ,
692
725
params . position ,
0 commit comments