@@ -653,23 +653,37 @@ async function inlayHint(msg: p.RequestMessage) {
653653 const filePath = utils . uriToNormalizedPath (
654654 params . textDocument . uri as utils . FileURI ,
655655 ) ;
656- let code = getOpenedFileContent ( params . textDocument . uri as utils . FileURI ) ;
657- let extension = path . extname ( params . textDocument . uri ) ;
658- let tmpname = utils . createFileInTempDir ( extension ) ;
659- fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
660- const response = await utils . runAnalysisCommand (
656+ let args : Array < any > = [
657+ "inlayHint" ,
661658 filePath ,
662- [
663- "inlayHint" ,
664- filePath ,
665- params . range . start . line ,
666- params . range . end . line ,
667- config . extensionConfiguration . inlayHints ?. maxLength ,
668- tmpname ,
669- ] ,
670- msg ,
671- ) ;
672- fs . unlink ( tmpname , ( ) => null ) ;
659+ params . range . start . line ,
660+ params . range . end . line ,
661+ config . extensionConfiguration . inlayHints ?. maxLength ,
662+ ] ;
663+ let tmpname : string | null = null ;
664+ let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
665+ let rescriptVersion = projectRootPath
666+ ? projectsFiles . get ( projectRootPath ) ?. rescriptVersion
667+ : null ;
668+ let supportsCurrentFile =
669+ rescriptVersion != null &&
670+ semver . valid ( rescriptVersion ) != null &&
671+ semver . gte ( rescriptVersion , "12.0.0-alpha.5" ) ;
672+ // The currentFile argument (passing unsaved buffer content via a temp file)
673+ // is only supported by the analysis binary that ships with the compiler
674+ // starting from 12.0.0-alpha.5. Older versions don't recognize the extra
675+ // argument and would fail to match the CLI pattern.
676+ if ( supportsCurrentFile ) {
677+ let code = getOpenedFileContent ( params . textDocument . uri as utils . FileURI ) ;
678+ let extension = path . extname ( params . textDocument . uri ) ;
679+ tmpname = utils . createFileInTempDir ( extension ) ;
680+ fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
681+ args . push ( tmpname ) ;
682+ }
683+ const response = await utils . runAnalysisCommand ( filePath , args , msg ) ;
684+ if ( tmpname != null ) {
685+ fs . unlink ( tmpname , ( ) => null ) ;
686+ }
673687 return response ;
674688}
675689
0 commit comments