@@ -70,6 +70,19 @@ export let findBscNativeOfFile = (
70
70
}
71
71
} ;
72
72
73
+ let findBscBinFromConfig = (
74
+ pathToBinFromConfig : p . DocumentUri | null
75
+ ) : null | p . DocumentUri => {
76
+ if ( pathToBinFromConfig === null ) {
77
+ return null ;
78
+ }
79
+ let bscPath = path . join ( pathToBinFromConfig , c . bscBinName ) ;
80
+ if ( fs . existsSync ( bscPath ) ) {
81
+ return bscPath ;
82
+ }
83
+ return null ;
84
+ } ;
85
+
73
86
// TODO: this doesn't handle file:/// scheme
74
87
export let findNodeBuildOfProjectRoot = (
75
88
projectRootPath : p . DocumentUri
@@ -94,21 +107,30 @@ type execResult =
94
107
kind : "error" ;
95
108
error : string ;
96
109
} ;
97
- export let formatCode = ( filePath : string , code : string ) : execResult => {
110
+
111
+ export let formatCode = (
112
+ pathToBinFromConfig : p . DocumentUri | null ,
113
+ filePath : string ,
114
+ code : string
115
+ ) : execResult => {
98
116
let extension = path . extname ( filePath ) ;
99
117
let formatTempFileFullPath = createFileInTempDir ( extension ) ;
100
118
fs . writeFileSync ( formatTempFileFullPath , code , {
101
119
encoding : "utf-8" ,
102
120
} ) ;
103
121
try {
122
+ // Try to find the bsc bin from the binaryPath setting from the configuration.
123
+ let bscPath = findBscBinFromConfig ( pathToBinFromConfig ) ;
124
+
104
125
// See comment on findBscNativeDirOfFile for why we need
105
126
// to recursively search for bsc.exe upward
106
- let bscNativePath = findBscNativeOfFile ( filePath ) ;
127
+ bscPath = bscPath == null ? findBscNativeOfFile ( filePath ) : bscPath ;
107
128
108
- // Default to using the project formatter. If not, use the one we ship with
109
- // the analysis binary in the extension itself.
110
- if ( bscNativePath != null ) {
111
- let result = childProcess . execFileSync ( bscNativePath , [
129
+ // Default to using the formatter from the binaryPath setting from the configuration
130
+ // or the project formatter.
131
+ // If not, use the one we ship with the analysis binary in the extension itself.
132
+ if ( bscPath != null ) {
133
+ let result = childProcess . execFileSync ( bscPath , [
112
134
"-color" ,
113
135
"never" ,
114
136
"-format" ,
0 commit comments