From a81e99d7481f02952fe65614f5650db67a76d273 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Tue, 30 Jul 2019 11:10:00 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/code_action.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index 9e2a2ecb..64106369 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go @@ -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 } }