mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
revert: "fix(lsp): use buffer scheme for files not stored on disk" (#22604)
Although using `buffer://` for unsaved file buffers fixes issues with
language servers like eclipse.jdt.ls or ansible-language-server, it
breaks completion and signature help for clangd.
A regression is worse than a fix for something else, so this reverts
commit 896d672736
.
The spec change is also still in dicussion, see
https://github.com/microsoft/language-server-protocol/pull/1679#discussion_r1130704886
This commit is contained in:

committed by
GitHub

parent
a7cd79349c
commit
236c20795e
@@ -369,7 +369,7 @@ do
|
|||||||
--- @field offset_encoding "utf-8"|"utf-16"|"utf-32"
|
--- @field offset_encoding "utf-8"|"utf-16"|"utf-32"
|
||||||
---
|
---
|
||||||
--- @class CTBufferState
|
--- @class CTBufferState
|
||||||
--- @field uri string uri of the buffer
|
--- @field name string name of the buffer
|
||||||
--- @field lines string[] snapshot of buffer lines from last didChange
|
--- @field lines string[] snapshot of buffer lines from last didChange
|
||||||
--- @field lines_tmp string[]
|
--- @field lines_tmp string[]
|
||||||
--- @field pending_changes table[] List of debounced changes in incremental sync mode
|
--- @field pending_changes table[] List of debounced changes in incremental sync mode
|
||||||
@@ -488,12 +488,8 @@ do
|
|||||||
if buf_state then
|
if buf_state then
|
||||||
buf_state.refs = buf_state.refs + 1
|
buf_state.refs = buf_state.refs + 1
|
||||||
else
|
else
|
||||||
local uri = vim.uri_from_bufnr(bufnr)
|
|
||||||
if not uv.fs_stat(api.nvim_buf_get_name(bufnr)) then
|
|
||||||
uri = uri:gsub('^file://', 'buffer://')
|
|
||||||
end
|
|
||||||
buf_state = {
|
buf_state = {
|
||||||
uri = uri,
|
name = api.nvim_buf_get_name(bufnr),
|
||||||
lines = {},
|
lines = {},
|
||||||
lines_tmp = {},
|
lines_tmp = {},
|
||||||
pending_changes = {},
|
pending_changes = {},
|
||||||
@@ -508,26 +504,12 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
---@param client table
|
function changetracking._get_and_set_name(client, bufnr, name)
|
||||||
---@param bufnr integer
|
|
||||||
---@return string uri
|
|
||||||
function changetracking._get_uri(client, bufnr)
|
|
||||||
local state = state_by_group[get_group(client)] or {}
|
local state = state_by_group[get_group(client)] or {}
|
||||||
local buf_state = (state.buffers or {})[bufnr]
|
local buf_state = (state.buffers or {})[bufnr]
|
||||||
return assert(buf_state.uri, 'Must have an URI set')
|
local old_name = buf_state.name
|
||||||
end
|
buf_state.name = name
|
||||||
|
return old_name
|
||||||
---@private
|
|
||||||
---@param client table
|
|
||||||
---@param bufnr integer
|
|
||||||
---@param uri string
|
|
||||||
---@return string uri
|
|
||||||
function changetracking._get_and_set_uri(client, bufnr, uri)
|
|
||||||
local state = state_by_group[get_group(client)] or {}
|
|
||||||
local buf_state = (state.buffers or {})[bufnr]
|
|
||||||
local old_uri = buf_state.uri
|
|
||||||
buf_state.uri = uri
|
|
||||||
return old_uri
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
@@ -614,7 +596,7 @@ do
|
|||||||
{ text = buf_get_full_text(bufnr) },
|
{ text = buf_get_full_text(bufnr) },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
local uri = buf_state.uri
|
local uri = vim.uri_from_bufnr(bufnr)
|
||||||
for _, client in pairs(state.clients) do
|
for _, client in pairs(state.clients) do
|
||||||
if not client.is_stopped() and lsp.buf_is_attached(bufnr, client.id) then
|
if not client.is_stopped() and lsp.buf_is_attached(bufnr, client.id) then
|
||||||
client.notify('textDocument/didChange', {
|
client.notify('textDocument/didChange', {
|
||||||
@@ -727,14 +709,11 @@ local function text_document_did_open_handler(bufnr, client)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local filetype = nvim_buf_get_option(bufnr, 'filetype')
|
local filetype = nvim_buf_get_option(bufnr, 'filetype')
|
||||||
local uri = vim.uri_from_bufnr(bufnr)
|
|
||||||
if not uv.fs_stat(api.nvim_buf_get_name(bufnr)) then
|
|
||||||
uri = uri:gsub('^file://', 'buffer://')
|
|
||||||
end
|
|
||||||
local params = {
|
local params = {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
version = 0,
|
version = 0,
|
||||||
uri = uri,
|
uri = vim.uri_from_bufnr(bufnr),
|
||||||
languageId = client.config.get_language_id(bufnr, filetype),
|
languageId = client.config.get_language_id(bufnr, filetype),
|
||||||
text = buf_get_full_text(bufnr),
|
text = buf_get_full_text(bufnr),
|
||||||
},
|
},
|
||||||
@@ -1611,13 +1590,8 @@ local function text_document_did_save_handler(bufnr)
|
|||||||
local text = once(buf_get_full_text)
|
local text = once(buf_get_full_text)
|
||||||
for_each_buffer_client(bufnr, function(client)
|
for_each_buffer_client(bufnr, function(client)
|
||||||
local name = api.nvim_buf_get_name(bufnr)
|
local name = api.nvim_buf_get_name(bufnr)
|
||||||
local old_uri = changetracking._get_and_set_uri(client, bufnr, uri)
|
local old_name = changetracking._get_and_set_name(client, bufnr, name)
|
||||||
if old_uri and name ~= old_uri then
|
if old_name and name ~= old_name then
|
||||||
client.notify('textDocument/didClose', {
|
|
||||||
textDocument = {
|
|
||||||
uri = old_uri,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
client.notify('textDocument/didOpen', {
|
client.notify('textDocument/didOpen', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
version = 0,
|
version = 0,
|
||||||
@@ -1720,12 +1694,8 @@ function lsp.buf_attach_client(bufnr, client_id)
|
|||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
on_detach = function()
|
on_detach = function()
|
||||||
|
local params = { textDocument = { uri = uri } }
|
||||||
for_each_buffer_client(bufnr, function(client, _)
|
for_each_buffer_client(bufnr, function(client, _)
|
||||||
local params = {
|
|
||||||
textDocument = {
|
|
||||||
uri = changetracking._get_uri(client, bufnr),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
changetracking.reset_buf(client, bufnr)
|
changetracking.reset_buf(client, bufnr)
|
||||||
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
|
||||||
client.notify('textDocument/didClose', params)
|
client.notify('textDocument/didClose', params)
|
||||||
|
@@ -2032,12 +2032,7 @@ end
|
|||||||
---@returns `TextDocumentIdentifier`
|
---@returns `TextDocumentIdentifier`
|
||||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
|
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
|
||||||
function M.make_text_document_params(bufnr)
|
function M.make_text_document_params(bufnr)
|
||||||
bufnr = bufnr or 0
|
return { uri = vim.uri_from_bufnr(bufnr or 0) }
|
||||||
local uri = vim.uri_from_bufnr(bufnr)
|
|
||||||
if not uv.fs_stat(api.nvim_buf_get_name(bufnr)) then
|
|
||||||
uri = uri:gsub('^file://', 'buffer://')
|
|
||||||
end
|
|
||||||
return { uri = uri }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create the workspace params
|
--- Create the workspace params
|
||||||
@@ -2070,7 +2065,7 @@ function M.make_formatting_params(options)
|
|||||||
insertSpaces = vim.bo.expandtab,
|
insertSpaces = vim.bo.expandtab,
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
textDocument = M.make_text_document_params(0),
|
textDocument = { uri = vim.uri_from_bufnr(0) },
|
||||||
options = options,
|
options = options,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@@ -272,7 +272,6 @@ function tests.text_document_save_did_open()
|
|||||||
end;
|
end;
|
||||||
body = function()
|
body = function()
|
||||||
notify('start')
|
notify('start')
|
||||||
expect_notification('textDocument/didClose')
|
|
||||||
expect_notification('textDocument/didOpen')
|
expect_notification('textDocument/didOpen')
|
||||||
expect_notification('textDocument/didSave')
|
expect_notification('textDocument/didSave')
|
||||||
notify('shutdown')
|
notify('shutdown')
|
||||||
@@ -293,8 +292,6 @@ function tests.text_document_sync_save_bool()
|
|||||||
end;
|
end;
|
||||||
body = function()
|
body = function()
|
||||||
notify('start')
|
notify('start')
|
||||||
expect_notification('textDocument/didClose')
|
|
||||||
expect_notification('textDocument/didOpen')
|
|
||||||
expect_notification('textDocument/didSave', {textDocument = { uri = "file://" }})
|
expect_notification('textDocument/didSave', {textDocument = { uri = "file://" }})
|
||||||
notify('shutdown')
|
notify('shutdown')
|
||||||
end;
|
end;
|
||||||
@@ -316,8 +313,6 @@ function tests.text_document_sync_save_includeText()
|
|||||||
end;
|
end;
|
||||||
body = function()
|
body = function()
|
||||||
notify('start')
|
notify('start')
|
||||||
expect_notification('textDocument/didClose')
|
|
||||||
expect_notification('textDocument/didOpen')
|
|
||||||
expect_notification('textDocument/didSave', {
|
expect_notification('textDocument/didSave', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "file://"
|
uri = "file://"
|
||||||
@@ -464,7 +459,7 @@ function tests.basic_check_buffer_open()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
@@ -491,13 +486,13 @@ function tests.basic_check_buffer_open_and_change()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 3;
|
version = 3;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -527,13 +522,13 @@ function tests.basic_check_buffer_open_and_change_noeol()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n");
|
text = table.concat({"testing"; "123"}, "\n");
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 3;
|
version = 3;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -562,13 +557,13 @@ function tests.basic_check_buffer_open_and_change_multi()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 3;
|
version = 3;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -577,7 +572,7 @@ function tests.basic_check_buffer_open_and_change_multi()
|
|||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 4;
|
version = 4;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -607,13 +602,13 @@ function tests.basic_check_buffer_open_and_change_multi_and_close()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 3;
|
version = 3;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -622,7 +617,7 @@ function tests.basic_check_buffer_open_and_change_multi_and_close()
|
|||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 4;
|
version = 4;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -631,7 +626,7 @@ function tests.basic_check_buffer_open_and_change_multi_and_close()
|
|||||||
})
|
})
|
||||||
expect_notification('textDocument/didClose', {
|
expect_notification('textDocument/didClose', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification("finish")
|
expect_notification("finish")
|
||||||
@@ -665,13 +660,13 @@ function tests.basic_check_buffer_open_and_change_incremental()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
text = table.concat({"testing"; "123"}, "\n") .. '\n';
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 3;
|
version = 3;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
@@ -708,13 +703,13 @@ function tests.basic_check_buffer_open_and_change_incremental_editing()
|
|||||||
textDocument = {
|
textDocument = {
|
||||||
languageId = "";
|
languageId = "";
|
||||||
text = table.concat({"testing"; "123"}, "\n");
|
text = table.concat({"testing"; "123"}, "\n");
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 0;
|
version = 0;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
expect_notification('textDocument/didChange', {
|
expect_notification('textDocument/didChange', {
|
||||||
textDocument = {
|
textDocument = {
|
||||||
uri = "buffer://";
|
uri = "file://";
|
||||||
version = 3;
|
version = 3;
|
||||||
};
|
};
|
||||||
contentChanges = {
|
contentChanges = {
|
||||||
|
Reference in New Issue
Block a user