mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
refactor: create function for deferred loading
The benefit of this is that users only pay for what they use. If e.g.
only `vim.lsp.buf_get_clients()` is called then they don't need to load
all modules under `vim.lsp` which could lead to significant startuptime
saving.
Also `vim.lsp.module` is a bit nicer to user compared to
`require("vim.lsp.module")`.
This isn't used for some nested modules such as `filetype` as it breaks
tests with error messages such as "attempt to index field 'detect'".
It's not entirely certain the reason for this, but it is likely it is
due to filetype being precompiled which would imply deferred loading
isn't needed for performance reasons.
This commit is contained in:
@@ -8,7 +8,7 @@ local ms = protocol.Methods
|
||||
---@return string parsed snippet
|
||||
local function parse_snippet(input)
|
||||
local ok, parsed = pcall(function()
|
||||
return require('vim.lsp._snippet_grammar').parse(input)
|
||||
return vim.lsp._snippet_grammar.parse(input)
|
||||
end)
|
||||
return ok and tostring(parsed) or input
|
||||
end
|
||||
@@ -206,7 +206,7 @@ function M.omnifunc(findstart, base)
|
||||
local params = util.make_position_params(win, client.offset_encoding)
|
||||
client.request(ms.textDocument_completion, params, function(err, result)
|
||||
if err then
|
||||
require('vim.lsp.log').warn(err.message)
|
||||
vim.lsp.log.warn(err.message)
|
||||
end
|
||||
if result and vim.fn.mode() == 'i' then
|
||||
local matches
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local glob = require('vim.glob')
|
||||
local glob = vim.glob
|
||||
|
||||
--- @class lsp.DynamicCapabilities
|
||||
--- @field capabilities table<string, lsp.Registration[]>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local bit = require('bit')
|
||||
local glob = require('vim.glob')
|
||||
local watch = require('vim._watch')
|
||||
local glob = vim.glob
|
||||
local watch = vim._watch
|
||||
local protocol = require('vim.lsp.protocol')
|
||||
local ms = protocol.Methods
|
||||
local lpeg = vim.lpeg
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---@brief lsp-diagnostic
|
||||
|
||||
local util = require('vim.lsp.util')
|
||||
local protocol = require('vim.lsp.protocol')
|
||||
local log = require('vim.lsp.log')
|
||||
local ms = protocol.Methods
|
||||
|
||||
local api = vim.api
|
||||
@@ -95,7 +93,7 @@ local function tags_lsp_to_vim(diagnostic, client_id)
|
||||
tags = tags or {}
|
||||
tags.deprecated = true
|
||||
else
|
||||
log.info(string.format('Unknown DiagnosticTag %d from LSP client %d', tag, client_id))
|
||||
vim.lsp.log.info(string.format('Unknown DiagnosticTag %d from LSP client %d', tag, client_id))
|
||||
end
|
||||
end
|
||||
return tags
|
||||
@@ -425,7 +423,7 @@ end
|
||||
local function _refresh(bufnr, opts)
|
||||
opts = opts or {}
|
||||
opts['bufnr'] = bufnr
|
||||
util._refresh(ms.textDocument_diagnostic, opts)
|
||||
vim.lsp.util._refresh(ms.textDocument_diagnostic, opts)
|
||||
end
|
||||
|
||||
--- Enable pull diagnostics for a buffer
|
||||
|
||||
@@ -120,7 +120,7 @@ M[ms.client_registerCapability] = function(_, result, ctx)
|
||||
local unsupported = {}
|
||||
for _, reg in ipairs(result.registrations) do
|
||||
if reg.method == ms.workspace_didChangeWatchedFiles then
|
||||
require('vim.lsp._watchfiles').register(reg, ctx)
|
||||
vim.lsp._watchfiles.register(reg, ctx)
|
||||
elseif not client.dynamic_capabilities:supports_registration(reg.method) then
|
||||
unsupported[#unsupported + 1] = reg.method
|
||||
end
|
||||
@@ -144,7 +144,7 @@ M[ms.client_unregisterCapability] = function(_, result, ctx)
|
||||
|
||||
for _, unreg in ipairs(result.unregisterations) do
|
||||
if unreg.method == ms.workspace_didChangeWatchedFiles then
|
||||
require('vim.lsp._watchfiles').unregister(unreg, ctx)
|
||||
vim.lsp._watchfiles.unregister(unreg, ctx)
|
||||
end
|
||||
end
|
||||
return vim.NIL
|
||||
@@ -223,19 +223,19 @@ M[ms.workspace_workspaceFolders] = function(_, _, ctx)
|
||||
end
|
||||
|
||||
M[ms.textDocument_publishDiagnostics] = function(...)
|
||||
return require('vim.lsp.diagnostic').on_publish_diagnostics(...)
|
||||
return vim.lsp.diagnostic.on_publish_diagnostics(...)
|
||||
end
|
||||
|
||||
M[ms.textDocument_diagnostic] = function(...)
|
||||
return require('vim.lsp.diagnostic').on_diagnostic(...)
|
||||
return vim.lsp.diagnostic.on_diagnostic(...)
|
||||
end
|
||||
|
||||
M[ms.textDocument_codeLens] = function(...)
|
||||
return require('vim.lsp.codelens').on_codelens(...)
|
||||
return vim.lsp.codelens.on_codelens(...)
|
||||
end
|
||||
|
||||
M[ms.textDocument_inlayHint] = function(...)
|
||||
return require('vim.lsp.inlay_hint').on_inlayhint(...)
|
||||
return vim.lsp.inlay_hint.on_inlayhint(...)
|
||||
end
|
||||
|
||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
||||
@@ -643,7 +643,7 @@ end
|
||||
|
||||
---@see https://microsoft.github.io/language-server-protocol/specification/#workspace_inlayHint_refresh
|
||||
M[ms.workspace_inlayHint_refresh] = function(err, result, ctx, config)
|
||||
return require('vim.lsp.inlay_hint').on_refresh(err, result, ctx, config)
|
||||
return vim.lsp.inlay_hint.on_refresh(err, result, ctx, config)
|
||||
end
|
||||
|
||||
-- Add boilerplate error validation and logging for all of these.
|
||||
|
||||
@@ -5,7 +5,7 @@ function M.check()
|
||||
local report_info = vim.health.info
|
||||
local report_warn = vim.health.warn
|
||||
|
||||
local log = require('vim.lsp.log')
|
||||
local log = vim.lsp.log
|
||||
local current_log_level = log.get_level()
|
||||
local log_level_string = log.levels[current_log_level]
|
||||
report_info(string.format('LSP log level : %s', log_level_string))
|
||||
|
||||
@@ -3,7 +3,7 @@ local snippet = require('vim.lsp._snippet_grammar')
|
||||
local validate = vim.validate
|
||||
local api = vim.api
|
||||
local list_extend = vim.list_extend
|
||||
local highlight = require('vim.highlight')
|
||||
local highlight = vim.highlight
|
||||
local uv = vim.uv
|
||||
|
||||
local npcall = vim.F.npcall
|
||||
@@ -636,7 +636,7 @@ end
|
||||
---@see complete-items
|
||||
function M.text_document_completion_list_to_complete_items(result, prefix)
|
||||
vim.deprecate('vim.lsp.util.text_document_completion_list_to_complete_items()', nil, '0.11')
|
||||
return require('vim.lsp._completion')._lsp_to_complete_items(result, prefix)
|
||||
return vim.lsp._completion._lsp_to_complete_items(result, prefix)
|
||||
end
|
||||
|
||||
--- Like vim.fn.bufwinid except it works across tabpages.
|
||||
|
||||
Reference in New Issue
Block a user