LSP: Add a check for null version in VersionedTextDocumentIdentifier (#12185)

According to the spec there is the possibility that when a
VersionedTextDocumentIdentifier is used in a TextEdit the value may be
null. Currently we don't check for this and always assume that it's set.
So currently if a TextEdit comes in for a rename for example with the
version null, it fails as we are comparing the bufnumber with nil.

https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
This commit is contained in:
Chris Kipp
2020-04-26 16:51:41 +02:00
committed by GitHub
parent f3ffe0b325
commit 663b83814d

View File

@@ -159,7 +159,8 @@ 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 M.buf_versions[bufnr] > text_document.version then -- `VersionedTextDocumentIdentifier`s version may be nil https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
if text_document.version ~= nil and M.buf_versions[bufnr] > text_document.version then
print("Buffer ", text_document.uri, " newer than edits.") print("Buffer ", text_document.uri, " newer than edits.")
return return
end end