aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
diff options
context:
space:
mode:
authorMathias Fussenegger <f.mathias@zignar.net>2021-03-11 16:01:40 +0100
committerMathias Fussenegger <f.mathias@zignar.net>2021-03-11 20:13:52 +0100
commit16827817bb0d16de0fb0ebca5faebe85d53c40a2 (patch)
treec9919d55414ba19be24424721e5b11613466dc02 /runtime/lua/vim/lsp.lua
parent5d20fc4fc5c076455a5c4c07dc297f214f43ee2d (diff)
downloadrneovim-16827817bb0d16de0fb0ebca5faebe85d53c40a2.tar.gz
rneovim-16827817bb0d16de0fb0ebca5faebe85d53c40a2.tar.bz2
rneovim-16827817bb0d16de0fb0ebca5faebe85d53c40a2.zip
lsp: Use incremental sync by default
With the new implementation added in https://github.com/neovim/neovim/pull/14079 I think this is now working well enough to enable it by default. There are high CPU usage issues popping up now and then and they might at least partially be related to the full-text sync.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r--runtime/lua/vim/lsp.lua29
1 files changed, 8 insertions, 21 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 9bc6679228..f0845bfc80 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -265,8 +265,11 @@ end
--@param bufnr (Number) Number of the buffer, or 0 for current
--@param client Client object
local function text_document_did_open_handler(bufnr, client)
- local allow_incremental_sync = if_nil(client.config.flags.allow_incremental_sync, false)
- if allow_incremental_sync then
+ local use_incremental_sync = (
+ if_nil(client.config.flags.allow_incremental_sync, true)
+ and client.resolved_capabilities.text_document_did_change == protocol.TextDocumentSyncKind.Incremental
+ )
+ if use_incremental_sync then
if not client._cached_buffers then
client._cached_buffers = {}
end
@@ -452,16 +455,7 @@ end
--@param trace: "off" | "messages" | "verbose" | nil passed directly to the language
--- server in the initialize request. Invalid/empty values will default to "off"
--@param flags: A table with flags for the client. The current (experimental) flags are:
---- - allow_incremental_sync (bool, default false): Allow using on_line callbacks for lsp
----
---- <pre>
---- -- In attach function for the client, you can do:
---- local custom_attach = function(client)
---- if client.config.flags then
---- client.config.flags.allow_incremental_sync = true
---- end
---- end
---- </pre>
+--- - allow_incremental_sync (bool, default true): Allow using incremental sync for buffer edits
---
--@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be
--- fully initialized. Use `on_init` to do any actions once
@@ -858,19 +852,12 @@ do
};
end)
local uri = vim.uri_from_bufnr(bufnr)
- for_each_buffer_client(bufnr, function(client, _client_id)
- local allow_incremental_sync = if_nil(client.config.flags.allow_incremental_sync, false)
-
+ for_each_buffer_client(bufnr, function(client)
+ local allow_incremental_sync = if_nil(client.config.flags.allow_incremental_sync, true)
local text_document_did_change = client.resolved_capabilities.text_document_did_change
local changes
if text_document_did_change == protocol.TextDocumentSyncKind.None then
return
- --[=[ TODO(ashkan) there seem to be problems with the byte_sizes sent by
- -- neovim right now so only send the full content for now. In general, we
- -- can assume that servers *will* support both versions anyway, as there
- -- is no way to specify the sync capability by the client.
- -- See https://github.com/palantir/python-language-server/commit/cfd6675bc10d5e8dbc50fc50f90e4a37b7178821#diff-f68667852a14e9f761f6ebf07ba02fc8 for an example of pyls handling both.
- --]=]
elseif not allow_incremental_sync or text_document_did_change == protocol.TextDocumentSyncKind.Full then
changes = full_changes(client)
elseif text_document_did_change == protocol.TextDocumentSyncKind.Incremental then