Skip to content

Commit

Permalink
QF1003: reorder edits to respect LSP spec
Browse files Browse the repository at this point in the history
LSP states that

> Text edits ranges must never overlap, that means no part of the original
> document must be manipulated by more than one edit. However, it is
> possible that multiple edits have the same start position: multiple
> inserts, or any number of inserts followed by a single remove or replace
> edit. If multiple inserts have the same position, the order in the array
> defines the order in which the inserted strings appear in the resulting
> text.
  • Loading branch information
dominikh committed Nov 6, 2023
1 parent b3ee554 commit 4136a84
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions quickfix/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ func CheckIfElseToSwitch(pass *analysis.Pass) (interface{}, error) {
}

var edits []analysis.TextEdit
// FIXME this forces the first case to begin in column 0. try to fix the indentation
edits = append(edits, edit.ReplaceWithString(edit.Range{ifstmt.If, ifstmt.If}, fmt.Sprintf("switch %s {\n", report.Render(pass, x))))
for item := ifstmt; item != nil; {
var end token.Pos
if item.Else != nil {
Expand Down Expand Up @@ -413,8 +415,6 @@ func CheckIfElseToSwitch(pass *analysis.Pass) (interface{}, error) {
panic(fmt.Sprintf("unreachable: %T", els))
}
}
// FIXME this forces the first case to begin in column 0. try to fix the indentation
edits = append(edits, edit.ReplaceWithString(edit.Range{ifstmt.If, ifstmt.If}, fmt.Sprintf("switch %s {\n", report.Render(pass, x))))
report.Report(pass, ifstmt, fmt.Sprintf("could use tagged switch on %s", report.Render(pass, x)),
report.Fixes(edit.Fix("Replace with tagged switch", edits...)),
report.ShortRange())
Expand Down

0 comments on commit 4136a84

Please sign in to comment.