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>
diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go
index 9e2a2ec..6410636 100644
--- a/internal/lsp/code_action.go
+++ b/internal/lsp/code_action.go
@@ -123,7 +123,8 @@
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
}
}