Skip to content

Commit

Permalink
Fix end position of diagnostic for LSP
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop#12932.

This is a porting because it can be said that even Standard.rb, which serves as the base for RuboCop's built-in LSP,
does the same thing.

---

This is a quote from rubocop/rubocop#12932.

`character` of `Position` is zero-based
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
> Character offset on a line in a document (zero-based).

And, `Parser::Source::Range` is also zero-based
https://github.com/whitequark/parser/blob/3e260d2e37bcb3de8705489d1c2799c26c7a2215/lib/parser/source/range.rb#L104
> zero-based column number of the end of this range.

Therefore, `-1` is not necessary.
  • Loading branch information
koic committed Jun 23, 2024
1 parent ad9ca9e commit f0df3dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/standard/lsp/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def diagnostic(file_uri, text)
message: msg,
range: {
start: {character: loc[:start_column] - 1, line: loc[:start_line] - 1},
end: {character: loc[:last_column] - 1, line: loc[:last_line] - 1}
end: {character: loc[:last_column], line: loc[:last_line] - 1}
},
severity: severity,
source: "standard"
Expand Down
6 changes: 3 additions & 3 deletions test/standard/runners/lsp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ def test_did_open
diagnostics: [
{code: "Layout/ArrayAlignment",
message: "Use one level of indentation for elements following the first line of a multi-line array.",
range: {start: {character: 3, line: 2}, end: {character: 3, line: 2}},
range: {start: {character: 3, line: 2}, end: {character: 4, line: 2}},
severity: 3,
source: "standard"},
{code: "Layout/ExtraSpacing",
message: "Unnecessary spacing detected.",
range: {start: {character: 4, line: 2}, end: {character: 4, line: 2}},
range: {start: {character: 4, line: 2}, end: {character: 5, line: 2}},
severity: 3,
source: "standard"},
{code: "Layout/SpaceInsideArrayLiteralBrackets",
message: "Do not use space inside array brackets.",
range: {start: {character: 4, line: 2}, end: {character: 5, line: 2}},
range: {start: {character: 4, line: 2}, end: {character: 6, line: 2}},
severity: 3,
source: "standard"}
],
Expand Down

0 comments on commit f0df3dd

Please sign in to comment.