Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee35f8e

Browse files
committed
gopls/internal/lsp/source: hovering over broken packages is not an error
Fixesgolang/go#64237Change-Id: I5b326e084c31a7835684fb08491bd71af606fb1cReviewed-on:https://go-review.googlesource.com/c/tools/+/549117LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent67611a1 commitee35f8e

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

‎gopls/internal/lsp/source/hover.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
273273
{
274274
linkMeta=findFileInDeps(snapshot,pkg.Metadata(),declPGF.URI)
275275
iflinkMeta==nil {
276-
return protocol.Range{},nil,bug.Errorf("nometadata for %s",declPGF.URI)
276+
return protocol.Range{},nil,bug.Errorf("nopackage data for %s",declPGF.URI)
277277
}
278278

279279
// For package names, we simply link to their imported package.
@@ -283,7 +283,10 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
283283
impID:=linkMeta.DepsByPkgPath[PackagePath(pkgName.Imported().Path())]
284284
linkMeta=snapshot.Metadata(impID)
285285
iflinkMeta==nil {
286-
return protocol.Range{},nil,bug.Errorf("no metadata for %s",declPGF.URI)
286+
// Broken imports have fake package paths, so it is not a bug if we
287+
// don't have metadata. As of writing, there is no way to distinguish
288+
// broken imports from a true bug where expected metadata is missing.
289+
return protocol.Range{},nil,fmt.Errorf("no package data for %s",declPGF.URI)
287290
}
288291
}else {
289292
// For all others, check whether the object is in the package scope, or

‎gopls/internal/test/marker/doc.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,18 @@ The following markers are supported within marker tests:
151151
TODO(adonovan): in the older marker framework, the annotation asserted
152152
two additional fields (source="compiler", kind="error"). Restore them?
153153
154-
- def(src, dst location):perform a textDocument/definition request at
154+
- def(src, dst location):performs a textDocument/definition request at
155155
the src location, and check the result points to the dst location.
156156
157157
- documentLink(golden): asserts that textDocument/documentLink returns
158158
links as described by the golden file.
159159
160-
- foldingrange(golden):perform a textDocument/foldingRange for the
160+
- foldingrange(golden):performs a textDocument/foldingRange for the
161161
current document, and compare with the golden content, which is the
162162
original source annotated with numbered tags delimiting the resulting
163163
ranges (e.g. <1 kind="..."> ... </1>).
164164
165-
- format(golden):perform a textDocument/format request for the enclosing
165+
- format(golden):performs a textDocument/format request for the enclosing
166166
file, and compare against the named golden file. If the formatting
167167
request succeeds, the golden file must contain the resulting formatted
168168
source. If the formatting request fails, the golden file must contain
@@ -172,9 +172,12 @@ The following markers are supported within marker tests:
172172
textDocument/highlight request at the given src location, which should
173173
highlight the provided dst locations.
174174
175-
- hover(src, dst location, sm stringMatcher): perform a
176-
textDocument/hover at the src location, and checks that the result is
177-
the dst location, with matching hover content.
175+
- hover(src, dst location, sm stringMatcher): performs a textDocument/hover
176+
at the src location, and checks that the result is the dst location, with
177+
matching hover content.
178+
179+
- hovererr(src, sm stringMatcher): performs a textDocument/hover at the src
180+
location, and checks that the error matches the given stringMatcher.
178181
179182
- implementations(src location, want ...location): makes a
180183
textDocument/implementation query at the src location and

‎gopls/internal/test/marker/marker_test.go‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ func (m marker) ctx() context.Context { return m.run.env.Ctx }
231231
// T returns the testing.TB for this mark.
232232
func (mmarker)T() testing.TB {returnm.run.env.T }
233233

234+
// server returns the LSP server for the marker test run.
235+
func (mmarker)editor()*fake.Editor {returnm.run.env.Editor }
236+
234237
// server returns the LSP server for the marker test run.
235238
func (mmarker)server() protocol.Server {returnm.run.env.Editor.Server }
236239

@@ -251,7 +254,7 @@ func (mark marker) path() string {
251254

252255
// mapper returns a *protocol.Mapper for the current file.
253256
func (markmarker)mapper()*protocol.Mapper {
254-
mapper,err:=mark.run.env.Editor.Mapper(mark.path())
257+
mapper,err:=mark.editor().Mapper(mark.path())
255258
iferr!=nil {
256259
mark.T().Fatalf("failed to get mapper for current mark: %v",err)
257260
}
@@ -418,6 +421,7 @@ var actionMarkerFuncs = map[string]func(marker){
418421
"format":actionMarkerFunc(formatMarker),
419422
"highlight":actionMarkerFunc(highlightMarker),
420423
"hover":actionMarkerFunc(hoverMarker),
424+
"hovererr":actionMarkerFunc(hoverErrMarker),
421425
"implementation":actionMarkerFunc(implementationMarker),
422426
"incomingcalls":actionMarkerFunc(incomingCallsMarker),
423427
"inlayhints":actionMarkerFunc(inlayhintsMarker),
@@ -1456,10 +1460,6 @@ func highlightMarker(mark marker, src protocol.Location, dsts ...protocol.Locati
14561460
}
14571461
}
14581462

1459-
// hoverMarker implements the @hover marker, running textDocument/hover at the
1460-
// given src location and asserting that the resulting hover is over the dst
1461-
// location (typically a span surrounding src), and that the markdown content
1462-
// matches the golden content.
14631463
funchoverMarker(markmarker,src,dst protocol.Location,scstringMatcher) {
14641464
content,gotDst:=mark.run.env.Hover(src)
14651465
ifgotDst!=dst {
@@ -1472,6 +1472,11 @@ func hoverMarker(mark marker, src, dst protocol.Location, sc stringMatcher) {
14721472
sc.check(mark,gotMD)
14731473
}
14741474

1475+
funchoverErrMarker(markmarker,src protocol.Location,emstringMatcher) {
1476+
_,_,err:=mark.editor().Hover(mark.ctx(),src)
1477+
em.checkErr(mark,err)
1478+
}
1479+
14751480
// locMarker implements the @loc marker. It is executed before other
14761481
// markers, so that locations are available.
14771482
funclocMarker(markmarker,loc protocol.Location) protocol.Location {returnloc }

‎gopls/internal/test/marker/testdata/hover/issue64239.txt‎

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This test verifies fixes for various issues reported for hover.
2+
3+
-- go.mod --
4+
module golang.org/lsptests
5+
6+
-- issue64239/p.go --
7+
package issue64239
8+
9+
// golang/go#64239: hover fails for objects in the unsafe package.
10+
11+
import "unsafe"
12+
13+
var _ = unsafe.Sizeof(struct{}{}) //@hover("Sizeof", "Sizeof", "`Sizeof` on pkg.go.dev")
14+
15+
-- issue64237/p.go --
16+
package issue64237
17+
18+
// golang/go#64237: hover panics for broken imports.
19+
20+
import "golang.org/lsptests/nonexistant" //@diag("\"golang", re"could not import")
21+
22+
var _ = nonexistant.Value //@hovererr("nonexistant", "no package data")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp