From 1feb683013bc6c9399337012b647e1e7db4b759d Mon Sep 17 00:00:00 2001 From: Pontus Leitzler Date: Tue, 19 Oct 2021 20:36:53 +0200 Subject: [PATCH] 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 Run-TryBot: Pontus Leitzler gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Robert Findley --- internal/lsp/analysis/infertypeargs/run_go118.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/lsp/analysis/infertypeargs/run_go118.go b/internal/lsp/analysis/infertypeargs/run_go118.go index 1b767e76d0..aed558a362 100644 --- a/internal/lsp/analysis/infertypeargs/run_go118.go +++ b/internal/lsp/analysis/infertypeargs/run_go118.go @@ -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}, }}, }) }