@@ -112,7 +112,7 @@ export let runBsbWatcherUsingValidBsbPath = (
112
112
} else {
113
113
return childProcess . execFile ( bsbPath , [ "-w" ] , {
114
114
cwd : projectRootPath ,
115
- } )
115
+ } ) ;
116
116
}
117
117
// try {
118
118
// let result = childProcess.execFileSync(bsbPath, [], { stdio: 'pipe', cwd: projectRootPath })
@@ -159,38 +159,8 @@ export let parseDiagnosticLocation = (location: string): Range => {
159
159
}
160
160
} ;
161
161
162
- let findLocationSeparator = ( fileAndLocation : string ) => {
163
- // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.."
164
- if ( process . platform === "win32" ) {
165
- return fileAndLocation . indexOf ( ":" , 2 ) ;
166
- } else {
167
- return fileAndLocation . indexOf ( ":" ) ;
168
- }
169
- } ;
170
-
171
- let separateFileAndLocation = ( fileAndLocation : string ) : [ string , string ] => {
172
- let locationSeparator = findLocationSeparator ( fileAndLocation ) ;
173
- let file = fileAndLocation . slice ( 0 , locationSeparator ) ;
174
- let location = fileAndLocation . slice ( locationSeparator + 1 ) ;
175
-
176
- if ( process . platform === "win32" ) {
177
- return [ `file:\\\\\\${ file } ` , location ] ;
178
- } else {
179
- return [ file , location ]
180
- }
181
- } ;
182
-
183
- type filesDiagnostics = {
184
- [ key : string ] : p . Diagnostic [ ] ;
185
- } ;
186
- type parsedCompilerLogResult = {
187
- done : boolean ;
188
- result : filesDiagnostics ;
189
- } ;
190
- export let parseCompilerLogOutput = (
191
- content : string
192
- ) : parsedCompilerLogResult => {
193
- /* example .compiler.log file content that we're gonna parse:
162
+ // Logic for parsing .compiler.log
163
+ /* example .compiler.log content:
194
164
195
165
#Start(1600519680823)
196
166
@@ -228,8 +198,36 @@ export let parseCompilerLogOutput = (
228
198
Somewhere wanted: int
229
199
230
200
#Done(1600519680836)
231
- */
201
+ */
202
+
203
+ // parser helper
204
+ let splitFileAndLocation = ( fileAndLocation : string ) => {
205
+ let isWindows = process . platform === "win32" ;
206
+ // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.."
207
+ let locationSeparator = isWindows
208
+ ? fileAndLocation . indexOf ( ":" , 2 )
209
+ : fileAndLocation . indexOf ( ":" ) ;
210
+
211
+ let file = fileAndLocation . slice ( 0 , locationSeparator ) ;
212
+ let location = fileAndLocation . slice ( locationSeparator + 1 ) ;
213
+
214
+ return {
215
+ file : isWindows ? `file:\\\\\\${ file } ` : file ,
216
+ location,
217
+ } ;
218
+ } ;
232
219
220
+ // main parsing logic
221
+ type filesDiagnostics = {
222
+ [ key : string ] : p . Diagnostic [ ] ;
223
+ } ;
224
+ type parsedCompilerLogResult = {
225
+ done : boolean ;
226
+ result : filesDiagnostics ;
227
+ } ;
228
+ export let parseCompilerLogOutput = (
229
+ content : string
230
+ ) : parsedCompilerLogResult => {
233
231
type parsedDiagnostic = {
234
232
code : number | undefined ;
235
233
severity : t . DiagnosticSeverity ;
@@ -300,8 +298,7 @@ export let parseCompilerLogOutput = (
300
298
let result : filesDiagnostics = { } ;
301
299
parsedDiagnostics . forEach ( ( parsedDiagnostic ) => {
302
300
let [ fileAndLocationLine , ...diagnosticMessage ] = parsedDiagnostic . content ;
303
-
304
- let [ file , location ] = separateFileAndLocation ( fileAndLocationLine . slice ( 2 ) ) ;
301
+ let { file, location } = splitFileAndLocation ( fileAndLocationLine . slice ( 2 ) ) ;
305
302
306
303
if ( result [ file ] == null ) {
307
304
result [ file ] = [ ] ;
0 commit comments