mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat: Allow incremental sync & lsp flags (#13371)
This commit is contained in:
parent
4383c0f952
commit
08ec36efaf
@ -715,6 +715,15 @@ start_client({config}) *vim.lsp.start_client()*
|
||||
|
||||
The following parameters describe fields in the {config}
|
||||
table.
|
||||
>
|
||||
|
||||
-- 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
|
||||
<
|
||||
|
||||
Parameters: ~
|
||||
{root_dir} (required, string) Directory where the
|
||||
@ -796,6 +805,11 @@ start_client({config}) *vim.lsp.start_client()*
|
||||
in the initialize request.
|
||||
Invalid/empty values will default to
|
||||
"off"
|
||||
{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
|
||||
|
||||
Return: ~
|
||||
Client id. |vim.lsp.get_client_by_id()| Note: client may
|
||||
@ -833,6 +847,12 @@ with({handler}, {override_config}) *vim.lsp.with()*
|
||||
==============================================================================
|
||||
Lua module: vim.lsp.buf *lsp-buf*
|
||||
|
||||
*vim.lsp.buf.add_workspace_folder()*
|
||||
add_workspace_folder({workspace_folder})
|
||||
Add the folder at path to the workspace folders. If {path} is
|
||||
not provided, the user will be prompted for a path using
|
||||
|input()|.
|
||||
|
||||
clear_references() *vim.lsp.buf.clear_references()*
|
||||
Removes document highlights from current buffer.
|
||||
|
||||
@ -935,6 +955,9 @@ incoming_calls() *vim.lsp.buf.incoming_calls()*
|
||||
|quickfix| window. If the symbol can resolve to multiple
|
||||
items, the user can pick one in the |inputlist|.
|
||||
|
||||
list_workspace_folders() *vim.lsp.buf.list_workspace_folders()*
|
||||
List workspace folders.
|
||||
|
||||
outgoing_calls() *vim.lsp.buf.outgoing_calls()*
|
||||
Lists all the items that are called by the symbol under the
|
||||
cursor in the |quickfix| window. If the symbol can resolve to
|
||||
@ -974,6 +997,12 @@ references({context}) *vim.lsp.buf.references()*
|
||||
See also: ~
|
||||
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
||||
|
||||
*vim.lsp.buf.remove_workspace_folder()*
|
||||
remove_workspace_folder({workspace_folder})
|
||||
Remove the folder at path from the workspace folders. If
|
||||
{path} is not provided, the user will be prompted for a path
|
||||
using |input()|.
|
||||
|
||||
rename({new_name}) *vim.lsp.buf.rename()*
|
||||
Renames all references to the symbol under the cursor.
|
||||
|
||||
@ -996,19 +1025,6 @@ type_definition() *vim.lsp.buf.type_definition()*
|
||||
Jumps to the definition of the type of the symbol under the
|
||||
cursor.
|
||||
|
||||
add_workspace_folder({path}) *vim.lsp.buf.add_workspace_folder()*
|
||||
Add the folder at path to the workspace folders. If {path} is
|
||||
not provided, the user will be prompted for a path using
|
||||
|input()|.
|
||||
|
||||
remove_workspace_folder({path}) *vim.lsp.buf.remove_workspace_folder()*
|
||||
Remove the folder at path from the workspace folders. If
|
||||
{path} is not provided, the user will be prompted for
|
||||
a path using |input()|.
|
||||
|
||||
list_workspace_folders() *vim.lsp.buf.list_workspace_folders()*
|
||||
List all folders in the workspace.
|
||||
|
||||
workspace_symbol({query}) *vim.lsp.buf.workspace_symbol()*
|
||||
Lists all symbols in the current workspace in the quickfix
|
||||
window.
|
||||
@ -1062,9 +1078,9 @@ get_count({bufnr}, {severity}, {client_id})
|
||||
let sl = ''
|
||||
if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
|
||||
let sl.='%#MyStatuslineLSP#E:'
|
||||
let sl.='%#MyStatuslineLSPErrors#%{luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Error]])")}'
|
||||
let sl.='%#MyStatuslineLSPErrors#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Error]])")}'
|
||||
let sl.='%#MyStatuslineLSP# W:'
|
||||
let sl.='%#MyStatuslineLSPWarnings#%{luaeval("vim.lsp.diagnostic.get_count(vim.fn.bufnr('%'), [[Warning]])")}'
|
||||
let sl.='%#MyStatuslineLSPWarnings#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Warning]])")}'
|
||||
else
|
||||
let sl.='%#MyStatuslineLSPErrors#off'
|
||||
endif
|
||||
@ -1654,6 +1670,14 @@ make_text_document_params() *vim.lsp.util.make_text_document_params()*
|
||||
See also: ~
|
||||
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
|
||||
|
||||
*vim.lsp.util.make_workspace_params()*
|
||||
make_workspace_params({added}, {removed})
|
||||
Create the workspace params
|
||||
|
||||
Parameters: ~
|
||||
{added}
|
||||
{removed}
|
||||
|
||||
*vim.lsp.util.open_floating_preview()*
|
||||
open_floating_preview({contents}, {filetype}, {opts})
|
||||
Shows contents in a floating window.
|
||||
|
@ -1,3 +1,5 @@
|
||||
local if_nil = vim.F.if_nil
|
||||
|
||||
local default_handlers = require 'vim.lsp.handlers'
|
||||
local log = require 'vim.lsp.log'
|
||||
local lsp_rpc = require 'vim.lsp.rpc'
|
||||
@ -226,6 +228,7 @@ local function validate_client_config(config)
|
||||
on_init = { config.on_init, "f", true };
|
||||
before_init = { config.before_init, "f", true };
|
||||
offset_encoding = { config.offset_encoding, "s", true };
|
||||
flags = { config.flags, "t", true };
|
||||
}
|
||||
|
||||
-- TODO(remove-callbacks)
|
||||
@ -434,6 +437,17 @@ 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>
|
||||
---
|
||||
--@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be
|
||||
--- fully initialized. Use `on_init` to do any actions once
|
||||
@ -442,6 +456,8 @@ function lsp.start_client(config)
|
||||
local cleaned_config = validate_client_config(config)
|
||||
local cmd, cmd_args, offset_encoding = cleaned_config.cmd, cleaned_config.cmd_args, cleaned_config.offset_encoding
|
||||
|
||||
config.flags = config.flags or {}
|
||||
|
||||
local client_id = next_client_id()
|
||||
|
||||
-- TODO(remove-callbacks)
|
||||
@ -799,6 +815,7 @@ do
|
||||
local size_index = encoding_index[client.offset_encoding]
|
||||
local length = select(size_index, old_byte_size, old_utf16_size, old_utf32_size)
|
||||
local lines = nvim_buf_get_lines(bufnr, firstline, new_lastline, true)
|
||||
|
||||
-- This is necessary because we are specifying the full line including the
|
||||
-- newline in range. Therefore, we must replace the newline as well.
|
||||
if #lines > 0 then
|
||||
@ -820,6 +837,8 @@ 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)
|
||||
|
||||
local text_document_did_change = client.resolved_capabilities.text_document_did_change
|
||||
local changes
|
||||
if text_document_did_change == protocol.TextDocumentSyncKind.None then
|
||||
@ -830,7 +849,7 @@ do
|
||||
-- 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 true 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)
|
||||
elseif text_document_did_change == protocol.TextDocumentSyncKind.Incremental then
|
||||
changes = incremental_changes(client)
|
||||
|
@ -239,6 +239,7 @@ function M.outgoing_calls()
|
||||
end
|
||||
|
||||
--- List workspace folders.
|
||||
---
|
||||
function M.list_workspace_folders()
|
||||
local workspace_folders = {}
|
||||
for _, client in ipairs(vim.lsp.buf_get_clients()) do
|
||||
@ -249,7 +250,8 @@ function M.list_workspace_folders()
|
||||
return workspace_folders
|
||||
end
|
||||
|
||||
--- Add a workspace folder.
|
||||
--- Add the folder at path to the workspace folders. If {path} is
|
||||
--- not provided, the user will be prompted for a path using |input()|.
|
||||
function M.add_workspace_folder(workspace_folder)
|
||||
workspace_folder = workspace_folder or npcall(vfn.input, "Workspace Folder: ", vfn.expand('%:p:h'))
|
||||
vim.api.nvim_command("redraw")
|
||||
@ -275,7 +277,9 @@ function M.add_workspace_folder(workspace_folder)
|
||||
end
|
||||
end
|
||||
|
||||
--- Remove a workspace folder.
|
||||
--- Remove the folder at path from the workspace folders. If
|
||||
--- {path} is not provided, the user will be prompted for
|
||||
--- a path using |input()|.
|
||||
function M.remove_workspace_folder(workspace_folder)
|
||||
workspace_folder = workspace_folder or npcall(vfn.input, "Workspace Folder: ", vfn.expand('%:p:h'))
|
||||
vim.api.nvim_command("redraw")
|
||||
|
@ -400,9 +400,9 @@ end
|
||||
--- let sl = ''
|
||||
--- if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
|
||||
--- let sl.='%#MyStatuslineLSP#E:'
|
||||
--- let sl.='%#MyStatuslineLSPErrors#%{luaeval("vim.lsp.diagnostic.get_count([[Error]])")}'
|
||||
--- let sl.='%#MyStatuslineLSPErrors#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Error]])")}'
|
||||
--- let sl.='%#MyStatuslineLSP# W:'
|
||||
--- let sl.='%#MyStatuslineLSPWarnings#%{luaeval("vim.lsp.diagnostic.get_count([[Warning]])")}'
|
||||
--- let sl.='%#MyStatuslineLSPWarnings#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Warning]])")}'
|
||||
--- else
|
||||
--- let sl.='%#MyStatuslineLSPErrors#off'
|
||||
--- endif
|
||||
|
@ -1315,6 +1315,9 @@ function M.make_text_document_params()
|
||||
return { uri = vim.uri_from_bufnr(0) }
|
||||
end
|
||||
|
||||
--- Create the workspace params
|
||||
--@param added
|
||||
--@param removed
|
||||
function M.make_workspace_params(added, removed)
|
||||
return { event = { added = added; removed = removed; } }
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user