Merge pull request #30825 from lewis6991/refactor/lsputil

This commit is contained in:
Lewis Russell
2024-10-17 13:35:02 +01:00
committed by GitHub
9 changed files with 568 additions and 550 deletions

View File

@@ -66,6 +66,97 @@
--- @field winnr integer
--- @field winrow integer
--- @class vim.quickfix.entry
--- buffer number; must be the number of a valid buffer
--- @field bufnr? integer
---
--- name of a file; only used when "bufnr" is not
--- present or it is invalid.
--- @field filename? string
---
--- name of a module; if given it will be used in
--- quickfix error window instead of the filename.
--- @field module? string
---
--- line number in the file
--- @field lnum? integer
---
--- end of lines, if the item spans multiple lines
--- @field end_lnum? integer
---
--- search pattern used to locate the error
--- @field pattern? string
---
--- column number
--- @field col? integer
---
--- when non-zero: "col" is visual column
--- when zero: "col" is byte index
--- @field vcol? integer
---
--- end column, if the item spans multiple columns
--- @field end_col? integer
---
--- error number
--- @field nr? integer
---
--- description of the error
--- @field text? string
---
--- single-character error type, 'E', 'W', etc.
--- @field type? string
---
--- recognized error message
--- @field valid? boolean
---
--- custom data associated with the item, can be
--- any type.
--- @field user_data? any
--- @class vim.fn.setqflist.what
---
--- quickfix list context. See |quickfix-context|
--- @field context? table
---
--- errorformat to use when parsing text from
--- "lines". If this is not present, then the
--- 'errorformat' option value is used.
--- See |quickfix-parse|
--- @field efm? string
---
--- quickfix list identifier |quickfix-ID|
--- @field id? integer
--- index of the current entry in the quickfix
--- list specified by "id" or "nr". If set to '$',
--- then the last entry in the list is set as the
--- current entry. See |quickfix-index|
--- @field idx? integer
---
--- list of quickfix entries. Same as the {list}
--- argument.
--- @field items? vim.quickfix.entry[]
---
--- use 'errorformat' to parse a list of lines and
--- add the resulting entries to the quickfix list
--- {nr} or {id}. Only a |List| value is supported.
--- See |quickfix-parse|
--- @field lines? string[]
---
--- list number in the quickfix stack; zero
--- means the current quickfix list and "$" means
--- the last quickfix list.
--- @field nr? integer
---
--- function to get the text to display in the
--- quickfix window. The value can be the name of
--- a function or a funcref or a lambda. Refer
--- to |quickfix-window-function| for an explanation
--- of how to write the function and an example.
--- @field quickfixtextfunc? function
---
--- quickfix list title text. See |quickfix-title|
--- @field title? string
--- @class vim.fn.sign_define.dict
--- @field text string
--- @field icon? string

View File

@@ -8286,9 +8286,9 @@ function vim.fn.setpos(expr, list) end
--- independent of the 'errorformat' setting. Use a command like
--- `:cc 1` to jump to the first position.
---
--- @param list any[]
--- @param list vim.quickfix.entry[]
--- @param action? string
--- @param what? table
--- @param what? vim.fn.setqflist.what
--- @return any
function vim.fn.setqflist(list, action, what) end

View File

@@ -27,15 +27,20 @@ local function query_definition(pattern)
return {}
end
local results = {}
--- @param range lsp.Range
--- @param uri string
--- @param offset_encoding string
local add = function(range, uri, offset_encoding)
table.insert(results, mk_tag_item(pattern, range, uri, offset_encoding))
end
for client_id, lsp_results in pairs(assert(results_by_client)) do
local client = lsp.get_client_by_id(client_id)
local offset_encoding = client and client.offset_encoding or 'utf-16'
local result = lsp_results.result or {}
if result.range then -- Location
add(result.range, result.uri)
add(result.range, result.uri, offset_encoding)
else
result = result --[[@as (lsp.Location[]|lsp.LocationLink[])]]
for _, item in pairs(result) do

View File

@@ -338,6 +338,8 @@ function M.rename(new_name, opts)
-- Compute early to account for cursor movements after going async
local cword = vim.fn.expand('<cword>')
--- @param range lsp.Range
--- @param offset_encoding string
local function get_text_at_range(range, offset_encoding)
return api.nvim_buf_get_text(
bufnr,

File diff suppressed because it is too large Load Diff