@@ -90,34 +90,32 @@ let findRescriptBinary = (projectRootPath: p.DocumentUri | null) =>
90
90
? utils . findFilePathFromProjectRoot ( projectRootPath , path . join ( c . nodeModulesBinDir , c . rescriptBinName ) )
91
91
: utils . findBinary ( extensionConfiguration . binaryPath , c . rescriptBinName ) ;
92
92
93
- let findBscBinary = ( projectRootPath : p . DocumentUri ) => {
94
- let rescriptBinaryPath = findRescriptBinary ( projectRootPath ) ;
95
- if ( rescriptBinaryPath !== null ) {
96
- let rescriptDirPath = path . join (
97
- path . dirname ( rescriptBinaryPath ) ,
98
- ".." ,
99
- "rescript"
100
- ) ;
93
+ let findPlatformPath = ( projectRootPath : p . DocumentUri | null ) => {
94
+ if ( extensionConfiguration . platformPath != null ) {
95
+ return extensionConfiguration . platformPath ;
96
+ }
101
97
102
- let bscBinaryPath = path . join ( rescriptDirPath , c . platformDir , c . bscExeName ) ;
98
+ let rescriptDir = utils . findFilePathFromProjectRoot ( projectRootPath , path . join ( "node_modules" , "rescript" ) ) ;
99
+ if ( rescriptDir == null ) {
100
+ return null ;
101
+ }
103
102
104
- // Workaround for darwinarm64 which has no folder yet in ReScript <= 9.1.4
105
- if (
106
- process . platform == "darwin" &&
107
- process . arch == "arm64" &&
108
- ! fs . existsSync ( bscBinaryPath )
109
- ) {
110
- bscBinaryPath = path . join (
111
- rescriptDirPath ,
112
- process . platform ,
113
- c . bscExeName
114
- ) ;
115
- }
103
+ let platformPath = path . join ( rescriptDir , c . platformDir )
116
104
117
- return bscBinaryPath ;
105
+ // Workaround for darwinarm64 which has no folder yet in ReScript <= 9.1.4
106
+ if (
107
+ process . platform == "darwin" &&
108
+ process . arch == "arm64" &&
109
+ ! fs . existsSync ( platformPath )
110
+ ) {
111
+ platformPath = path . join ( rescriptDir , process . platform ) ;
118
112
}
119
- return null ;
120
- } ;
113
+
114
+ return platformPath ;
115
+ }
116
+
117
+ let findBscExeBinary = ( projectRootPath : p . DocumentUri | null ) =>
118
+ utils . findBinary ( findPlatformPath ( projectRootPath ) , c . bscExeName )
121
119
122
120
interface CreateInterfaceRequestParams {
123
121
uri : string ;
@@ -718,12 +716,12 @@ function format(msg: p.RequestMessage): Array<p.Message> {
718
716
} else {
719
717
// code will always be defined here, even though technically it can be undefined
720
718
let code = getOpenedFileContent ( params . textDocument . uri ) ;
719
+
721
720
let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
722
- let bscBinaryPath =
723
- projectRootPath === null ? null : findBscBinary ( projectRootPath ) ;
721
+ let bscExeBinaryPath = findBscExeBinary ( projectRootPath ) ;
724
722
725
723
let formattedResult = utils . formatCode (
726
- bscBinaryPath ,
724
+ bscExeBinaryPath ,
727
725
filePath ,
728
726
code ,
729
727
extensionConfiguration . allowBuiltInFormatter
0 commit comments