mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Fix off-by-one errors in LanguageServer's GetRange (#7251)
LSP assumes lines are index 0 to n-1, but Carbon Locs are index from 1
to n. We had the logic for this correct for the start of range but not
for the end of range (inclusive range).
Before this was the diagnostic span we would produce:
```carbon
fn F() {
return ();
<~~~~~~~~>
}
<~~~~~~~~~~~>
```
after:
```carbon
fn F() {
return ();
<~~~~~~~~>
}
```
This commit is contained in:
@@ -77,8 +77,8 @@ class DiagnosticConsumer : public Diagnostics::Consumer {
|
||||
auto GetRange(const Diagnostics::Loc& loc) -> clang::clangd::Range {
|
||||
return {.start = {.line = loc.line_number - 1,
|
||||
.character = loc.column_number - 1},
|
||||
.end = {.line = loc.line_number,
|
||||
.character = loc.column_number + loc.length}};
|
||||
.end = {.line = loc.line_number - 1,
|
||||
.character = loc.column_number + loc.length - 1}};
|
||||
}
|
||||
|
||||
// Converts a diagnostic level to an LSP severity.
|
||||
|
||||
Reference in New Issue
Block a user