fix(lsp): send didClose on buffer rename (#22623)

Subset of https://github.com/neovim/neovim/pull/22407 that was reverted
in https://github.com/neovim/neovim/pull/22604

If a buffer is renamed sending `didClose` for the old buffer helps
ensure the language server doesn't keep a stale document in memory.
This commit is contained in:
Mathias Fußenegger 2023-03-11 14:50:14 +01:00 committed by GitHub
parent 865d8d4720
commit 23dc2a59b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -1,3 +1,4 @@
---@diagnostic disable: invisible
local default_handlers = require('vim.lsp.handlers')
local log = require('vim.lsp.log')
local lsp_rpc = require('vim.lsp.rpc')
@ -1592,6 +1593,11 @@ local function text_document_did_save_handler(bufnr)
local name = api.nvim_buf_get_name(bufnr)
local old_name = changetracking._get_and_set_name(client, bufnr, name)
if old_name and name ~= old_name then
client.notify('textDocument/didClose', {
textDocument = {
uri = vim.uri_from_fname(old_name),
},
})
client.notify('textDocument/didOpen', {
textDocument = {
version = 0,

View File

@ -272,6 +272,7 @@ function tests.text_document_save_did_open()
end;
body = function()
notify('start')
expect_notification('textDocument/didClose')
expect_notification('textDocument/didOpen')
expect_notification('textDocument/didSave')
notify('shutdown')