@@ -5,8 +5,6 @@ import * as path from "path";
55import * as t from "vscode-languageserver-types" ;
66import fs from "fs" ;
77import * as os from "os" ;
8- import { fileURLToPath } from "url" ;
9- import { RequestMessage } from "vscode-languageserver-protocol" ;
108
119let tempFilePrefix = "rescript_format_file_" + process . pid + "_" ;
1210let tempFileId = 0 ;
@@ -45,21 +43,25 @@ export let findProjectRootOfFile = (
4543// Also, if someone's ever formatting a regular project setup's dependency
4644// (which is weird but whatever), they'll at least find an upward bs-platform
4745// from the dependent.
48- export let findBscExeDirOfFile = (
46+ export let findBscNativeOfFile = (
4947 source : p . DocumentUri
5048) : null | p . DocumentUri => {
5149 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
5663 } else {
57- if ( dir === source ) {
58- // reached the top
59- return null ;
60- } else {
61- return findBscExeDirOfFile ( dir ) ;
62- }
64+ return findBscNativeOfFile ( dir ) ;
6365 }
6466} ;
6567
@@ -72,9 +74,9 @@ type execResult =
7274 kind : "error" ;
7375 error : string ;
7476 } ;
75- export let formatUsingValidBscExePath = (
77+ export let formatUsingValidBscNativePath = (
7678 code : string ,
77- bscExePath : p . DocumentUri ,
79+ bscNativePath : p . DocumentUri ,
7880 isInterface : boolean
7981) : execResult => {
8082 let extension = isInterface ? c . resiExt : c . resExt ;
@@ -83,7 +85,7 @@ export let formatUsingValidBscExePath = (
8385 encoding : "utf-8" ,
8486 } ) ;
8587 try {
86- let result = childProcess . execFileSync ( bscExePath , [
88+ let result = childProcess . execFileSync ( bscNativePath , [
8789 "-color" ,
8890 "never" ,
8991 "-format" ,
0 commit comments