@@ -94,9 +94,52 @@ local function keymaps(bufnr, client)
9494 k (" <leader>dd" , snacks .picker .diagnostics_buffer , " Diagnostics: File" )
9595 k (" K" , hover , " Hover" )
9696
97+ -- Jump to type implementation
9798 if client :supports_method (methods .textDocument_typeDefinition ) then
9899 k (" grt" , vim .lsp .buf .type_definition , " Jump to type definition" )
99100 end
101+
102+ -- Jump to symbol references
103+ if client :supports_method (methods .textDocument_references ) then
104+ local function jump_to_reference (direction )
105+ return function ()
106+ -- Make sure we're at the beginning of the current word
107+ vim .cmd (" normal! eb" )
108+
109+ vim .lsp .buf .references (nil , {
110+ on_list = function (options )
111+ if not options or not options .items or # options .items == 0 then
112+ vim .notify (" No references found" , vim .log .levels .WARN )
113+ return
114+ end
115+
116+ -- Find the current reference based on cursor position
117+ local current_ref = 1
118+ local lnum = vim .fn .line (" ." )
119+ local col = vim .fn .col (" ." )
120+ for i , item in ipairs (options .items ) do
121+ if item .lnum == lnum and item .col == col then
122+ current_ref = i
123+ break
124+ end
125+ end
126+
127+ local delta = direction == " next" and 1 or - 1
128+ local adjacent_ref = math.min (# options .items , current_ref + delta )
129+ if adjacent_ref < 1 then
130+ adjacent_ref = 1
131+ end
132+
133+ vim .fn .setqflist ({}, " r" , { items = options .items })
134+ vim .cmd (adjacent_ref .. " cc" )
135+ end ,
136+ })
137+ end
138+ end
139+
140+ k (" [r" , jump_to_reference (" prev" ), " Jump to previous reference" )
141+ k (" ]r" , jump_to_reference (" next" ), " Jump to next reference" )
142+ end
100143end
101144
102145-- Highlight all references to symbol under cursor
0 commit comments