Skip to content

Commit de1308f

Browse files
Lin ZhenyunAntoineGS
authored andcommitted
fix: avoid LSP error with unsupported window/logMessage
Some LSP servers like jsonlsp don't support window/logMessage method, causing potential errors. Move the handler to client config to avoid this. Fixes #389
1 parent 1f893df commit de1308f

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

lua/copilot/client.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,29 @@ local function prepare_client_config(overrides)
222222
PanelSolutionsDone = api.handlers.PanelSolutionsDone,
223223
statusNotification = api.handlers.statusNotification,
224224
["copilot/openURL"] = api.handlers["copilot/openURL"],
225+
-- set up "window/logMessage" handler here instead of in `logger.lua`, since some other lsp servers don't support this method, such as jsonlsp
226+
["window/logMessage"] = function(_, result, _)
227+
if not result then
228+
return
229+
end
230+
231+
local message = string.format("LSP message: %s", result.message)
232+
local message_type = result.type --[[@as integer]]
233+
234+
if message_type == 1 then
235+
logger.error(message)
236+
elseif message_type == 2 then
237+
logger.warn(message)
238+
elseif message_type == 3 then
239+
logger.info(message)
240+
elseif message_type == 4 then
241+
logger.info(message)
242+
elseif message_type == 5 then
243+
logger.debug(message)
244+
else
245+
logger.trace(message)
246+
end
247+
end,
225248
}
226249

227250
local root_dir = config.get_root_dir()

lua/copilot/logger.lua

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,6 @@ function mod.setup(conf)
147147
mod.trace(string.format("LSP progress - token %s", result.token), result.value)
148148
end
149149
end
150-
151-
vim.lsp.handlers["window/logMessage"] = function(_, result, _)
152-
if not result then
153-
return
154-
end
155-
156-
local message = string.format("LSP message: %s", result.message)
157-
local message_type = result.type --[[@as integer]]
158-
159-
if message_type == 1 then
160-
mod.error(message)
161-
elseif message_type == 2 then
162-
mod.warn(message)
163-
elseif message_type == 3 then
164-
mod.info(message)
165-
elseif message_type == 4 then
166-
mod.info(message)
167-
elseif message_type == 5 then
168-
mod.debug(message)
169-
else
170-
mod.trace(message)
171-
end
172-
end
173150
end
174151

175152
return mod

0 commit comments

Comments
 (0)