File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ let send: (msg: p.Message) => void = (_) => {};
6767
6868let getBinaryDirPath = ( projectRootPath : p . DocumentUri ) =>
6969 extensionConfiguration . binaryPath === null
70- ? path . join ( projectRootPath , c . nodeModulesBinDir )
70+ ? utils . findBinaryFromProjectRoot ( projectRootPath )
7171 : extensionConfiguration . binaryPath ;
7272
7373let findRescriptBinary = ( projectRootPath : p . DocumentUri ) =>
@@ -618,7 +618,8 @@ function format(msg: p.RequestMessage): Array<p.Message> {
618618 // code will always be defined here, even though technically it can be undefined
619619 let code = getOpenedFileContent ( params . textDocument . uri ) ;
620620 let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
621- let bscBinaryPath = projectRootPath === null ? null : findBscBinary ( projectRootPath ) ;
621+ let bscBinaryPath =
622+ projectRootPath === null ? null : findBscBinary ( projectRootPath ) ;
622623 let formattedResult = utils . formatCode ( bscBinaryPath , filePath , code ) ;
623624 if ( formattedResult . kind === "success" ) {
624625 let max = code . length ;
Original file line number Diff line number Diff line change @@ -38,6 +38,22 @@ export let findProjectRootOfFile = (
3838 }
3939} ;
4040
41+ export let findBinaryFromProjectRoot = (
42+ source : p . DocumentUri
43+ ) : null | p . DocumentUri => {
44+ let dir = path . dirname ( source ) ;
45+ let bscNativeReScriptPath = path . join ( dir , c . nodeModulesBinDir ) ;
46+
47+ if ( fs . existsSync ( bscNativeReScriptPath ) ) {
48+ return bscNativeReScriptPath ;
49+ } else if ( dir === source ) {
50+ // reached the top
51+ return null ;
52+ } else {
53+ return findBinaryFromProjectRoot ( dir ) ;
54+ }
55+ } ;
56+
4157export let findBinary = (
4258 binaryDirPath : p . DocumentUri | null ,
4359 binaryName : string
You can’t perform that action at this time.
0 commit comments