internal/lsp: handle definitions for variables with error types
Fixes golang/go#31465 Change-Id: I2f79fe2167bab79b497125995efc938f2b63d274 Reviewed-on: https://go-review.googlesource.com/c/tools/+/172117 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
744a51dd88
commit
2e9de471eb
|
@ -24,7 +24,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
expectedDefinitionsCount = 25
|
||||
expectedDefinitionsCount = 26
|
||||
expectedTypeDefinitionsCount = 2
|
||||
)
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) {
|
|||
const expectedCompletionsCount = 64
|
||||
const expectedDiagnosticsCount = 16
|
||||
const expectedFormatCount = 4
|
||||
const expectedDefinitionsCount = 16
|
||||
const expectedDefinitionsCount = 17
|
||||
const expectedTypeDefinitionsCount = 2
|
||||
const expectedHighlightsCount = 2
|
||||
const expectedSymbolsCount = 1
|
||||
|
|
|
@ -111,6 +111,10 @@ func identifier(ctx context.Context, v View, f File, pos token.Pos) (*Identifier
|
|||
}
|
||||
result.Type.Object = typeToObject(typ)
|
||||
if result.Type.Object != nil {
|
||||
// Identifiers with the type "error" are a special case with no position.
|
||||
if types.IsInterface(result.Type.Object.Type()) && result.Type.Object.Pkg() == nil && result.Type.Object.Name() == "error" {
|
||||
return result, nil
|
||||
}
|
||||
if result.Type.Range, err = objToRange(ctx, v, result.Type.Object); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@
|
|||
|
||||
package a
|
||||
|
||||
import "fmt"
|
||||
|
||||
type A string //@A
|
||||
|
||||
func Stuff() { //@Stuff
|
||||
x := 5
|
||||
Random2(x) //@godef("dom2", Random2)
|
||||
Random() //@godef("()", Random)
|
||||
|
||||
var err error //@err
|
||||
fmt.Printf("%v", err) //@godef("err", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue