Skip to content

Commit b574610

Browse files
committed
turn on reason errors automatically for re/rei files
1 parent 6b98c1f commit b574610

File tree

11 files changed

+162
-14
lines changed

11 files changed

+162
-14
lines changed

jscomp/bin/bsb.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12135,9 +12135,14 @@ let handle_generators oc
1213512135
)
1213612136

1213712137

12138-
let make_common_shadows package_specs dirname dir_index
12138+
let make_common_shadows
12139+
is_re
12140+
package_specs
12141+
dirname
12142+
dir_index
1213912143
: Bsb_ninja_util.shadow list
1214012144
=
12145+
let shadows : Bsb_ninja_util.shadow list =
1214112146
{ key = Bsb_ninja_global_vars.bs_package_flags;
1214212147
op =
1214312148
Append
@@ -12154,8 +12159,14 @@ let make_common_shadows package_specs dirname dir_index
1215412159
{ key = "bsc_extra_includes";
1215512160
op = OverwriteVar (Bsb_dir_index.string_of_bsb_dev_include dir_index)
1215612161
}
12157-
]
12162+
]
1215812163
)
12164+
in
12165+
if is_re then
12166+
{ key = Bsb_ninja_global_vars.bsc_flags;
12167+
op = Append("-bs-re-error")
12168+
} :: shadows
12169+
else shadows
1215912170

1216012171

1216112172
let emit_impl_build
@@ -12186,7 +12197,7 @@ let emit_impl_build
1218612197
let output_js =
1218712198
Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in
1218812199
let common_shadows =
12189-
make_common_shadows package_specs
12200+
make_common_shadows is_re package_specs
1219012201
(Filename.dirname file_cmi)
1219112202
group_dir_index in
1219212203
begin
@@ -12255,7 +12266,7 @@ let emit_intf_build
1225512266
in
1225612267
let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
1225712268
let common_shadows =
12258-
make_common_shadows package_specs
12269+
make_common_shadows is_re package_specs
1225912270
(Filename.dirname output_cmi)
1226012271
group_dir_index in
1226112272
Bsb_ninja_util.output_build oc

jscomp/bin/whole_compiler.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112955,7 +112955,12 @@ let leading_space_count str =
112955112955
starting from the first erroring character?) *)
112956112956
(* Range coordinates all 1-indexed, like for editors. Otherwise this code
112957112957
would have way too many off-by-one errors *)
112958-
let print_file ~is_warning ~range:((start_line, start_char), (end_line, end_char)) ~lines ppf () =
112958+
let print_file
112959+
~is_warning
112960+
~range:((start_line, start_line_start_char), (end_line, end_line_end_char))
112961+
~lines
112962+
ppf
112963+
() =
112959112964
(* show 2 lines before & after the erroring lines *)
112960112965
let first_shown_line = max 1 (start_line - 2) in
112961112966
let last_shown_line = min (Array.length lines) (end_line + 2) in
@@ -113026,13 +113031,13 @@ let print_file ~is_warning ~range:((start_line, start_char), (end_line, end_char
113026113031
if current_line_strictly_between_start_and_end_line then
113027113032
fprintf ppf "%c@," current_char
113028113033
else if i = start_line then begin
113029-
if j == (start_char - columns_to_cut) then fprintf ppf highlighted_content;
113034+
if j == (start_line_start_char - columns_to_cut) then fprintf ppf highlighted_content;
113030113035
fprintf ppf "%c@," current_char;
113031-
if j == (end_char - columns_to_cut) then fprintf ppf "@}"
113036+
if j == current_line_cut_length then fprintf ppf "@}"
113032113037
end else if i = end_line then begin
113033113038
if j == 1 then fprintf ppf highlighted_content;
113034113039
fprintf ppf "%c@," current_char;
113035-
if j == (end_char - columns_to_cut) then fprintf ppf "@}"
113040+
if j == (end_line_end_char - columns_to_cut) then fprintf ppf "@}"
113036113041
end else
113037113042
(* normal, non-highlighted line *)
113038113043
fprintf ppf "%c@," current_char
@@ -113977,7 +113982,7 @@ let buckle_script_flags =
113977113982
" Better error message combined with other tools "
113978113983
)
113979113984
::
113980-
("-bs-print-errors-in-reason-syntax",
113985+
("-bs-re-error",
113981113986
Arg.Unit Reason_outcome_printer_main.setup,
113982113987
" Print compiler errors in Reason syntax"
113983113988
)

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ let handle_generators oc
6262
)
6363

6464

65-
let make_common_shadows package_specs dirname dir_index
65+
let make_common_shadows
66+
is_re
67+
package_specs
68+
dirname
69+
dir_index
6670
: Bsb_ninja_util.shadow list
6771
=
72+
let shadows : Bsb_ninja_util.shadow list =
6873
{ key = Bsb_ninja_global_vars.bs_package_flags;
6974
op =
7075
Append
@@ -81,8 +86,14 @@ let make_common_shadows package_specs dirname dir_index
8186
{ key = "bsc_extra_includes";
8287
op = OverwriteVar (Bsb_dir_index.string_of_bsb_dev_include dir_index)
8388
}
84-
]
89+
]
8590
)
91+
in
92+
if is_re then
93+
{ key = Bsb_ninja_global_vars.bsc_flags;
94+
op = Append("-bs-re-error")
95+
} :: shadows
96+
else shadows
8697

