Skip to content

Commit a125fa5

Browse files
committed
fix(tags): ctags adjustments for windows
1 parent 87f83f0 commit a125fa5

File tree

6 files changed

+45
-17
lines changed

6 files changed

+45
-17
lines changed

lua/fzf-lua/core.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,17 @@ M.build_fzf_cli = function(opts)
534534
for k, v in pairs(opts.fzf_opts) do
535535
-- flag can be set to `false` to negate a default
536536
if v then
537-
if utils.__IS_WINDOWS and type(v) == "string" and v:match([[^'.*'$]]) then
538-
-- replace single quote shellescape
539-
-- TODO: replace all so we never get here
540-
v = [["]] .. v:sub(2, #v - 1) .. [["]]
541-
end
542537
table.insert(cli_args, k)
543538
if type(v) == "string" or type(v) == "number" then
544539
v = tostring(v) -- convert number type to string
545540
if k == "--query" then
546541
table.insert(cli_args, libuv.shellescape(v))
547542
else
543+
if utils.__IS_WINDOWS and type(v) == "string" and v:match([[^'.*'$]]) then
544+
-- replace single quote shellescape
545+
-- TODO: replace all so we never get here
546+
v = [["]] .. v:sub(2, #v - 1) .. [["]]
547+
end
548548
if libuv.is_escaped(v) then
549549
utils.warn(string.format("`fzf_opts` are automatically shellescaped."
550550
.. " Please remove surrounding quotes from %s=%s", k, v))

lua/fzf-lua/make_entry.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,21 @@ M.preprocess = function(opts)
384384
-- This changes slightly if you are running with DelayedExpansion of variables:
385385
-- if any part of the command line includes an '!' then CMD will escape a second
386386
-- time, so ^^^^ will become ^
387-
opts.cmd = opts.cmd:gsub('[%(%)%%!%^<>&|"]', function(x)
388-
return "^" .. x
389-
end)
390-
-- make sure all ! are escaped at least twice
391-
opts.cmd = opts.cmd:gsub("[^%^]%^!", function(x)
392-
return x:sub(1, 1) .. "^" .. x:sub(2)
393-
end)
387+
-- replace in sections, only double the relevant pipe sections with !
388+
local escaped_cmd = {}
389+
for _, str in ipairs(utils.strsplit(opts.cmd, "%s+|")) do
390+
if str:match("!") then
391+
str = str:gsub('[%(%)%%!%^<>&|"]', function(x)
392+
return "^" .. x
393+
end)
394+
-- make sure all ! are escaped at least twice
395+
str = str:gsub("[^%^]%^!", function(x)
396+
return x:sub(1, 1) .. "^" .. x:sub(2)
397+
end)
398+
end
399+
table.insert(escaped_cmd, str)
400+
end
401+
opts.cmd = table.concat(escaped_cmd, " |")
394402
end
395403

396404
return opts

lua/fzf-lua/path.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ local function stripBeforeLastOccurrenceOf(str, sep)
331331
end
332332

333333
function M.entry_to_ctag(entry, noesc)
334-
local ctag = entry:match("%:.-/^?\t?(.*)/")
334+
local ctag = entry:match("%:.-[/\\]^?\t?(.*)[/\\]")
335335
-- if tag name contains a slash we could
336336
-- have the wrong match, most tags start
337337
-- with ^ so try to match based on that
338-
ctag = ctag and ctag:match("/^(.*)") or ctag
338+
ctag = ctag and ctag:match("[/\\]^(.*)") or ctag
339339
if ctag and not noesc then
340340
-- required escapes for vim.fn.search()
341341
-- \ ] ~ *

lua/fzf-lua/providers/grep.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ M.grep = function(opts)
113113
end
114114
end
115115

116+
if utils.__IS_WINDOWS and opts.search and opts.search:match("[;,]") then
117+
-- TODO: having [;,] in the search errs the NEQ exec_empty_query condition
118+
opts.exec_empty_query = true
119+
end
120+
116121
-- get the grep command before saving the last search
117122
-- in case the search string is overwritten by 'rg_glob'
118123
opts.cmd = get_grep_cmd(opts, opts.search, opts.no_esc)
@@ -196,6 +201,11 @@ local function normalize_live_grep_opts(opts)
196201
end
197202
end
198203

204+
if utils.__IS_WINDOWS and opts.query:match("[;,]") then
205+
-- TODO: having [;,] in the search errs the NEQ exec_empty_query condition
206+
opts.exec_empty_query = true
207+
end
208+
199209
return opts
200210
end
201211

lua/fzf-lua/providers/tags.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ local function get_tags_cmd(opts)
1919
if opts.filename and #opts.filename > 0 then
2020
-- tags use relative paths, by now we should
2121
-- have the correct cwd from `get_ctags_cwd`
22-
query = libuv.shellescape(path.relative_to(opts.filename, opts.cwd or vim.loop.cwd()))
22+
query = libuv.shellescape(
23+
utils.rg_escape(path.relative_to(opts.filename, opts.cwd or vim.loop.cwd())))
2324
elseif opts.search and #opts.search > 0 then
2425
filter = ([[%s -v "^!"]]):format(bin)
2526
query = libuv.shellescape(opts.no_esc and opts.search or

lua/fzf-lua/utils.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,17 @@ end
110110
---@return string[]
111111
M.strsplit = function(inputstr, sep)
112112
local t = {}
113-
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
114-
table.insert(t, str)
113+
if #sep == 1 then
114+
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
115+
table.insert(t, str)
116+
end
117+
else
118+
local s, m, r = inputstr, nil, nil
119+
repeat
120+
m, r = s:match("^(.-)" .. sep .. "(.*)$")
121+
s = r and r or s
122+
table.insert(t, m or s)
123+
until not m
115124
end
116125
return t
117126
end

0 commit comments

Comments
 (0)