internal/lsp/analysis/infertypeargs: reduce diagnostic range

When infertypeargs suggested an edit that kept at least one argument the
diagnostic sent to the editor included comma and whitespace(s).

In editors/IDEs that highlight the range it looked a bit odd. This
change reduce the diagnostic range to start at the first unnecessary
argument.

Change-Id: Ib091f8ff150c66d1d8ee4f82bda8b1b37202eeba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356989
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Pontus Leitzler 2021-10-19 20:36:53 +02:00 committed by Robert Findley
parent 98f6e0395b
commit 1feb683013
1 changed files with 7 additions and 6 deletions

View File

@ -74,22 +74,23 @@ func run(pass *analysis.Pass) (interface{}, error) {
}
if required < len(ix.Indices) {
var start, end token.Pos
var edit analysis.TextEdit
if required == 0 {
start, end = ix.Lbrack, ix.Rbrack+1 // erase the entire index
edit = analysis.TextEdit{Pos: start, End: end}
} else {
start = ix.Indices[required-1].End()
start = ix.Indices[required].Pos()
end = ix.Rbrack
// erase from end of last arg to include last comma & white-spaces
edit = analysis.TextEdit{Pos: ix.Indices[required-1].End(), End: end}
}
pass.Report(analysis.Diagnostic{
Pos: start,
End: end,
Message: "unnecessary type arguments",
SuggestedFixes: []analysis.SuggestedFix{{
Message: "simplify type arguments",
TextEdits: []analysis.TextEdit{{
Pos: start,
End: end,
}},
Message: "simplify type arguments",
TextEdits: []analysis.TextEdit{edit},
}},
})
}