aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r--runtime/lua/vim/lsp.lua54
1 files changed, 12 insertions, 42 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index c85d38a50e..117b32dc57 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -369,7 +369,7 @@ do
--- @field offset_encoding "utf-8"|"utf-16"|"utf-32"
---
--- @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_tmp string[]
--- @field pending_changes table[] List of debounced changes in incremental sync mode
@@ -488,12 +488,8 @@ do
if buf_state then
buf_state.refs = buf_state.refs + 1
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 = {
- uri = uri,
+ name = api.nvim_buf_get_name(bufnr),
lines = {},
lines_tmp = {},
pending_changes = {},
@@ -508,26 +504,12 @@ do
end
---@private
- ---@param client table
- ---@param bufnr integer
- ---@return string uri
- function changetracking._get_uri(client, bufnr)
- local state = state_by_group[get_group(client)] or {}
- local buf_state = (state.buffers or {})[bufnr]
- return assert(buf_state.uri, 'Must have an URI set')
- end
-
- ---@private
- ---@param client table
- ---@param bufnr integer
- ---@param uri string
- ---@return string uri
- function changetracking._get_and_set_uri(client, bufnr, uri)
+ function changetracking._get_and_set_name(client, bufnr, name)
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
+ local old_name = buf_state.name
+ buf_state.name = name
+ return old_name
end
---@private
@@ -614,7 +596,7 @@ do
{ text = buf_get_full_text(bufnr) },
}
end
- local uri = buf_state.uri
+ local uri = vim.uri_from_bufnr(bufnr)
for _, client in pairs(state.clients) do
if not client.is_stopped() and lsp.buf_is_attached(bufnr, client.id) then
client.notify('textDocument/didChange', {
@@ -727,14 +709,11 @@ local function text_document_did_open_handler(bufnr, client)
return
end
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 = {
textDocument = {
version = 0,
- uri = uri,
+ uri = vim.uri_from_bufnr(bufnr),
languageId = client.config.get_language_id(bufnr, filetype),
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)
for_each_buffer_client(bufnr, function(client)
local name = api.nvim_buf_get_name(bufnr)
- local old_uri = changetracking._get_and_set_uri(client, bufnr, uri)
- if old_uri and name ~= old_uri then
- client.notify('textDocument/didClose', {
- textDocument = {
- uri = old_uri,
- },
- })
+ local old_name = changetracking._get_and_set_name(client, bufnr, name)
+ if old_name and name ~= old_name then
client.notify('textDocument/didOpen', {
textDocument = {
version = 0,
@@ -1720,12 +1694,8 @@ function lsp.buf_attach_client(bufnr, client_id)
end)
end,
on_detach = function()
+ local params = { textDocument = { uri = uri } }
for_each_buffer_client(bufnr, function(client, _)
- local params = {
- textDocument = {
- uri = changetracking._get_uri(client, bufnr),
- },
- }
changetracking.reset_buf(client, bufnr)
if vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'openClose') then
client.notify('textDocument/didClose', params)