File tree 2 files changed +19
-2
lines changed
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 = (_) => {};
67
67
68
68
let getBinaryDirPath = ( projectRootPath : p . DocumentUri ) =>
69
69
extensionConfiguration . binaryPath === null
70
- ? path . join ( projectRootPath , c . nodeModulesBinDir )
70
+ ? utils . findBinaryFromProjectRoot ( projectRootPath )
71
71
: extensionConfiguration . binaryPath ;
72
72
73
73
let findRescriptBinary = ( projectRootPath : p . DocumentUri ) =>
@@ -618,7 +618,8 @@ function format(msg: p.RequestMessage): Array<p.Message> {
618
618
// code will always be defined here, even though technically it can be undefined
619
619
let code = getOpenedFileContent ( params . textDocument . uri ) ;
620
620
let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
621
- let bscBinaryPath = projectRootPath === null ? null : findBscBinary ( projectRootPath ) ;
621
+ let bscBinaryPath =
622
+ projectRootPath === null ? null : findBscBinary ( projectRootPath ) ;
622
623
let formattedResult = utils . formatCode ( bscBinaryPath , filePath , code ) ;
623
624
if ( formattedResult . kind === "success" ) {
624
625
let max = code . length ;
Original file line number Diff line number Diff line change @@ -38,6 +38,22 @@ export let findProjectRootOfFile = (
38
38
}
39
39
} ;
40
40
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
+
41
57
export let findBinary = (
42
58
binaryDirPath : p . DocumentUri | null ,
43
59
binaryName : string
You can’t perform that action at this time.
0 commit comments