@@ -128,6 +128,9 @@ func (s *server) Initialize(
128128 DefinitionProvider : & protocol.DefinitionOptions {
129129 WorkDoneProgressOptions : protocol.WorkDoneProgressOptions {WorkDoneProgress : true },
130130 },
131+ TypeDefinitionProvider : & protocol.TypeDefinitionOptions {
132+ WorkDoneProgressOptions : protocol.WorkDoneProgressOptions {WorkDoneProgress : true },
133+ },
131134 DocumentFormattingProvider : true ,
132135 HoverProvider : true ,
133136 ReferencesProvider : & protocol.ReferenceOptions {
@@ -384,16 +387,35 @@ func (s *server) Definition(
384387 ctx context.Context ,
385388 params * protocol.DefinitionParams ,
386389) ([]protocol.Location , error ) {
387- file := s .fileManager .Get (params .TextDocument .URI )
390+ return s .definition (ctx , params .TextDocument .URI , & params .WorkDoneProgressParams , params .Position )
391+ }
392+
393+ // TypeDefinition is the entry point for go-to-type-definition.
394+ func (s * server ) TypeDefinition (
395+ ctx context.Context ,
396+ params * protocol.TypeDefinitionParams ,
397+ ) ([]protocol.Location , error ) {
398+ return s .definition (ctx , params .TextDocument .URI , & params .WorkDoneProgressParams , params .Position )
399+ }
400+
401+ // definition powers [server.Definition] and [server.TypeDefinition], as they are not meaningfully
402+ // different in protobuf, but users may be used to using either.
403+ func (s * server ) definition (
404+ ctx context.Context ,
405+ uri protocol.URI ,
406+ workDoneProgressParams * protocol.WorkDoneProgressParams ,
407+ position protocol.Position ,
408+ ) ([]protocol.Location , error ) {
409+ file := s .fileManager .Get (uri )
388410 if file == nil {
389411 return nil , nil
390412 }
391413
392- progress := newProgressFromClient (s .lsp , & params . WorkDoneProgressParams )
414+ progress := newProgressFromClient (s .lsp , workDoneProgressParams )
393415 progress .Begin (ctx , "Searching" )
394416 defer progress .Done (ctx )
395417
396- symbol := file .SymbolAt (ctx , params . Position )
418+ symbol := file .SymbolAt (ctx , position )
397419 if symbol == nil {
398420 return nil , nil
399421 }
0 commit comments