mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
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.
This commit is contained in:
@@ -749,15 +749,6 @@ start_client({config}) *vim.lsp.start_client()*
|
||||
|
||||
The following parameters describe fields in the {config}
|
||||
table.
|
||||
>
|
||||
|
||||
-- In init function for the client, you can do:
|
||||
local custom_init = function(client)
|
||||
if client.config.flags then
|
||||
client.config.flags.allow_incremental_sync = true
|
||||
end
|
||||
end
|
||||
<
|
||||
|
||||
Parameters: ~
|
||||
{root_dir} (required, string) Directory where the
|
||||
@@ -856,8 +847,8 @@ start_client({config}) *vim.lsp.start_client()*
|
||||
{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
|
||||
true): Allow using incremental sync
|
||||
for buffer edits
|
||||
|
||||
Return: ~
|
||||
Client id. |vim.lsp.get_client_by_id()| Note: client may
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user