mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
feat(lsp): add triggerKind option for vim.lsp.buf.code_action (#21905)
This commit is contained in:
@@ -1022,6 +1022,8 @@ code_action({options}) *vim.lsp.buf.code_action()*
|
|||||||
• only (table|nil): List of LSP `CodeActionKind`s used to
|
• only (table|nil): List of LSP `CodeActionKind`s used to
|
||||||
filter the code actions. Most language servers support
|
filter the code actions. Most language servers support
|
||||||
values like `refactor` or `quickfix`.
|
values like `refactor` or `quickfix`.
|
||||||
|
• triggerKind (number|nil): The reason why code actions
|
||||||
|
were requested.
|
||||||
|
|
||||||
• filter: (function|nil) Predicate taking an `CodeAction`
|
• filter: (function|nil) Predicate taking an `CodeAction`
|
||||||
and returning a boolean.
|
and returning a boolean.
|
||||||
@@ -1036,6 +1038,7 @@ code_action({options}) *vim.lsp.buf.code_action()*
|
|||||||
|
|
||||||
See also: ~
|
See also: ~
|
||||||
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
|
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
|
||||||
|
vim.lsp.protocol.constants.CodeActionTriggerKind
|
||||||
|
|
||||||
completion({context}) *vim.lsp.buf.completion()*
|
completion({context}) *vim.lsp.buf.completion()*
|
||||||
Retrieves the completion items at the current cursor position. Can only be
|
Retrieves the completion items at the current cursor position. Can only be
|
||||||
|
@@ -733,6 +733,7 @@ end
|
|||||||
--- List of LSP `CodeActionKind`s used to filter the code actions.
|
--- List of LSP `CodeActionKind`s used to filter the code actions.
|
||||||
--- Most language servers support values like `refactor`
|
--- Most language servers support values like `refactor`
|
||||||
--- or `quickfix`.
|
--- or `quickfix`.
|
||||||
|
--- - triggerKind (number|nil): The reason why code actions were requested.
|
||||||
--- - filter: (function|nil)
|
--- - filter: (function|nil)
|
||||||
--- Predicate taking an `CodeAction` and returning a boolean.
|
--- Predicate taking an `CodeAction` and returning a boolean.
|
||||||
--- - apply: (boolean|nil)
|
--- - apply: (boolean|nil)
|
||||||
@@ -746,6 +747,7 @@ end
|
|||||||
--- using mark-like indexing. See |api-indexing|
|
--- using mark-like indexing. See |api-indexing|
|
||||||
---
|
---
|
||||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
|
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
|
||||||
|
---@see vim.lsp.protocol.constants.CodeActionTriggerKind
|
||||||
function M.code_action(options)
|
function M.code_action(options)
|
||||||
validate({ options = { options, 't', true } })
|
validate({ options = { options, 't', true } })
|
||||||
options = options or {}
|
options = options or {}
|
||||||
@@ -755,6 +757,9 @@ function M.code_action(options)
|
|||||||
options = { options = options }
|
options = { options = options }
|
||||||
end
|
end
|
||||||
local context = options.context or {}
|
local context = options.context or {}
|
||||||
|
if not context.triggerKind then
|
||||||
|
context.triggerKind = vim.lsp.protocol.CodeActionTriggerKind.Invoked
|
||||||
|
end
|
||||||
if not context.diagnostics then
|
if not context.diagnostics then
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = api.nvim_get_current_buf()
|
||||||
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
|
context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr)
|
||||||
|
@@ -304,6 +304,17 @@ local constants = {
|
|||||||
-- Base kind for an organize imports source action
|
-- Base kind for an organize imports source action
|
||||||
SourceOrganizeImports = 'source.organizeImports',
|
SourceOrganizeImports = 'source.organizeImports',
|
||||||
},
|
},
|
||||||
|
-- The reason why code actions were requested.
|
||||||
|
---@enum lsp.CodeActionTriggerKind
|
||||||
|
CodeActionTriggerKind = {
|
||||||
|
-- Code actions were explicitly requested by the user or by an extension.
|
||||||
|
Invoked = 1,
|
||||||
|
-- Code actions were requested automatically.
|
||||||
|
--
|
||||||
|
-- This typically happens when current selection in a file changes, but can
|
||||||
|
-- also be triggered when file content changes.
|
||||||
|
Automatic = 2,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v in pairs(constants) do
|
for k, v in pairs(constants) do
|
||||||
|
Reference in New Issue
Block a user