Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/lsp/source: respond with the underlying type to Type Definition requests for composite types #292

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}