From d7af8707026968887ea4ee3a4e6fa51fd4372033 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 24 Sep 2026 13:30:07 +0100 Subject: fix(lua): enable nil-safety diagnostics in runtime code Enable EmmyLua's need-check-nil diagnostic and resolve nullable values through more precise types, explicit invariants, and guards for missing runtime state. Keep analyzer-specific workarounds local and update the affected API documentation. Exclude the bundled re.lua from analysis so its nil-check warnings do not fail CI. AI-assisted --- runtime/lua/vim/lsp.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp.lua') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index d30ab8fd36..1a633924fa 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -343,6 +343,7 @@ lsp.config = setmetatable({ _configs = {} }, { -- Calls to vim.lsp.config in lsp/* have a lower precedence than calls from other sites. local rtp_config --- @type vim.lsp.Config? for _, v in ipairs(api.nvim_get_runtime_file(('lsp/%s.lua'):format(name), true)) do + --- @diagnostic disable-next-line: need-check-nil EmmyLuaLs/emmylua-analyzer-rust#1259 local config = assert(loadfile(v))() ---@type any? if type(config) == 'table' then --- @type vim.lsp.Config? @@ -1412,7 +1413,7 @@ function lsp.formatexpr(opts) local params = util.make_formatting_params() local method ---@type vim.lsp.protocol.Method.ClientToServer.Request? if client:supports_method('textDocument/rangeFormatting') then - local end_line = vim.fn.getline(end_lnum) --[[@as string]] + local end_line = vim.fn.getline(end_lnum) local end_col = vim.str_utfindex(end_line, client.offset_encoding) --- @cast params +lsp.DocumentRangeFormattingParams params.range = { -- cgit