Filter out directories in matcha
This commit is contained in:
parent
497c440216
commit
678fa8827e
1 changed files with 22 additions and 16 deletions
|
@ -6,39 +6,45 @@ local function nextcol(state)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function isfile(path)
|
||||||
|
return vim.fn.isdirectory(path) == 0
|
||||||
|
end
|
||||||
|
|
||||||
local function colmatch(str, pattern)
|
local function colmatch(str, pattern)
|
||||||
return nextcol, {str=str,pattern=pattern,last=0}
|
return nextcol, {str=str,pattern=pattern,last=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function findLocations(pattern, first_glob, ...)
|
local function findLocations(pattern, first_glob, ...)
|
||||||
local files if first_glob then
|
local paths if first_glob then
|
||||||
files = vim.fn.glob(first_glob, false, true)
|
paths = vim.fn.glob(first_glob, false, true)
|
||||||
if ... then
|
if ... then
|
||||||
for _, glob in ipairs { ... } do
|
for _, glob in ipairs { ... } do
|
||||||
for _, file in ipairs(vim.fn.glob(glob, false, true)) do
|
for _, path in ipairs(vim.fn.glob(glob, false, true)) do
|
||||||
-- Assume overhead of table.insert is outweighed by all the file ops anyway
|
-- Assume overhead of table.insert is outweighed by all the file ops anyway
|
||||||
table.insert(files, file)
|
table.insert(paths, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
files = vim.fn.argv()
|
paths = vim.fn.argv()
|
||||||
end
|
end
|
||||||
|
|
||||||
local locations = {}
|
local locations = {}
|
||||||
|
|
||||||
for _, file in ipairs(files) do
|
for _, path in ipairs(paths) do
|
||||||
local lnum = 0
|
local lnum = 0
|
||||||
for line in io.lines(file) do
|
if isfile(path) then
|
||||||
lnum = lnum + 1
|
for line in io.lines(path) do
|
||||||
for from, to in colmatch(line, pattern) do
|
lnum = lnum + 1
|
||||||
table.insert(locations, {
|
for from, to in colmatch(line, pattern) do
|
||||||
filename = file;
|
table.insert(locations, {
|
||||||
lnum = lnum;
|
filename = path;
|
||||||
col = from;
|
lnum = lnum;
|
||||||
end_col = to;
|
col = from;
|
||||||
text = line:sub(from, to)
|
end_col = to;
|
||||||
})
|
text = line:sub(from, to)
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue