Skip to content

Commit

Permalink
feat(index): add validation for pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhwang91 committed Mar 25, 2021
1 parent fb6bf0c commit fdce47e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lua/hlslens/index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ local function find_hls_qfnr()
return 0
end

local function valid_pat(pat)
if pat == '' then
return false
end
for g in pat:gmatch('.?/') do
if g ~= [[\/]] then
return false
end
end
return true
end

function M.build_index(pattern)
if pattern == '' then
if not valid_pat(pattern) then
return
end

Expand Down Expand Up @@ -55,6 +67,11 @@ function M.build_index(pattern)
end
end

-- don't waste the memory :)
if fn.getqflist({size = 0}).size > 100000 then
return
end

local pos_list = ok and vim.tbl_map(function(item)
return {item.lnum, item.col}
end, fn.getqflist()) or {}
Expand Down

0 comments on commit fdce47e

Please sign in to comment.