internal/lsp: fix no definition when importShortcut is link

Fixes golang/go#45987

Change-Id: I59194f41eccdd3a0df6d9a3d0cc57008c40b1450
GitHub-Last-Rev: 832d6f864f1ec30b86ee59a8a196f24881dca0e3
GitHub-Pull-Request: golang/tools#317
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318469
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Suzy Mueller <suzmue@golang.org>
diff --git a/internal/lsp/definition.go b/internal/lsp/definition.go
index a80f07e..f8932d9 100644
--- a/internal/lsp/definition.go
+++ b/internal/lsp/definition.go
@@ -26,7 +26,7 @@
 	if err != nil {
 		return nil, err
 	}
-	if !snapshot.View().Options().ImportShortcut.ShowDefinition() {
+	if ident.IsImport() && !snapshot.View().Options().ImportShortcut.ShowDefinition() {
 		return nil, nil
 	}
 	var locations []protocol.Location
diff --git a/internal/lsp/source/identifier.go b/internal/lsp/source/identifier.go
index 1a726cc..78abcdf 100644
--- a/internal/lsp/source/identifier.go
+++ b/internal/lsp/source/identifier.go
@@ -41,6 +41,11 @@
 	qf  types.Qualifier
 }
 
+func (i *IdentifierInfo) IsImport() bool {
+	_, ok := i.Declaration.node.(*ast.ImportSpec)
+	return ok
+}
+
 type Declaration struct {
 	MappedRange []MappedRange
 	node        ast.Node