1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:04:44 -07:00

internal/lsp: find import errors for named imports

String matching is used to find diagnostics that could be fixed by
organizing imports. Unused imports are of the form:
	"X imported but not used"
	"X imported but not used as Y"

Check that "imported but not used" is contained in the message to
include both named and unnamed imports.

Change-Id: I478d1fb239962e706eb1adf305b858fcc875b7f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188158
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Suzy Mueller 2019-07-30 11:10:00 -04:00
parent ed3277de27
commit a81e99d748

View File

@ -123,7 +123,8 @@ func findImportErrors(diagnostics []protocol.Diagnostic) bool {
return true
}
// "X imported but not used" is an unused import.
if strings.HasSuffix(diagnostic.Message, " imported but not used") {
// "X imported but not used as Y" is an unused import.
if strings.Contains(diagnostic.Message, " imported but not used") {
return true
}
}