lsp: remove vim.NIL from processing (#13174)

* lsp: remove vim.NIL from processing

* lsp: remove instances of vim.NIL
This commit is contained in:
TJ DeVries
2020-11-02 08:50:44 -05:00
committed by GitHub
parent 6224ec3d4a
commit dc14b1468a
2 changed files with 28 additions and 13 deletions

View File

@@ -42,13 +42,28 @@ local function is_dir(filename)
end end
local NIL = vim.NIL local NIL = vim.NIL
--@private
local recursive_convert_NIL
recursive_convert_NIL = function(v, tbl_processed)
if v == NIL then
return nil
elseif not tbl_processed[v] and type(v) == 'table' then
tbl_processed[v] = true
return vim.tbl_map(function(x)
return recursive_convert_NIL(x, tbl_processed)
end, v)
end
return v
end
--@private --@private
--- Returns its argument, but converts `vim.NIL` to Lua `nil`. --- Returns its argument, but converts `vim.NIL` to Lua `nil`.
--@param v (any) Argument --@param v (any) Argument
--@returns (any) --@returns (any)
local function convert_NIL(v) local function convert_NIL(v)
if v == NIL then return nil end return recursive_convert_NIL(v, {})
return v
end end
--@private --@private

View File

@@ -214,13 +214,16 @@ end
function M.apply_text_document_edit(text_document_edit) function M.apply_text_document_edit(text_document_edit)
local text_document = text_document_edit.textDocument local text_document = text_document_edit.textDocument
local bufnr = vim.uri_to_bufnr(text_document.uri) local bufnr = vim.uri_to_bufnr(text_document.uri)
if text_document.version then
-- `VersionedTextDocumentIdentifier`s version may be null https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier -- `VersionedTextDocumentIdentifier`s version may be null
if text_document.version ~= vim.NIL and M.buf_versions[bufnr] ~= nil and M.buf_versions[bufnr] > text_document.version then -- https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
print("Buffer ", text_document.uri, " newer than edits.") if text_document.version
return and M.buf_versions[bufnr]
end and M.buf_versions[bufnr] > text_document.version then
print("Buffer ", text_document.uri, " newer than edits.")
return
end end
M.apply_text_edits(text_document_edit.edits, bufnr) M.apply_text_edits(text_document_edit.edits, bufnr)
end end
@@ -492,10 +495,7 @@ function M.convert_signature_help_to_markdown_lines(signature_help)
--=== 0`. Whenever possible implementors should make an active decision about --=== 0`. Whenever possible implementors should make an active decision about
--the active signature and shouldn't rely on a default value. --the active signature and shouldn't rely on a default value.
local contents = {} local contents = {}
local active_signature = signature_help.activeSignature local active_signature = signature_help.activeSignature or 0
if active_signature == vim.NIL or active_signature == nil then
active_signature = 0
end
-- If the activeSignature is not inside the valid range, then clip it. -- If the activeSignature is not inside the valid range, then clip it.
if active_signature >= #signature_help.signatures then if active_signature >= #signature_help.signatures then
active_signature = 0 active_signature = 0
@@ -535,7 +535,7 @@ function M.convert_signature_help_to_markdown_lines(signature_help)
} }
--]=] --]=]
-- TODO highlight parameter -- TODO highlight parameter
if parameter.documentation and parameter.documentation ~= vim.NIL then if parameter.documentation then
M.convert_input_to_markdown_lines(parameter.documentation, contents) M.convert_input_to_markdown_lines(parameter.documentation, contents)
end end
end end