diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2026-09-24 13:30:07 +0100 |
|---|---|---|
| committer | Lewis Russell <me@lewisr.dev> | 2026-09-25 10:28:19 +0100 |
| commit | d7af8707026968887ea4ee3a4e6fa51fd4372033 (patch) | |
| tree | 19cae6c571311bbd5af56575dcc710485568f7b8 /runtime/lua/vim/treesitter/query.lua | |
| parent | f6aac851ddd82db5241a56ddfb9cc9a9aec8f7e5 (diff) | |
| download | rneovim-d7af8707026968887ea4ee3a4e6fa51fd4372033.tar.gz rneovim-d7af8707026968887ea4ee3a4e6fa51fd4372033.tar.bz2 rneovim-d7af8707026968887ea4ee3a4e6fa51fd4372033.zip | |
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
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
| -rw-r--r-- | runtime/lua/vim/treesitter/query.lua | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua index 38621be625..13be18b9e0 100644 --- a/runtime/lua/vim/treesitter/query.lua +++ b/runtime/lua/vim/treesitter/query.lua @@ -723,34 +723,38 @@ local directive_handlers = { local end_idx = #node_text local start_idx = 1 + local end_line = node_text[end_idx] if trim_end_lines then - while end_idx > 0 and node_text[end_idx]:find('^%s*$') do + while end_line and end_line:find('^%s*$') do end_idx = end_idx - 1 + end_line = node_text[end_idx] end_row = end_row - 1 -- set the end position to the last column of the next line, or 0 if we just trimmed the -- last line - end_col = end_idx > 0 and #node_text[end_idx] or 0 + end_col = end_line and #end_line or 0 end end if trim_end_cols then - if end_idx == 0 then + if not end_line then end_row = start_row end_col = start_col else - local whitespace_start = node_text[end_idx]:find('(%s*)$') + local whitespace_start = assert(end_line:find('(%s*)$')) end_col = (whitespace_start - 1) + (end_idx == 1 and start_col or 0) end end + local start_line = node_text[start_idx] if trim_start_lines then - while start_idx <= end_idx and node_text[start_idx]:find('^%s*$') do + while start_idx <= end_idx and assert(start_line):find('^%s*$') do start_idx = start_idx + 1 + start_line = node_text[start_idx] start_row = start_row + 1 start_col = 0 end end - if trim_start_cols and node_text[start_idx] then - local _, whitespace_end = node_text[start_idx]:find('^(%s*)') + if trim_start_cols and start_line then + local _, whitespace_end = start_line:find('^(%s*)') whitespace_end = whitespace_end or 0 start_col = (start_idx == 1 and start_col or 0) + whitespace_end end |