Skip to content

Commit 36f9fb7

Browse files
committed
[ fix ] Handle different format of output from Agda-2.8.0
1 parent 4c16f71 commit 36f9fb7

File tree

10 files changed

+95
-53
lines changed

10 files changed

+95
-53
lines changed

lib/js/src/Agda.bs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/src/View/Common.bs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/src/View/Component/RichText.bs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/test/tests/Test__ShowGoals.bs.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/js/test/tests/Test__WhyInScope.bs.js

Lines changed: 25 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Agda.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ module Output = {
118118
})
119119
, ...))
120120
let parse = raw => {
121-
let locRe = %re("/\[ at (\S+\:(?:\d+\,\d+\-\d+\,\d+|\d+\,\d+\-\d+|\d+\,\d+)) \]$/")
121+
let locRe = %re("/\[ at (\S+\:(?:\d+[,\.]\d+\-\d+[,\.]\d+|\d+[,\.]\d+\-\d+|\d+[,\.]\d+)) \]$/")
122122
let hasLocation = RegExp.test(locRe, raw)
123123
if hasLocation {
124124
parseOutputWithLocation(raw)

src/View/Common.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ module AgdaRange = {
8888
| Range(option<string>, array<AgdaInterval.t>)
8989

9090
let parse = %re(
91-
// Regex updated to v10.1.4
92-
// There are 3 types of range:
93-
// type 1: filepath:line,col-line,col
94-
// type 2: filepath:line,col-col
95-
// type 3: filepath:line,col
91+
// Regex updated for Agda 2.8.0 compatibility
92+
// There are 3 types of range, each supporting both comma and dot separators:
93+
// type 1: filepath:line,col-line,col OR filepath:line.col-line.col
94+
// type 2: filepath:line,col-col OR filepath:line.col-col
95+
// type 3: filepath:line,col OR filepath:line.col
9696

97-
/* filepath | line,col-line,col | line,col-col | line,col | */
98-
"/^(\S+)\:(?:(\d+)\,(\d+)\-(\d+)\,(\d+)|(\d+)\,(\d+)\-(\d+)|(\d+)\,(\d+))$/"
97+
/* filepath | line[,.]col-line[,.]col | line[,.]col-col | line[,.]col | */
98+
"/^(\S+)\:(?:(\d+)[,\.](\d+)\-(\d+)[,\.](\d+)|(\d+)[,\.](\d+)\-(\d+)|(\d+)[,\.](\d+))$/"
9999
)->(Emacs__Parser.captures(captured => {
100100
open Option
101101
let flatten = xs => xs->flatMap(x => x)

src/View/Component/RichText.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ module Module = {
172172
// tokens captured by the regex will be placed at odd indices
173173
// and the rest will be placed at even indices
174174
// 3 kinds of tokens are captured as AgdaRange:
175-
// 1. filepath:line,column-line,column
176-
// 2. filepath:line,column-column
177-
// 3. filepath:line,column
175+
// 1. filepath:line,column-line,column OR filepath:line.column-line.column
176+
// 2. filepath:line,column-column OR filepath:line.column-column
177+
// 3. filepath:line,column OR filepath:line.column
178178
raw
179-
->String.splitByRegExp(%re("/([^\(\)\s]+\:(?:\d+\,\d+\-\d+\,\d+|\d+\,\d+\-\d+|\d+\,\d+))/"))
179+
->String.splitByRegExp(%re("/([^\(\)\s]+\:(?:\d+[,\.]\d+\-\d+[,\.]\d+|\d+[,\.]\d+\-\d+|\d+[,\.]\d+))/"))
180180
->Array.filterMap(x => x)
181181
->Array.mapWithIndex((token, i) =>
182182
switch mod(i, 2) {

test/tests/Test__ShowGoals.res

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ let run = normalization => {
2020

2121
switch ctx.state.agdaVersion {
2222
| Some(version) =>
23-
let expectedAllGoalsWarningsBody = if Util.Version.gte(version, "2.7.0") {
24-
// Agda 2.7.0+ uses singular "Error" and no trailing newline
23+
let expectedAllGoalsWarningsBody = if Util.Version.gte(version, "2.8.0") {
24+
// Agda 2.8.0+ uses dot format for positions and includes error codes
25+
`?0 : ℕ\n?1 : ℕ\n?2 : ℕ\n?3 : _11\nSort _10 [ at ${filepath}:11.19-31 ]\n_11 : _10 [ at ${filepath}:11.19-31 ]\n_14 : ℕ [ at ${filepath}:11.19-31 ]\n\n———— Error —————————————————————————————————————————————————\nerror: [UnsolvedConstraints]\nUnsolved constraints`
26+
} else if Util.Version.gte(version, "2.7.0") {
27+
// Agda 2.7.0+ uses comma format and singular "Error" and no trailing newline
2528
`?0 : ℕ\n?1 : ℕ\n?2 : ℕ\n?3 : _11\nSort _10 [ at ${filepath}:11,19-31 ]\n_11 : _10 [ at ${filepath}:11,19-31 ]\n_14 : ℕ [ at ${filepath}:11,19-31 ]\n\n———— Error —————————————————————————————————————————————————\nUnsolved constraints`
2629
} else {
27-
// Agda < 2.7.0 uses plural "Errors" and has trailing newline
30+
// Agda < 2.7.0 uses comma format and plural "Errors" and has trailing newline
2831
`?0 : ℕ\n?1 : ℕ\n?2 : ℕ\n?3 : _11\nSort _10 [ at ${filepath}:11,19-31 ]\n_11 : _10 [ at ${filepath}:11,19-31 ]\n_14 : ℕ [ at ${filepath}:11,19-31 ]\n\n———— Errors ————————————————————————————————————————————————\nUnsolved constraints\n`
2932
}
3033

test/tests/Test__WhyInScope.res

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,30 @@ describe("agda-mode.why-in-scope", () => {
2323

2424
let filteredResponses = responses->Array.filter(filteredResponse)
2525
let dependencyFilepath = Path.asset("Lib.agda")
26-
Assert.deepStrictEqual(
27-
filteredResponses,
28-
[
29-
DisplayInfo(
30-
WhyInScope(
31-
"Lib.true is in scope as\n * a constructor Lib.Bool.true brought into scope by\n - its definition at " ++
32-
dependencyFilepath ++ ":4,3-7",
26+
27+
switch ctx.state.agdaVersion {
28+
| Some(version) =>
29+
let positionFormat = if Util.Version.gte(version, "2.8.0") {
30+
// Agda 2.8.0+ uses dot format for WhyInScope
31+
":4.3-7"
32+
} else {
33+
// Pre-2.8.0 uses comma format
34+
":4,3-7"
35+
}
36+
37+
Assert.deepStrictEqual(
38+
filteredResponses,
39+
[
40+
DisplayInfo(
41+
WhyInScope(
42+
"Lib.true is in scope as\n * a constructor Lib.Bool.true brought into scope by\n - its definition at " ++
43+
dependencyFilepath ++ positionFormat,
44+
),
3345
),
34-
),
35-
],
36-
)
46+
],
47+
)
48+
| None => Assert.fail("No Agda version found")
49+
}
3750
})
3851

3952
Async.it("should be responded with correct responses (global)", async () => {
@@ -45,16 +58,29 @@ describe("agda-mode.why-in-scope", () => {
4558

4659
let filteredResponses = responses->Array.filter(filteredResponse)
4760
let dependencyFilepath = Path.asset("Lib.agda")
48-
Assert.deepStrictEqual(
49-
filteredResponses,
50-
[
51-
DisplayInfo(
52-
WhyInScope(
53-
"Lib.true is in scope as\n * a constructor Lib.Bool.true brought into scope by\n - its definition at " ++
54-
dependencyFilepath ++ ":4,3-7",
61+
62+
switch ctx.state.agdaVersion {
63+
| Some(version) =>
64+
let positionFormat = if Util.Version.gte(version, "2.8.0") {
65+
// Agda 2.8.0+ uses dot format for WhyInScope
66+
":4.3-7"
67+
} else {
68+
// Pre-2.8.0 uses comma format
69+
":4,3-7"
70+
}
71+
72+
Assert.deepStrictEqual(
73+
filteredResponses,
74+
[
75+
DisplayInfo(
76+
WhyInScope(
77+
"Lib.true is in scope as\n * a constructor Lib.Bool.true brought into scope by\n - its definition at " ++
78+
dependencyFilepath ++ positionFormat,
79+
),
5580
),
56-
),
57-
],
58-
)
81+
],
82+
)
83+
| None => Assert.fail("No Agda version found")
84+
}
5985
})
6086
})

0 commit comments

Comments
 (0)