@@ -168,10 +168,14 @@ export let runBsbWatcherUsingValidBsbPath = (
168
168
#Done(1600519680836)
169
169
*/
170
170
171
- // parser helper
171
+ // parser helpers
172
+ let normalizeFileForWindows = ( file : string ) => {
173
+ return process . platform === "win32" ? `file:\\\\\\${ file } ` : file ;
174
+ } ;
172
175
let parseFileAndRange = ( fileAndRange : string ) => {
173
- // https://github.com/rescript-lang/rescript-compiler/blob/0a3f4bb32ca81e89cefd5a912b8795878836f883/jscomp/super_errors/super_location.ml#L19 -L25
176
+ // https://github.com/rescript-lang/rescript-compiler/blob/0a3f4bb32ca81e89cefd5a912b8795878836f883/jscomp/super_errors/super_location.ml#L15 -L25
174
177
/* The file + location format can be:
178
+ a/b.res <- fallback, no location available (usually due to bad ppx...)
175
179
a/b.res:10:20
176
180
a/b.res:10:20-21 <- last number here is the end char of line 10
177
181
a/b.res:10:20-30:11
@@ -184,7 +188,20 @@ let parseFileAndRange = (fileAndRange: string) => {
184
188
^^^ end line or chararacter
185
189
^^^ end character
186
190
*/
187
- // it's not possible that this regex fails. If it does, something's wrong in the caller
191
+ // for the trimming, see https://github.com/rescript-lang/rescript-vscode/pull/71#issuecomment-769160576
192
+ let trimmedFileAndRange = fileAndRange . trim ( ) ;
193
+ let match = trimmedFileAndRange . match ( regex ) ;
194
+ if ( match === null ) {
195
+ // no location! Though LSP insist that we provide at least a dummy location
196
+ return {
197
+ file : normalizeFileForWindows ( trimmedFileAndRange ) ,
198
+ range : {
199
+ start : { line : 0 , character : 0 } ,
200
+ end : { line : 0 , character : 0 } ,
201
+ } ,
202
+ } ;
203
+ }
204
+
188
205
let [
189
206
_source ,
190
207
file ,
@@ -194,8 +211,7 @@ let parseFileAndRange = (fileAndRange: string) => {
194
211
endLineOrChar ,
195
212
_colonPlusEndCharOrNothing ,
196
213
endCharOrNothing ,
197
- ] = fileAndRange . trim ( ) . match ( regex ) ! ;
198
- // for the trimming, see https://github.com/rescript-lang/rescript-vscode/pull/71#issuecomment-769160576
214
+ ] = match ;
199
215
200
216
// language-server position is 0-based. Ours is 1-based. Convert
201
217
// also, our end character is inclusive. Language-server's is exclusive
@@ -223,7 +239,7 @@ let parseFileAndRange = (fileAndRange: string) => {
223
239
} ;
224
240
}
225
241
return {
226
- file : process . platform === "win32" ? ` file:\\\\\\ ${ file } ` : file ,
242
+ file : normalizeFileForWindows ( file ) ,
227
243
range,
228
244
} ;
229
245
} ;
0 commit comments