diff options
author | Yi Ming <ofseed@foxmail.com> | 2025-02-11 17:09:39 +0800 |
---|---|---|
committer | Yi Ming <ofseed@foxmail.com> | 2025-02-11 17:09:39 +0800 |
commit | 67221497762ab5a055451c40a374e03bb620a68a (patch) | |
tree | 1b9291bfef62a0dacf3c1c4d4e5306a7eae96918 /runtime/lua/vim/lsp/util.lua | |
parent | f8cbdbb4a817c9e85386c50ddf31460e49038c21 (diff) | |
download | rneovim-67221497762ab5a055451c40a374e03bb620a68a.tar.gz rneovim-67221497762ab5a055451c40a374e03bb620a68a.tar.bz2 rneovim-67221497762ab5a055451c40a374e03bb620a68a.zip |
feat(lsp): include `end_col` and `end_lnum` in `vim.lsp.buf.symbols_to_items`
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index e16a905c44..e0d93ca75b 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1775,32 +1775,41 @@ end --- Converts symbols to quickfix list items. --- ----@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[] ----@param bufnr? integer +---@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[] list of symbols +---@param bufnr? integer buffer handle or 0 for current, defaults to current ---@return vim.quickfix.entry[] # See |setqflist()| for the format function M.symbols_to_items(symbols, bufnr) - bufnr = bufnr or 0 + bufnr = vim._resolve_bufnr(bufnr) + local items = {} --- @type vim.quickfix.entry[] for _, symbol in ipairs(symbols) do - --- @type string?, lsp.Position? - local filename, pos + --- @type string?, lsp.Range? + local filename, range if symbol.location then --- @cast symbol lsp.SymbolInformation filename = vim.uri_to_fname(symbol.location.uri) - pos = symbol.location.range.start + range = symbol.location.range elseif symbol.selectionRange then --- @cast symbol lsp.DocumentSymbol filename = api.nvim_buf_get_name(bufnr) - pos = symbol.selectionRange.start + range = symbol.selectionRange end - if filename and pos then + if filename and range then local kind = protocol.SymbolKind[symbol.kind] or 'Unknown' + + local lnum = range['start'].line + 1 + local col = range['start'].character + 1 + local end_lnum = range['end'].line + 1 + local end_col = range['end'].character + 1 + items[#items + 1] = { filename = filename, - lnum = pos.line + 1, - col = pos.character + 1, + lnum = lnum, + col = col, + end_lnum = end_lnum, + end_col = end_col, kind = kind, text = '[' .. kind .. '] ' .. symbol.name, } |