Skip to content

How to highlight a symbol under the cursor and its references? #428

Answered by antosha417
arbitrary-dev asked this question in Q&A
Discussion options

You must be logged in to vote

In order to do it I have this in on_attach function

metals_config.on_attach = function(client, bufnr)
  if client.server_capabilities.documentHighlightProvider then
    vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
    vim.api.nvim_create_autocmd('CursorHold', {
      buffer = bufnr,
      group = 'lsp_document_highlight',
      callback = vim.lsp.buf.document_highlight
    })
    vim.api.nvim_create_autocmd('CursorMoved', {
      buffer = bufnr,
      group = 'lsp_document_highlight',
      callback = vim.lsp.buf.clear_references
    })
 end
end

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@antosha417
Comment options

@arbitrary-dev
Comment options

@antosha417
Comment options

@arbitrary-dev
Comment options

@arbitrary-dev
Comment options

Answer selected by arbitrary-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants