@@ -605,6 +605,55 @@ function! s:completionErrorHandler(next, error) abort dict
605605 call call (a: next , [-1 , []])
606606endfunction
607607
608+ " go#lsp#Type calls gopls to get the type definition of the identifier at
609+ " line and col in fname. handler should be a dictionary function that takes a
610+ " list of strings in the form 'file:line:col: message'. handler will be
611+ " attached to a dictionary that manages state (statuslines, sets the winid,
612+ " etc.)
613+ function ! go#lsp#SameIDs (showstatus, fname, line , col , handler) abort
614+ call go#lsp#DidChange (a: fname )
615+
616+ let l: lsp = s: lspfactory .get ()
617+ let l: msg = go#lsp#message#References (a: fname , a: line , a: col )
618+
619+ if a: showstatus
620+ let l: state = s: newHandlerState (' same ids' )
621+ else
622+ let l: state = s: newHandlerState (' ' )
623+ endif
624+
625+ let l: state .handleResult = funcref (' s:sameIDsHandler' , [function (a: handler , [], l: state )], l: state )
626+ let l: state .error = funcref (' s:noop' )
627+ return l: lsp .sendMessage (l: msg , l: state )
628+ endfunction
629+
630+ function ! s: sameIDsHandler (next , msg) abort dict
631+ let l: furi = go#path#ToURI (expand (' %:p' ))
632+
633+ let l: result = {
634+ \ ' sameids' : [],
635+ \ ' enclosing' : [],
636+ \ }
637+
638+ for l: loc in a: msg
639+ if l: loc .uri !=# l: furi
640+ continue
641+ endif
642+
643+ if len (l: result .enclosing) == 0
644+ let l: result .enclosing = [{
645+ \ ' desc' : ' identifier' ,
646+ \ ' start' : l: loc .range .start .character + 1 ,
647+ \ ' end' : l: loc .range .end .character + 1 ,
648+ \ }]
649+ endif
650+
651+ let l: result .sameids = add (l: result .sameids, printf (' %s:%s:%s' , go#path#FromURI (l: loc .uri), l: loc .range .start .line + 1 , l: loc .range .start .character + 1 ))
652+ endfor
653+
654+ call call (a: next , [0 , json_encode (l: result ), ' ' ])
655+ endfunction
656+
608657function ! go#lsp#Hover (fname, line , col , handler) abort
609658 call go#lsp#DidChange (a: fname )
610659
0 commit comments