[LSP] Add in more docs for highlight groups with document_highlight() (#13614)

Currently it's not 100% clear that without setting these, using the autocomds
to utilize the `textDocument/documentHighlight` functionality, nothing will
actually be visible since the highlight groups don't have any details. This
just adds in a couple simple extra notes to make sure that's done
This commit is contained in:
Chris Kipp
2021-02-24 17:23:47 +01:00
committed by GitHub
parent d290da70b7
commit 7d82aaa6f5
2 changed files with 23 additions and 6 deletions

View File

@@ -397,6 +397,11 @@ LSP HIGHLIGHT *lsp-highlight*
Reference Highlights: Reference Highlights:
Highlight groups that are meant to be used by |vim.lsp.buf.document_highlight()|.
You can see more about the differences in types here:
https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight
*hl-LspReferenceText* *hl-LspReferenceText*
LspReferenceText used for highlighting "text" references LspReferenceText used for highlighting "text" references
*hl-LspReferenceRead* *hl-LspReferenceRead*
@@ -932,15 +937,21 @@ definition() *vim.lsp.buf.definition()*
Jumps to the definition of the symbol under the cursor. Jumps to the definition of the symbol under the cursor.
document_highlight() *vim.lsp.buf.document_highlight()* document_highlight() *vim.lsp.buf.document_highlight()*
Send request to server to resolve document highlights for the Send request to the server to resolve document highlights for
current text document position. This request can be associated the current text document position. This request can be
to key mapping or to events such as `CursorHold` , eg: triggered by a key mapping or by events such as `CursorHold` ,
eg:
> >
vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]] vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]]
vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]] vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]]
vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]] vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]]
< <
Note: Usage of |vim.lsp.buf.document_highlight()| requires the
following highlight groups to be defined or you won't be able
to see the actual highlights. |LspReferenceText|
|LspReferenceRead| |LspReferenceWrite|
document_symbol() *vim.lsp.buf.document_symbol()* document_symbol() *vim.lsp.buf.document_symbol()*
Lists all symbols in the current buffer in the quickfix Lists all symbols in the current buffer in the quickfix
window. window.

View File

@@ -310,15 +310,21 @@ function M.workspace_symbol(query)
request('workspace/symbol', params) request('workspace/symbol', params)
end end
--- Send request to server to resolve document highlights for the --- Send request to the server to resolve document highlights for the current
--- current text document position. This request can be associated --- text document position. This request can be triggered by a key mapping or
--- to key mapping or to events such as `CursorHold`, eg: --- by events such as `CursorHold`, eg:
--- ---
--- <pre> --- <pre>
--- vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]] --- vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]]
--- vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]] --- vim.api.nvim_command [[autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()]]
--- vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]] --- vim.api.nvim_command [[autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()]]
--- </pre> --- </pre>
---
--- Note: Usage of |vim.lsp.buf.document_highlight()| requires the following highlight groups
--- to be defined or you won't be able to see the actual highlights.
--- |LspReferenceText|
--- |LspReferenceRead|
--- |LspReferenceWrite|
function M.document_highlight() function M.document_highlight()
local params = util.make_position_params() local params = util.make_position_params()
request('textDocument/documentHighlight', params) request('textDocument/documentHighlight', params)