8798

8899
let emit_impl_build
@@ -113,7 +124,7 @@ let emit_impl_build
113124
let output_js =
114125
Bsb_package_specs.get_list_of_output_js package_specs output_filename_sans_extension in
115126
let common_shadows =
116-
make_common_shadows package_specs
127+
make_common_shadows is_re package_specs
117128
(Filename.dirname file_cmi)
118129
group_dir_index in
119130
begin
@@ -182,7 +193,7 @@ let emit_intf_build
182193
in
183194
let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
184195
let common_shadows =
185-
make_common_shadows package_specs
196+
make_common_shadows is_re package_specs
186197
(Filename.dirname output_cmi)
187198
group_dir_index in
188199
Bsb_ninja_util.output_build oc

jscomp/build_tests/rerror/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
*.exe
2+
*.obj
3+
*.out
4+
*.compile
5+
*.native
6+
*.byte
7+
*.cmo
8+
*.annot
9+
*.cmi
10+
*.cmx
11+
*.cmt
12+
*.cmti
13+
*.cma
14+
*.a
15+
*.cmxa
16+
*.obj
17+
*~
18+
*.annot
19+
*.cmj
20+
*.bak
21+
lib/bs
22+
*.mlast
23+
*.mliast
24+
.vscode
25+
.merlin

jscomp/build_tests/rerror/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Basic Reason Template
2+
3+
Hello! This project allows you to quickly get started with Reason and BuckleScript. If you wanted a more sophisticated version, try the `react` template (`bsb -theme react -init .`).
4+
5+
# Build
6+
```
7+
npm run build
8+
```
9+
10+
# Build + Watch
11+
12+
```
13+
npm run watch
14+
```
15+
16+
17+
# Editor
18+
If you use `vscode`, Press `Windows + Shift + B` it will build automatically
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This is the configuration file used by BuckleScript's build system bsb. Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
2+
// BuckleScript comes with its own parser for bsconfig.json, which is normal JSON, with the extra support of comments and trailing commas.
3+
{
4+
"name": "rerror",
5+
"version": "0.1.0",
6+
"bsc-flags": ["-bs-super-errors"],
7+
"sources": [
8+
"src"
9+
],
10+
"bs-dependencies" : [
11+
// add your dependencies here. You'd usually install them normally through `npm install my-dependency`. If my-dependency has a bsconfig.json too, then everything will work seamlessly.
12+
]
13+
}

jscomp/build_tests/rerror/input.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var child_process = require('child_process')
2+
var assert = require('assert')
3+
var o = child_process.spawnSync(`bsb `,{cwd:__dirname, encoding:'utf8',shell:true})
4+
5+
6+
7+
var u = o.stdout.match(/int => int/g)
8+
assert.ok(u.length === 2)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "rerror",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"clean": "bsb -clean-world",
6+
"build": "bsb -make-world",
7+
"watch": "bsb -make-world -w"
8+
},
9+
"keywords": [
10+
"BuckleScript"
11+
],
12+
"license": "MIT",
13+
"devDependencies": {
14+
"bs-platform": "1.8.3"
15+
}
16+
}

jscomp/build_tests/rerror/src/demo.re

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
let x : int => int = "x";

jscomp/build_tests/rerror/tasks.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"version": "0.1.0",
3+
"command": "npm",
4+
"options": {
5+
"cwd": "${workspaceRoot}"
6+
},
7+
"isShellCommand": true,
8+
"args": [
9+
"run",
10+
"watch"
11+
],
12+
"showOutput": "always",
13+
"isBackground": true,
14+
"problemMatcher": {
15+
"fileLocation": "absolute",
16+
"owner": "ocaml",
17+
"watching": {
18+
"activeOnStart": false,
19+
"beginsPattern": ">>>> Start compiling",
20+
"endsPattern": ">>>> Finish compiling"
21+
},
22+
"pattern": [
23+
{
24+
"regexp": "^File \"(.*)\", line (\\d+)(?:, characters (\\d+)-(\\d+))?:$",
25+
"file": 1,
26+
"line": 2,
27+
"column": 3,
28+
"endColumn": 4
29+
},
30+
{
31+
"regexp": "^(?:(?:Parse\\s+)?(Warning|[Ee]rror)(?:\\s+\\d+)?:)?\\s+(.*)$",
32+
"severity": 1,
33+
"message": 2,
34+
"loop": true
35+
}
36+
]
37+
}
38+
}

0 commit comments

Comments
 (0)