Fix pcre2 issue with ripgrep (closes #145) (#148)

* fix(tags): fix rg command if PCRE not available (closes #145)

Some linux distro do not compile ripgrep using the --pcre2 flag.
This commit checks if the --pcre2 flag is available and then tweaks the
ripgrep command accordingly.

At the moment, it will therefore not be possible to filter-out
hexademical color codes from #tags for people that do not have the
--pcre2 flag available. This will be documented in a later commit.

**Important**: the detection of the PCRE availability is done by trying
a simple rg search using _os.execute_. This function interface was
changed in Lua 5.2, which means it will break when Neovim will update to
Lua >5.1. The fix is already there in commented form.

Fixes #145

* refact: cleanup

* doc(tag): add note about rg --pcre2

* doc(tag): add note about rg --pcre2 in vim help
This commit is contained in:
lambtho
2022-06-26 17:49:19 +00:00
committed by GitHub
parent 440033919e
commit 994a44999f
4 changed files with 56 additions and 6 deletions

View File

@@ -1,7 +1,9 @@
local Job = require("plenary.job")
local M = {}
local hashtag_re =
local hashtag_re = "(^|\\s|'|\")#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*"
-- PCRE hashtag allows to remove the hex color codes from hastags
local hashtag_re_pcre =
"(^|\\s|'|\")((?!(#[a-fA-F0-9]{3})(\\W|$)|(#[a-fA-F0-9]{6})(\\W|$))#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*)"
local colon_re = "(^|\\s):[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*:"
local yaml_re =
@@ -11,6 +13,7 @@ local function command_find_all_tags(opts)
opts = opts or {}
opts.cwd = opts.cwd or "."
opts.templateDir = opts.templateDir or ""
opts.rg_pcre = opts.rg_pcre or false
-- do not list tags in the template directory
local globArg = ""
@@ -28,8 +31,20 @@ local function command_find_all_tags(opts)
re = yaml_re
end
return "rg",
{
local rg_args = {
"--vimgrep",
globArg,
"-o",
re,
"--",
opts.cwd,
}
-- PCRE engine allows to remove hex color codes from #hastags
if opts.rg_pcre then
re = hashtag_re_pcre
rg_args = {
"--vimgrep",
"--pcre2",
globArg,
@@ -38,6 +53,9 @@ local function command_find_all_tags(opts)
"--",
opts.cwd,
}
end
return "rg", rg_args
end
-- strips away leading ' or " , then trims whitespace