Skip to content

Commit 27a4ed5

Browse files
committed
Fixes #77
1 parent adf7486 commit 27a4ed5

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.0.x (unreleased)
2+
- Fix diagnostics when location's not found (advice: use fewer ppxes!). See [#77](https://github.com/rescript-lang/rescript-vscode/issues/77).
3+
14
## 1.0.5
25

36
Features:

server/src/utils.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,14 @@ export let runBsbWatcherUsingValidBsbPath = (
168168
#Done(1600519680836)
169169
*/
170170

171-
// parser helper
171+
// parser helpers
172+
let normalizeFileForWindows = (file: string) => {
173+
return process.platform === "win32" ? `file:\\\\\\${file}` : file;
174+
};
172175
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
174177
/* The file + location format can be:
178+
a/b.res <- fallback, no location available (usually due to bad ppx...)
175179
a/b.res:10:20
176180
a/b.res:10:20-21 <- last number here is the end char of line 10
177181
a/b.res:10:20-30:11
@@ -184,7 +188,20 @@ let parseFileAndRange = (fileAndRange: string) => {
184188
^^^ end line or chararacter
185189
^^^ end character
186190
*/
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+
188205
let [
189206
_source,
190207
file,
@@ -194,8 +211,7 @@ let parseFileAndRange = (fileAndRange: string) => {
194211
endLineOrChar,
195212
_colonPlusEndCharOrNothing,
196213
endCharOrNothing,
197-
] = fileAndRange.trim().match(regex)!;
198-
// for the trimming, see https://github.com/rescript-lang/rescript-vscode/pull/71#issuecomment-769160576
214+
] = match;
199215

200216
// language-server position is 0-based. Ours is 1-based. Convert
201217
// also, our end character is inclusive. Language-server's is exclusive
@@ -223,7 +239,7 @@ let parseFileAndRange = (fileAndRange: string) => {
223239
};
224240
}
225241
return {
226-
file: process.platform === "win32" ? `file:\\\\\\${file}` : file,
242+
file: normalizeFileForWindows(file),
227243
range,
228244
};
229245
};

0 commit comments

Comments
 (0)