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:
DavidLoftus
2026-05-27 17:37:56 +00:00
committed by GitHub
parent 518704608e
commit de381bded1
3 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -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.