-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement machine-applicable suggestions in diagnostics (#392)
This PR adds `report.SuggestEdits`, which allows diagnostics to suggest changes to an annotated span. This will be used for surfacing quick-fixes in the LSP (for example, for suggesting deleting unused imports, adding a `syntax` declaration, adding missing field numbers, and so on). The compiler is also able to render these as a simple diff, similar to some of rustc's diagnostics. I've tried to keep the data model simple: no diffing actually happens, the diagnostics are expected to generate the diffs manually. All the renderer does is convert the edits into hunks to show to the user. This PR contains examples in the lexer that shows how it is meant to be used.
- Loading branch information
Showing
17 changed files
with
812 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 20 additions & 12 deletions
32
experimental/parser/testdata/lexer/numbers/exotic-base.proto.stderr.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 26 additions & 14 deletions
40
experimental/parser/testdata/lexer/numbers/thousands.proto.stderr.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,55 @@ | ||
error: integer literal contains underscores | ||
--> testdata/lexer/numbers/thousands.proto:1:1 | ||
help: remove these underscores | ||
| | ||
1 | - 1_000_000 | ||
1 | + 1000000 | ||
| | ||
1 | 1_000_000 | ||
| ^^^^^^^^^ | ||
= note: Protobuf does not support Go/Java/Rust-style thousands separators | ||
|
||
error: unsupported base for integer literal | ||
--> testdata/lexer/numbers/thousands.proto:2:1 | ||
help: use a hexadecimal literal instead | ||
| | ||
2 | - 0b1_000_000 | ||
2 | + 0x40 | ||
| | ||
2 | 0b1_000_000 | ||
| ^^^^^^^^^^^ | ||
= note: Protobuf does not support binary integer literals | ||
= note: Protobuf does not support binary literals | ||
|
||
error: unsupported base for integer literal | ||
--> testdata/lexer/numbers/thousands.proto:3:1 | ||
help: remove the `o` | ||
| | ||
3 | - 0o1_000_000 | ||
3 | + 01_000_000 | ||
| | ||
3 | 0o1_000_000 | ||
| ^^^^^^^^^^^ replace `0o` with `0` | ||
= note: Protobuf does not support the `0o` prefix for octal literals | ||
= note: octal literals are prefixed with `0`, not `0o` | ||
|
||
error: integer literal contains underscores | ||
--> testdata/lexer/numbers/thousands.proto:4:1 | ||
help: remove these underscores | ||
| | ||
4 | - 0x1_000_000 | ||
4 | + 0x1000000 | ||
| | ||
4 | 0x1_000_000 | ||
| ^^^^^^^^^^^ | ||
= note: Protobuf does not support Go/Java/Rust-style thousands separators | ||
|
||
error: integer literal contains underscores | ||
--> testdata/lexer/numbers/thousands.proto:5:1 | ||
help: remove these underscores | ||
| | ||
5 | - 01_000_000 | ||
5 | + 01000000 | ||
| | ||
5 | 01_000_000 | ||
| ^^^^^^^^^^ | ||
= note: Protobuf does not support Go/Java/Rust-style thousands separators | ||
|
||
error: floating-point literal contains underscores | ||
--> testdata/lexer/numbers/thousands.proto:6:1 | ||
help: remove these underscores | ||
| | ||
6 | - 1_000_000.00 | ||
6 | + 1000000.00 | ||
| | ||
6 | 1_000_000.00 | ||
| ^^^^^^^^^^^^ | ||
= note: Protobuf does not support Go/Java/Rust-style thousands separators | ||
|
||
encountered 6 errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.