Merge pull request #14106 from mfussenegger/lsp-incremental-sync

lsp: Use incremental sync by default
This commit is contained in:
Michael Lingelbach
2021-03-11 11:43:03 -08:00
committed by GitHub
2 changed files with 10 additions and 32 deletions

View File

@@ -749,15 +749,6 @@ start_client({config}) *vim.lsp.start_client()*
The following parameters describe fields in the {config} The following parameters describe fields in the {config}
table. 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: ~ Parameters: ~
{root_dir} (required, string) Directory where the {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 {flags} A table with flags for the client. The
current (experimental) flags are: current (experimental) flags are:
• allow_incremental_sync (bool, default • allow_incremental_sync (bool, default
false): Allow using on_line callbacks true): Allow using incremental sync
for lsp for buffer edits
Return: ~ Return: ~
Client id. |vim.lsp.get_client_by_id()| Note: client may Client id. |vim.lsp.get_client_by_id()| Note: client may

View File

@@ -265,8 +265,11 @@ end
--@param bufnr (Number) Number of the buffer, or 0 for current --@param bufnr (Number) Number of the buffer, or 0 for current
--@param client Client object --@param client Client object
local function text_document_did_open_handler(bufnr, client) local function text_document_did_open_handler(bufnr, client)
local allow_incremental_sync = if_nil(client.config.flags.allow_incremental_sync, false) local use_incremental_sync = (
if allow_incremental_sync then 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 if not client._cached_buffers then
client._cached_buffers = {} client._cached_buffers = {}
end end
@@ -452,16 +455,7 @@ end
--@param trace: "off" | "messages" | "verbose" | nil passed directly to the language --@param trace: "off" | "messages" | "verbose" | nil passed directly to the language
--- server in the initialize request. Invalid/empty values will default to "off" --- 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: --@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 --- - allow_incremental_sync (bool, default true): Allow using incremental sync for buffer edits
---
--- <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>
--- ---
--@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be --@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be
--- fully initialized. Use `on_init` to do any actions once --- fully initialized. Use `on_init` to do any actions once
@@ -858,19 +852,12 @@ do
}; };
end) end)
local uri = vim.uri_from_bufnr(bufnr) local uri = vim.uri_from_bufnr(bufnr)
for_each_buffer_client(bufnr, function(client, _client_id) for_each_buffer_client(bufnr, function(client)
local allow_incremental_sync = if_nil(client.config.flags.allow_incremental_sync, false) 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 text_document_did_change = client.resolved_capabilities.text_document_did_change
local changes local changes
if text_document_did_change == protocol.TextDocumentSyncKind.None then if text_document_did_change == protocol.TextDocumentSyncKind.None then
return 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 elseif not allow_incremental_sync or text_document_did_change == protocol.TextDocumentSyncKind.Full then
changes = full_changes(client) changes = full_changes(client)
elseif text_document_did_change == protocol.TextDocumentSyncKind.Incremental then elseif text_document_did_change == protocol.TextDocumentSyncKind.Incremental then