Skip to content

Commit a8e4579

Browse files
committed
fix(formatter/grep): normalize grep input handling
Normalize parts in resolve_grep_string to safely convert nil, vim.NIL, numbers, and booleans to strings and prefer input.path over input.include when present. This prevents invalid grep strings from non-string inputs.
1 parent b9a201c commit a8e4579

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

lua/opencode/ui/formatter/tools/grep.lua

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,30 @@ local M = {}
44
---@param input GrepToolInput|nil
55
---@return string
66
local function resolve_grep_string(input)
7+
local function normalize_part(value)
8+
if value == nil or value == vim.NIL then
9+
return ''
10+
end
11+
12+
local value_type = type(value)
13+
if value_type == 'string' then
14+
return value
15+
end
16+
if value_type == 'number' or value_type == 'boolean' then
17+
return tostring(value)
18+
end
19+
20+
return ''
21+
end
22+
723
if not input then
824
return ''
925
end
10-
local path_part = input.path or input.include or ''
11-
local pattern_part = input.pattern or ''
26+
local path_part = normalize_part(input.path)
27+
if path_part == '' then
28+
path_part = normalize_part(input.include)
29+
end
30+
local pattern_part = normalize_part(input.pattern)
1231
return table.concat(
1332
vim.tbl_filter(function(p)
1433
return p ~= nil and p ~= ''

0 commit comments

Comments
 (0)