@@ -5,8 +5,6 @@ import * as path from "path";
5
5
import * as t from "vscode-languageserver-types" ;
6
6
import fs from "fs" ;
7
7
import * as os from "os" ;
8
- import { fileURLToPath } from "url" ;
9
- import { RequestMessage } from "vscode-languageserver-protocol" ;
10
8
11
9
let tempFilePrefix = "rescript_format_file_" + process . pid + "_" ;
12
10
let tempFileId = 0 ;
@@ -45,21 +43,25 @@ export let findProjectRootOfFile = (
45
43
// Also, if someone's ever formatting a regular project setup's dependency
46
44
// (which is weird but whatever), they'll at least find an upward bs-platform
47
45
// from the dependent.
48
- export let findBscExeDirOfFile = (
46
+ export let findBscNativeOfFile = (
49
47
source : p . DocumentUri
50
48
) : null | p . DocumentUri => {
51
49
let dir = path . dirname ( source ) ;
52
- let bscExePath1 = path . join ( dir , c . bscExeReScriptPartialPath ) ;
53
- let bscExePath2 = path . join ( dir , c . bscExePartialPath ) ;
54
- if ( fs . existsSync ( bscExePath1 ) || fs . existsSync ( bscExePath2 ) ) {
55
- return dir ;
50
+ // The rescript package's rescript command is a JS wrapper. `rescript format`
51
+ // also invokes another JS wrapper. _That_ JS wrapper ultimately calls the
52
+ // (unexposed) bsc -format anyway.
53
+ let bscNativeReScriptPath = path . join ( dir , c . bscNativeReScriptPartialPath ) ;
54
+ let bscNativePath = path . join ( dir , c . bscNativePartialPath ) ;
55
+
56
+ if ( fs . existsSync ( bscNativeReScriptPath ) ) {
57
+ return bscNativeReScriptPath
58
+ } else if ( fs . existsSync ( bscNativePath ) ) {
59
+ return bscNativePath
60
+ } else if ( dir === source ) {
61
+ // reached the top
62
+ return null
56
63
} else {
57
- if ( dir === source ) {
58
- // reached the top
59
- return null ;
60
- } else {
61
- return findBscExeDirOfFile ( dir ) ;
62
- }
64
+ return findBscNativeOfFile ( dir ) ;
63
65
}
64
66
} ;
65
67
@@ -72,9 +74,9 @@ type execResult =
72
74
kind : "error" ;
73
75
error : string ;
74
76
} ;
75
- export let formatUsingValidBscExePath = (
77
+ export let formatUsingValidBscNativePath = (
76
78
code : string ,
77
- bscExePath : p . DocumentUri ,
79
+ bscNativePath : p . DocumentUri ,
78
80
isInterface : boolean
79
81
) : execResult => {
80
82
let extension = isInterface ? c . resiExt : c . resExt ;
@@ -83,7 +85,7 @@ export let formatUsingValidBscExePath = (
83
85
encoding : "utf-8" ,
84
86
} ) ;
85
87
try {
86
- let result = childProcess . execFileSync ( bscExePath , [
88
+ let result = childProcess . execFileSync ( bscNativePath , [
87
89
"-color" ,
88
90
"never" ,
89
91
"-format" ,
0 commit comments