Skip to content

Commit

Permalink
internal/lsp/source: respond with the underlying type to Type Definit…
Browse files Browse the repository at this point in the history
…ion requests for composite types

Go to Type Definition works for all composite types except maps because
it is not clear which type to return if both key and value are named types.

Fixes golang/go#45029

Change-Id: Ie14f333c51af11033e2494aaaac367d35e7dc87b
GitHub-Last-Rev: 94a0481
GitHub-Pull-Request: golang#292
Reviewed-on: https://go-review.googlesource.com/c/tools/+/304789
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
ShoshinNikita authored and stamblerre committed Mar 30, 2021
1 parent 682c7e6 commit af36406
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/lsp/source/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ func typeToObject(typ types.Type) types.Object {
return typ.Obj()
case *types.Pointer:
return typeToObject(typ.Elem())
case *types.Array:
return typeToObject(typ.Elem())
case *types.Slice:
return typeToObject(typ.Elem())
case *types.Chan:
return typeToObject(typ.Elem())
default:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/testdata/summary.txt.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SemanticTokenCount = 3
SuggestedFixCount = 40
FunctionExtractionCount = 13
DefinitionsCount = 90
TypeDefinitionsCount = 2
TypeDefinitionsCount = 10
HighlightsCount = 69
ReferencesCount = 25
RenamesCount = 33
Expand Down
38 changes: 38 additions & 0 deletions internal/lsp/testdata/typdef/typdef.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package typdef

type Struct struct { //@item(Struct, "Struct", "struct{...}", "struct")
Field string
}

type Int int //@item(Int, "Int", "int", "type")

func _() {
var (
value Struct
point *Struct
)
_ = value //@typdef("value", Struct)
_ = point //@typdef("point", Struct)

var (
array [3]Struct
slice []Struct
ch chan Struct
complex [3]chan *[5][]Int
)
_ = array //@typdef("array", Struct)
_ = slice //@typdef("slice", Struct)
_ = ch //@typdef("ch", Struct)
_ = complex //@typdef("complex", Int)

var s struct {
x struct {
xx struct {
field1 []Struct
field2 []Int
}
}
}
s.x.xx.field1 //@typdef("field1", Struct)
s.x.xx.field2 //@typdef("field2", Int)
}

0 comments on commit af36406

Please sign in to comment.