mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
fix(lsp): use vim.notify
with action-less showMessage
requests (#34720)
This commit is contained in:
committed by
GitHub
parent
38aac21083
commit
807bc00dd6
@ -28,6 +28,22 @@ local function err_message(...)
|
|||||||
api.nvim_command('redraw')
|
api.nvim_command('redraw')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param params lsp.ShowMessageParams|lsp.ShowMessageRequestParams
|
||||||
|
--- @param ctx lsp.HandlerContext
|
||||||
|
local function show_message_notification(params, ctx)
|
||||||
|
local message_type = params.type
|
||||||
|
local message = params.message
|
||||||
|
local client_id = ctx.client_id
|
||||||
|
local client = vim.lsp.get_client_by_id(client_id)
|
||||||
|
local client_name = client and client.name or string.format('id=%d', client_id)
|
||||||
|
if not client then
|
||||||
|
err_message('LSP[', client_name, '] client has shut down after sending ', message)
|
||||||
|
end
|
||||||
|
message = ('LSP[%s] %s'):format(client_name, message)
|
||||||
|
vim.notify(message, log._from_lsp_level(message_type))
|
||||||
|
return params
|
||||||
|
end
|
||||||
|
|
||||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
||||||
RCS[ms.workspace_executeCommand] = function(_, _, _)
|
RCS[ms.workspace_executeCommand] = function(_, _, _)
|
||||||
-- Error handling is done implicitly by wrapping all handlers; see end of this file
|
-- Error handling is done implicitly by wrapping all handlers; see end of this file
|
||||||
@ -85,38 +101,43 @@ end
|
|||||||
|
|
||||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
|
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
|
||||||
---@param params lsp.ShowMessageRequestParams
|
---@param params lsp.ShowMessageRequestParams
|
||||||
RSC[ms.window_showMessageRequest] = function(_, params)
|
RSC[ms.window_showMessageRequest] = function(_, params, ctx)
|
||||||
local actions = params.actions or {}
|
if next(params.actions or {}) then
|
||||||
local co, is_main = coroutine.running()
|
local co, is_main = coroutine.running()
|
||||||
if co and not is_main then
|
if co and not is_main then
|
||||||
local opts = {
|
local opts = {
|
||||||
kind = 'lsp_message',
|
kind = 'lsp_message',
|
||||||
prompt = params.message .. ': ',
|
prompt = params.message .. ': ',
|
||||||
format_item = function(action)
|
format_item = function(action)
|
||||||
return (action.title:gsub('\r\n', '\\r\\n')):gsub('\n', '\\n')
|
return (action.title:gsub('\r\n', '\\r\\n')):gsub('\n', '\\n')
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
vim.ui.select(actions, opts, function(choice)
|
vim.ui.select(params.actions, opts, function(choice)
|
||||||
-- schedule to ensure resume doesn't happen _before_ yield with
|
-- schedule to ensure resume doesn't happen _before_ yield with
|
||||||
-- default synchronous vim.ui.select
|
-- default synchronous vim.ui.select
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
coroutine.resume(co, choice or vim.NIL)
|
coroutine.resume(co, choice or vim.NIL)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
return coroutine.yield()
|
||||||
return coroutine.yield()
|
|
||||||
else
|
|
||||||
local option_strings = { params.message, '\nRequest Actions:' }
|
|
||||||
for i, action in ipairs(actions) do
|
|
||||||
local title = action.title:gsub('\r\n', '\\r\\n')
|
|
||||||
title = title:gsub('\n', '\\n')
|
|
||||||
table.insert(option_strings, string.format('%d. %s', i, title))
|
|
||||||
end
|
|
||||||
local choice = vim.fn.inputlist(option_strings)
|
|
||||||
if choice < 1 or choice > #actions then
|
|
||||||
return vim.NIL
|
|
||||||
else
|
else
|
||||||
return actions[choice]
|
local option_strings = { params.message, '\nRequest Actions:' }
|
||||||
|
for i, action in ipairs(params.actions) do
|
||||||
|
local title = action.title:gsub('\r\n', '\\r\\n')
|
||||||
|
title = title:gsub('\n', '\\n')
|
||||||
|
table.insert(option_strings, string.format('%d. %s', i, title))
|
||||||
|
end
|
||||||
|
local choice = vim.fn.inputlist(option_strings)
|
||||||
|
if choice < 1 or choice > #params.actions then
|
||||||
|
return vim.NIL
|
||||||
|
else
|
||||||
|
return params.actions[choice]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- No actions, just show the message.
|
||||||
|
show_message_notification(params, ctx)
|
||||||
|
return vim.NIL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -580,17 +601,7 @@ end
|
|||||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessage
|
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessage
|
||||||
--- @param params lsp.ShowMessageParams
|
--- @param params lsp.ShowMessageParams
|
||||||
NSC['window/showMessage'] = function(_, params, ctx)
|
NSC['window/showMessage'] = function(_, params, ctx)
|
||||||
local message_type = params.type
|
return show_message_notification(params, ctx)
|
||||||
local message = params.message
|
|
||||||
local client_id = ctx.client_id
|
|
||||||
local client = vim.lsp.get_client_by_id(client_id)
|
|
||||||
local client_name = client and client.name or string.format('id=%d', client_id)
|
|
||||||
if not client then
|
|
||||||
err_message('LSP[', client_name, '] client has shut down after sending ', message)
|
|
||||||
end
|
|
||||||
message = ('LSP[%s] %s'):format(client_name, message)
|
|
||||||
vim.notify(message, log._from_lsp_level(message_type))
|
|
||||||
return params
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @private
|
--- @private
|
||||||
|
Reference in New Issue
Block a user