Skip to content

Commit

Permalink
Merge branch 'nvim-telescope:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Wordluc authored Oct 8, 2024
2 parents f2d46a6 + dc6fc32 commit 66dfab1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
4 changes: 4 additions & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,8 @@ builtin.tags({opts}) *telescope.builtin.tags()*
{show_line} (boolean) if true, shows the content of the line the
tag is found on in the picker (default:
true)
{show_kind} (boolean) if true and kind info is available, show
the kind of the tag (default: true)
{only_sort_tags} (boolean) if true we will only sort tags (default:
false)
{fname_width} (number) defines the width of the filename section
Expand All @@ -1033,6 +1035,8 @@ builtin.current_buffer_tags({opts}) *telescope.builtin.current_buffer_tags()*
{show_line} (boolean) if true, shows the content of the line the
tag is found on in the picker (default:
true)
{show_kind} (boolean) if true and kind info is available, show
the kind of the tag (default: true)
{only_sort_tags} (boolean) if true we will only sort tags (default:
false)
{fname_width} (number) defines the width of the filename section
Expand Down
53 changes: 27 additions & 26 deletions lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ local filter = vim.tbl_filter

local files = {}

local escape_chars = function(string)
return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%.]", {
["\\"] = "\\\\",
["-"] = "\\-",
["("] = "\\(",
[")"] = "\\)",
["["] = "\\[",
["]"] = "\\]",
["{"] = "\\{",
["}"] = "\\}",
["?"] = "\\?",
["+"] = "\\+",
["*"] = "\\*",
["^"] = "\\^",
["$"] = "\\$",
["."] = "\\.",
})
---@param s string
---@return string
local escape_chars = function(s)
return (
s:gsub("[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%.]", {
["\\"] = "\\\\",
["-"] = "\\-",
["("] = "\\(",
[")"] = "\\)",
["["] = "\\[",
["]"] = "\\]",
["{"] = "\\{",
["}"] = "\\}",
["?"] = "\\?",
["+"] = "\\+",
["*"] = "\\*",
["^"] = "\\^",
["$"] = "\\$",
["."] = "\\.",
})
)
end

local has_rg_program = function(picker_name, program)
Expand Down Expand Up @@ -202,7 +206,10 @@ files.grep_string = function(opts)
else
word = vim.F.if_nil(opts.search, vim.fn.expand "<cword>")
end

word = tostring(word)
local search = opts.use_regex and word or escape_chars(word)
local search_args = search == "" and { "-v", "--", "^[[:space:]]*$" } or { "--", search }

local additional_args = {}
if opts.additional_args ~= nil then
Expand All @@ -217,32 +224,26 @@ files.grep_string = function(opts)
additional_args[#additional_args + 1] = "--encoding=" .. opts.file_encoding
end

if search == "" then
search = { "-v", "--", "^[[:space:]]*$" }
else
search = { "--", search }
end

local args
if visual == true then
args = flatten {
vimgrep_arguments,
additional_args,
search,
search_args,
}
else
args = flatten {
vimgrep_arguments,
additional_args,
opts.word_match,
search,
search_args,
}
end

opts.__inverted, opts.__matches = opts_contain_invert(args)

if opts.grep_open_files then
for _, file in ipairs(get_open_filelist(opts.grep_open_files, opts.cwd)) do
for _, file in ipairs(get_open_filelist(opts.grep_open_files, opts.cwd) or {}) do
table.insert(args, file)
end
elseif opts.search_dirs then
Expand Down
2 changes: 2 additions & 0 deletions lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ builtin.current_buffer_fuzzy_find = require_on_exported_call("telescope.builtin.
---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer)
---@field ctags_file string: specify a particular ctags file to use
---@field show_line boolean: if true, shows the content of the line the tag is found on in the picker (default: true)
---@field show_kind boolean: if true and kind info is available, show the kind of the tag (default: true)
---@field only_sort_tags boolean: if true we will only sort tags (default: false)
---@field fname_width number: defines the width of the filename section (default: 30)
builtin.tags = require_on_exported_call("telescope.builtin.__files").tags
Expand All @@ -123,6 +124,7 @@ builtin.tags = require_on_exported_call("telescope.builtin.__files").tags
---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer)
---@field ctags_file string: specify a particular ctags file to use
---@field show_line boolean: if true, shows the content of the line the tag is found on in the picker (default: true)
---@field show_kind boolean: if true and kind info is available, show the kind of the tag (default: true)
---@field only_sort_tags boolean: if true we will only sort tags (default: false)
---@field fname_width number: defines the width of the filename section (default: 30)
builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.__files").current_buffer_tags
Expand Down
13 changes: 10 additions & 3 deletions lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,12 @@ end
function make_entry.gen_from_ctags(opts)
opts = opts or {}

local show_kind = vim.F.if_nil(opts.show_kind, true)
local cwd = utils.path_expand(opts.cwd or vim.loop.cwd())
local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):normalize(cwd)

local display_items = {
{ width = 16 },
{ remaining = true },
}

Expand Down Expand Up @@ -1062,6 +1064,7 @@ function make_entry.gen_from_ctags(opts)
end,
},
entry.tag,
entry.kind,
scode,
}
end
Expand Down Expand Up @@ -1089,13 +1092,14 @@ function make_entry.gen_from_ctags(opts)
return nil
end

local tag, file, scode, lnum
-- ctags gives us: 'tags\tfile\tsource'
tag, file, scode = string.match(line, '([^\t]+)\t([^\t]+)\t/^?\t?(.*)/;"\t+.*')
local tag, file, scode, lnum, extension_fields
-- ctags gives us: 'tags\tfile\tsource;"extension_fields'
tag, file, scode, extension_fields = string.match(line, '([^\t]+)\t([^\t]+)\t/^?\t?(.*)/;"\t+(.*)')
if not tag then
-- hasktags gives us: 'tags\tfile\tlnum'
tag, file, lnum = string.match(line, "([^\t]+)\t([^\t]+)\t(%d+).*")
end
local kind = string.match(extension_fields or "", "kind:(%S+)")

if Path.path.sep == "\\" then
file = string.gsub(file, "/", "\\")
Expand Down Expand Up @@ -1124,6 +1128,9 @@ function make_entry.gen_from_ctags(opts)
tag_entry.filename = file
tag_entry.col = 1
tag_entry.lnum = lnum and tonumber(lnum) or 1
if show_kind then
tag_entry.kind = kind
end

return setmetatable(tag_entry, mt)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/previewers/buffer_previewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ previewers.highlights = defaulter(function(_)
vim.schedule(function()
vim.api.nvim_buf_call(self.state.bufnr, function()
vim.cmd "keepjumps norm! gg"
vim.fn.search(entry.value .. " ")
vim.fn.search("^" .. entry.value .. " ")
local lnum = vim.api.nvim_win_get_cursor(self.state.winid)[1]
-- That one is actually a match but its better to use it like that then matchadd
pcall(vim.api.nvim_buf_clear_namespace, self.state.bufnr, ns_previewer, 0, -1)
Expand Down
6 changes: 5 additions & 1 deletion lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,11 @@ end)
--- Checks if treesitter parser for language is installed
---@param lang string
utils.has_ts_parser = function(lang)
return pcall(vim.treesitter.language.add, lang)
if vim.fn.has "nvim-0.11" == 1 then
return vim.treesitter.language.add(lang)
else
return pcall(vim.treesitter.language.add, lang)
end
end

--- Telescope Wrapper around vim.notify
Expand Down

0 comments on commit 66dfab1

Please sign in to comment.