mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	LSP: Support LocationLink (#12231)
* support LocationLink in callbacks * announce linkSupport in client capabilities
This commit is contained in:
		@@ -644,6 +644,18 @@ function protocol.make_client_capabilities()
 | 
				
			|||||||
        -- TODO(tjdevries): Implement this
 | 
					        -- TODO(tjdevries): Implement this
 | 
				
			||||||
        contextSupport = false;
 | 
					        contextSupport = false;
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
 | 
					      declaration = {
 | 
				
			||||||
 | 
					        linkSupport = true;
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					      definition = {
 | 
				
			||||||
 | 
					        linkSupport = true;
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					      implementation = {
 | 
				
			||||||
 | 
					        linkSupport = true;
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					      typeDefinition = {
 | 
				
			||||||
 | 
					        linkSupport = true;
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
      hover = {
 | 
					      hover = {
 | 
				
			||||||
        dynamicRegistration = false;
 | 
					        dynamicRegistration = false;
 | 
				
			||||||
        contentFormat = { protocol.MarkupKind.Markdown; protocol.MarkupKind.PlainText };
 | 
					        contentFormat = { protocol.MarkupKind.Markdown; protocol.MarkupKind.PlainText };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -424,8 +424,10 @@ function M.make_floating_popup_options(width, height, opts)
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function M.jump_to_location(location)
 | 
					function M.jump_to_location(location)
 | 
				
			||||||
  if location.uri == nil then return end
 | 
					  -- location may be Location or LocationLink
 | 
				
			||||||
  local bufnr = vim.uri_to_bufnr(location.uri)
 | 
					  local uri = location.uri or location.targetUri
 | 
				
			||||||
 | 
					  if uri == nil then return end
 | 
				
			||||||
 | 
					  local bufnr = vim.uri_to_bufnr(uri)
 | 
				
			||||||
  -- Save position in jumplist
 | 
					  -- Save position in jumplist
 | 
				
			||||||
  vim.cmd "normal! m'"
 | 
					  vim.cmd "normal! m'"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -436,8 +438,9 @@ function M.jump_to_location(location)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  --- Jump to new location
 | 
					  --- Jump to new location
 | 
				
			||||||
  api.nvim_set_current_buf(bufnr)
 | 
					  api.nvim_set_current_buf(bufnr)
 | 
				
			||||||
  local row = location.range.start.line
 | 
					  local range = location.range or location.targetSelectionRange
 | 
				
			||||||
  local col = location.range.start.character
 | 
					  local row = range.start.line
 | 
				
			||||||
 | 
					  local col = range.start.character
 | 
				
			||||||
  local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
 | 
					  local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
 | 
				
			||||||
  col = vim.str_byteindex(line, col)
 | 
					  col = vim.str_byteindex(line, col)
 | 
				
			||||||
  api.nvim_win_set_cursor(0, {row + 1, col})
 | 
					  api.nvim_win_set_cursor(0, {row + 1, col})
 | 
				
			||||||
@@ -876,9 +879,11 @@ function M.locations_to_items(locations)
 | 
				
			|||||||
    end;
 | 
					    end;
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
  for _, d in ipairs(locations) do
 | 
					  for _, d in ipairs(locations) do
 | 
				
			||||||
    local start = d.range.start
 | 
					    -- locations may be Location or LocationLink
 | 
				
			||||||
    local fname = assert(vim.uri_to_fname(d.uri))
 | 
					    local uri = d.uri or d.targetUri
 | 
				
			||||||
    table.insert(grouped[fname], {start = start})
 | 
					    local fname = assert(vim.uri_to_fname(uri))
 | 
				
			||||||
 | 
					    local range = d.range or d.targetSelectionRange
 | 
				
			||||||
 | 
					    table.insert(grouped[fname], {start = range.start})
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user