internal/lsp: find references for ident before selector

Previously, if the position was before the "." in a selector,
pathEnclosingObjNode would move the position to right after the
".". This created confusing behavior where editors would highlight
the identifier before the ".", but references and go to definition
would be applied on the identified after the selector. This change
removes the shifting of the position if found on a selector.

Fixes golang/go#47408

Change-Id: If2504e7d5af2fae24b97c5c1e88b9cbe67aaaaf3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/338789
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/source/implementation.go b/internal/lsp/source/implementation.go
index 379471f..b2136be 100644
--- a/internal/lsp/source/implementation.go
+++ b/internal/lsp/source/implementation.go
@@ -349,11 +349,6 @@
 			if pos == n.Star {
 				pos = n.X.Pos()
 			}
-		case *ast.SelectorExpr:
-			// If pos is on the ".", move it into the selector.
-			if pos == n.X.End() {
-				pos = n.Sel.Pos()
-			}
 		}
 
 		return !found
diff --git a/internal/lsp/testdata/references/another/another.go b/internal/lsp/testdata/references/another/another.go
index de2ea16..47bda1e 100644
--- a/internal/lsp/testdata/references/another/another.go
+++ b/internal/lsp/testdata/references/another/another.go
@@ -7,7 +7,7 @@
 
 func _() {
 	xes := other.GetXes()
-	for _, x := range xes {
-		_ = x.Y //@mark(anotherXY, "Y"),refs("Y", typeXY, anotherXY, GetXesY)
+	for _, x := range xes { //@mark(defX, "x")
+		_ = x.Y //@mark(useX, "x"),mark(anotherXY, "Y"),refs("Y", typeXY, anotherXY, GetXesY),refs(".", defX, useX),refs("x", defX, useX)
 	}
 }
diff --git a/internal/lsp/testdata/summary.txt.golden b/internal/lsp/testdata/summary.txt.golden
index 682caef..521dad2 100644
--- a/internal/lsp/testdata/summary.txt.golden
+++ b/internal/lsp/testdata/summary.txt.golden
@@ -19,7 +19,7 @@
 DefinitionsCount = 95
 TypeDefinitionsCount = 18
 HighlightsCount = 69
-ReferencesCount = 25
+ReferencesCount = 27
 RenamesCount = 37
 PrepareRenamesCount = 7
 SymbolsCount = 5
diff --git a/internal/lsp/testdata/summary_generics.txt.golden b/internal/lsp/testdata/summary_generics.txt.golden
index 152f38d..3128120 100644
--- a/internal/lsp/testdata/summary_generics.txt.golden
+++ b/internal/lsp/testdata/summary_generics.txt.golden
@@ -18,7 +18,7 @@
 DefinitionsCount = 99
 TypeDefinitionsCount = 18
 HighlightsCount = 69
-ReferencesCount = 25
+ReferencesCount = 27
 RenamesCount = 33
 PrepareRenamesCount = 7
 SymbolsCount = 5