From 24b0fbed65cd0fb891b4c660716e7dca118cf935 Mon Sep 17 00:00:00 2001 From: Michiel van den Heuvel Date: Mon, 12 May 2025 12:32:23 +0200 Subject: Check lsp return value is table in handlers At least in lua-cjson, null is sometimes returned as a (light) userdata value. This resulted in ugly errors. --- init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 3674990..2c91114 100644 --- a/init.lua +++ b/init.lua @@ -725,7 +725,7 @@ function LanguageServer:call_text_document_method(method, params, win, ctx) end local function lspc_handle_goto_method_response(req, result) - if not result or next(result) == nil then + if not result or type(result) ~= 'table' or next(result) == nil then lspc:warn(req.method .. ' found no results') return end @@ -772,7 +772,7 @@ local function lspc_handle_goto_method_response(req, result) end local function lspc_handle_completion_method_response(win, result, old_pos) - if not result or not result.items then + if not result or type(result) ~= 'table' or not result.items then lspc:warn('no completion available') return end @@ -860,7 +860,7 @@ local function lspc_handle_completion_method_response(win, result, old_pos) end local function lspc_handle_hover_method_response(win, result, old_pos) - if not result or not result.contents then + if not result or type(result) ~= 'table' or not result.contents then lspc:warn('no hover available') return end @@ -894,7 +894,7 @@ local function lspc_handle_hover_method_response(win, result, old_pos) end local function lspc_handle_signature_help_method_response(win, result, call_pos) - if not result or not result.signatures or #result.signatures == 0 then + if not result or type(result) ~= 'table' or not result.signatures or #result.signatures == 0 then lspc:warn('no signature help available') return end -- cgit v1.2.3