@@ -3,6 +3,7 @@ import * as p from "vscode-languageserver-protocol";
33import * as v from "vscode-languageserver" ;
44import * as rpc from "vscode-jsonrpc/node" ;
55import * as path from "path" ;
6+ import semver from "semver" ;
67import fs from "fs" ;
78import {
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