chore: use stylua for formatting (#1040)

* chore: stylua job and config

* reformat with stylua
This commit is contained in:
Simon Hauser
2021-07-23 17:42:37 +02:00
committed by GitHub
parent 664690029f
commit 79644ab677
75 changed files with 3201 additions and 2809 deletions

View File

@@ -1,16 +1,16 @@
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local action_set = require('telescope.actions.set')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local pickers = require('telescope.pickers')
local previewers = require('telescope.previewers')
local utils = require('telescope.utils')
local conf = require('telescope.config').values
local log = require('telescope.log')
local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local action_set = require "telescope.actions.set"
local finders = require "telescope.finders"
local make_entry = require "telescope.make_entry"
local pickers = require "telescope.pickers"
local previewers = require "telescope.previewers"
local utils = require "telescope.utils"
local conf = require("telescope.config").values
local log = require "telescope.log"
local scan = require('plenary.scandir')
local Path = require('plenary.path')
local scan = require "plenary.scandir"
local Path = require "plenary.path"
local os_sep = Path.path.sep
local flatten = vim.tbl_flatten
@@ -19,13 +19,19 @@ local filter = vim.tbl_filter
local files = {}
local escape_chars = function(string)
return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$]", {
["\\"] = "\\\\", ["-"] = "\\-",
["("] = "\\(", [")"] = "\\)",
["["] = "\\[", ["]"] = "\\]",
["{"] = "\\{", ["}"] = "\\}",
["?"] = "\\?", ["+"] = "\\+",
["*"] = "\\*", ["^"] = "\\^",
return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$]", {
["\\"] = "\\\\",
["-"] = "\\-",
["("] = "\\(",
[")"] = "\\)",
["["] = "\\[",
["]"] = "\\]",
["{"] = "\\{",
["}"] = "\\}",
["?"] = "\\?",
["+"] = "\\+",
["*"] = "\\*",
["^"] = "\\^",
["$"] = "\\$",
})
end
@@ -42,11 +48,15 @@ files.live_grep = function(opts)
local filelist = {}
if grep_open_files then
local bufnrs = filter(function(b)
if 1 ~= vim.fn.buflisted(b) then return false end
local bufnrs = filter(function(b)
if 1 ~= vim.fn.buflisted(b) then
return false
end
return true
end, vim.api.nvim_list_bufs())
if not next(bufnrs) then return end
if not next(bufnrs) then
return
end
for _, bufnr in ipairs(bufnrs) do
local file = vim.api.nvim_buf_get_name(bufnr)
@@ -59,35 +69,33 @@ files.live_grep = function(opts)
end
local live_grepper = finders.new_job(function(prompt)
-- TODO: Probably could add some options for smart case and whatever else rg offers.
-- TODO: Probably could add some options for smart case and whatever else rg offers.
if not prompt or prompt == "" then
return nil
end
if not prompt or prompt == "" then
return nil
end
prompt = escape_chars(prompt)
prompt = escape_chars(prompt)
local search_list = {}
local search_list = {}
if search_dirs then
table.insert(search_list, search_dirs)
else
table.insert(search_list, '.')
end
if search_dirs then
table.insert(search_list, search_dirs)
else
table.insert(search_list, ".")
end
if grep_open_files then
search_list = filelist
end
if grep_open_files then
search_list = filelist
end
return flatten { vimgrep_arguments, prompt, search_list }
end,
opts.entry_maker or make_entry.gen_from_vimgrep(opts),
opts.max_results,
opts.cwd
)
return flatten { vimgrep_arguments, prompt, search_list }
end, opts.entry_maker or make_entry.gen_from_vimgrep(
opts
), opts.max_results, opts.cwd)
pickers.new(opts, {
prompt_title = 'Live Grep',
prompt_title = "Live Grep",
finder = live_grepper,
previewer = conf.grep_previewer(opts),
sorter = conf.generic_sorter(opts),
@@ -103,7 +111,7 @@ files.grep_string = function(opts)
local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments
local search_dirs = opts.search_dirs
local word = opts.search or vim.fn.expand("<cword>")
local word = opts.search or vim.fn.expand "<cword>"
local search = opts.use_regex and word or escape_chars(word)
local word_match = opts.word_match
opts.entry_maker = opts.entry_maker or make_entry.gen_from_vimgrep(opts)
@@ -119,11 +127,11 @@ files.grep_string = function(opts)
table.insert(args, vim.fn.expand(path))
end
else
table.insert(args, '.')
table.insert(args, ".")
end
pickers.new(opts, {
prompt_title = 'Find Word',
prompt_title = "Find Word",
finder = finders.new_oneshot_job(args, opts),
previewer = conf.grep_previewer(opts),
sorter = conf.generic_sorter(opts),
@@ -139,71 +147,87 @@ files.find_files = function(opts)
local search_dirs = opts.search_dirs
if search_dirs then
for k,v in pairs(search_dirs) do
for k, v in pairs(search_dirs) do
search_dirs[k] = vim.fn.expand(v)
end
end
if not find_command then
if 1 == vim.fn.executable("fd") then
find_command = { 'fd', '--type', 'f' }
if hidden then table.insert(find_command, '--hidden') end
if follow then table.insert(find_command, '-L') end
if 1 == vim.fn.executable "fd" then
find_command = { "fd", "--type", "f" }
if hidden then
table.insert(find_command, "--hidden")
end
if follow then
table.insert(find_command, "-L")
end
if search_dirs then
table.insert(find_command, '.')
for _,v in pairs(search_dirs) do
table.insert(find_command, ".")
for _, v in pairs(search_dirs) do
table.insert(find_command, v)
end
end
elseif 1 == vim.fn.executable("fdfind") then
find_command = { 'fdfind', '--type', 'f' }
if hidden then table.insert(find_command, '--hidden') end
if follow then table.insert(find_command, '-L') end
elseif 1 == vim.fn.executable "fdfind" then
find_command = { "fdfind", "--type", "f" }
if hidden then
table.insert(find_command, "--hidden")
end
if follow then
table.insert(find_command, "-L")
end
if search_dirs then
table.insert(find_command, '.')
for _,v in pairs(search_dirs) do
table.insert(find_command, ".")
for _, v in pairs(search_dirs) do
table.insert(find_command, v)
end
end
elseif 1 == vim.fn.executable("rg") then
find_command = { 'rg', '--files' }
if hidden then table.insert(find_command, '--hidden') end
if follow then table.insert(find_command, '-L') end
elseif 1 == vim.fn.executable "rg" then
find_command = { "rg", "--files" }
if hidden then
table.insert(find_command, "--hidden")
end
if follow then
table.insert(find_command, "-L")
end
if search_dirs then
for _,v in pairs(search_dirs) do
for _, v in pairs(search_dirs) do
table.insert(find_command, v)
end
end
elseif 1 == vim.fn.executable("find") and vim.fn.has('win32') == 0 then
find_command = { 'find', '.', '-type', 'f' }
elseif 1 == vim.fn.executable "find" and vim.fn.has "win32" == 0 then
find_command = { "find", ".", "-type", "f" }
if not hidden then
table.insert(find_command, { '-not', '-path', "*/.*" })
table.insert(find_command, { "-not", "-path", "*/.*" })
find_command = flatten(find_command)
end
if follow then table.insert(find_command, '-L') end
if follow then
table.insert(find_command, "-L")
end
if search_dirs then
table.remove(find_command, 2)
for _,v in pairs(search_dirs) do
for _, v in pairs(search_dirs) do
table.insert(find_command, 2, v)
end
end
elseif 1 == vim.fn.executable("where") then
find_command = { 'where', '/r', '.', '*'}
elseif 1 == vim.fn.executable "where" then
find_command = { "where", "/r", ".", "*" }
if hidden ~= nil then
log.warn('The `hidden` key is not available for the Windows `where` command in `find_files`.')
log.warn "The `hidden` key is not available for the Windows `where` command in `find_files`."
end
if follow ~= nil then
log.warn('The `follow` key is not available for the Windows `where` command in `find_files`.')
log.warn "The `follow` key is not available for the Windows `where` command in `find_files`."
end
if search_dirs ~= nil then
log.warn('The `search_dirs` key is not available for the Windows `where` command in `find_files`.')
log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`."
end
end
end
if not find_command then
print("You need to install either find, fd, or rg. " ..
"You can also submit a PR to add support for another file finder :)")
print(
"You need to install either find, fd, or rg. "
.. "You can also submit a PR to add support for another file finder :)"
)
return
end
@@ -214,11 +238,8 @@ files.find_files = function(opts)
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
pickers.new(opts, {
prompt_title = 'Find Files',
finder = finders.new_oneshot_job(
find_command,
opts
),
prompt_title = "Find Files",
finder = finders.new_oneshot_job(find_command, opts),
previewer = conf.file_previewer(opts),
sorter = conf.file_sorter(opts),
}):find()
@@ -228,11 +249,11 @@ local function prepare_match(entry, kind)
local entries = {}
if entry.node then
entry["kind"] = kind
table.insert(entries, entry)
entry["kind"] = kind
table.insert(entries, entry)
else
for name, item in pairs(entry) do
vim.list_extend(entries, prepare_match(item, name))
vim.list_extend(entries, prepare_match(item, name))
end
end
@@ -248,71 +269,76 @@ files.file_browser = function(opts)
opts.depth = opts.depth or 1
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
opts.new_finder = opts.new_finder or function(path)
opts.cwd = path
local data = {}
opts.new_finder = opts.new_finder
or function(path)
opts.cwd = path
local data = {}
scan.scan_dir(path, {
hidden = opts.hidden or false,
add_dirs = true,
depth = opts.depth,
on_insert = function(entry, typ)
table.insert(data, typ == 'directory' and (entry .. os_sep) or entry)
end
})
table.insert(data, 1, '..' .. os_sep)
scan.scan_dir(path, {
hidden = opts.hidden or false,
add_dirs = true,
depth = opts.depth,
on_insert = function(entry, typ)
table.insert(data, typ == "directory" and (entry .. os_sep) or entry)
end,
})
table.insert(data, 1, ".." .. os_sep)
local maker = function()
local mt = {}
mt.cwd = opts.cwd
mt.display = function(entry)
local hl_group
local display = utils.transform_path(opts, entry.value)
if is_dir(entry.value) then
display = display .. os_sep
if not opts.disable_devicons then
display = (opts.dir_icon or "") .. " " .. display
hl_group = "Default"
local maker = function()
local mt = {}
mt.cwd = opts.cwd
mt.display = function(entry)
local hl_group
local display = utils.transform_path(opts, entry.value)
if is_dir(entry.value) then
display = display .. os_sep
if not opts.disable_devicons then
display = (opts.dir_icon or "") .. " " .. display
hl_group = "Default"
end
else
display, hl_group = utils.transform_devicons(entry.value, display, opts.disable_devicons)
end
else
display, hl_group = utils.transform_devicons(entry.value, display, opts.disable_devicons)
end
if hl_group then
return display, { { {1, 3}, hl_group } }
else
return display
end
end
mt.__index = function(t, k)
local raw = rawget(mt, k)
if raw then return raw end
if k == "path" then
local retpath = Path:new({t.cwd, t.value}):absolute()
if not vim.loop.fs_access(retpath, "R", nil) then
retpath = t.value
if hl_group then
return display, { { { 1, 3 }, hl_group } }
else
return display
end
if is_dir(t.value) then retpath = retpath .. os_sep end
return retpath
end
return rawget(t, rawget({ value = 1 }, k))
mt.__index = function(t, k)
local raw = rawget(mt, k)
if raw then
return raw
end
if k == "path" then
local retpath = Path:new({ t.cwd, t.value }):absolute()
if not vim.loop.fs_access(retpath, "R", nil) then
retpath = t.value
end
if is_dir(t.value) then
retpath = retpath .. os_sep
end
return retpath
end
return rawget(t, rawget({ value = 1 }, k))
end
return function(line)
local tbl = { line }
tbl.ordinal = Path:new(line):make_relative(opts.cwd)
return setmetatable(tbl, mt)
end
end
return function(line)
local tbl = {line}
tbl.ordinal = Path:new(line):make_relative(opts.cwd)
return setmetatable(tbl, mt)
end
return finders.new_table { results = data, entry_maker = maker() }
end
return finders.new_table { results = data, entry_maker = maker() }
end
pickers.new(opts, {
prompt_title = 'File Browser',
prompt_title = "File Browser",
finder = opts.new_finder(opts.cwd),
previewer = conf.file_previewer(opts),
sorter = conf.file_sorter(opts),
@@ -330,28 +356,38 @@ files.file_browser = function(opts)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local file = action_state.get_current_line()
if file == "" then
print('To create a new file or directory(add ' .. os_sep .. ' at the end of file) ' ..
'write the desired new into the prompt and press <C-e>. ' ..
'It works for not existing nested input as well.' ..
'Example: this' .. os_sep .. 'is' .. os_sep .. 'a' .. os_sep .. 'new_file.lua')
print(
"To create a new file or directory(add "
.. os_sep
.. " at the end of file) "
.. "write the desired new into the prompt and press <C-e>. "
.. "It works for not existing nested input as well."
.. "Example: this"
.. os_sep
.. "is"
.. os_sep
.. "a"
.. os_sep
.. "new_file.lua"
)
return
end
local fpath = current_picker.cwd .. os_sep .. file
if not is_dir(fpath) then
actions.close(prompt_bufnr)
Path:new(fpath):touch({ parents = true })
vim.cmd(string.format(':e %s', fpath))
Path:new(fpath):touch { parents = true }
vim.cmd(string.format(":e %s", fpath))
else
Path:new(fpath:sub(1, -2)):mkdir({ parents = true })
Path:new(fpath:sub(1, -2)):mkdir { parents = true }
local new_cwd = vim.fn.expand(fpath)
current_picker.cwd = new_cwd
current_picker:refresh(opts.new_finder(new_cwd), { reset_prompt = true })
end
end
map('i', '<C-e>', create_new_file)
map('n', '<C-e>', create_new_file)
map("i", "<C-e>", create_new_file)
map("n", "<C-e>", create_new_file)
return true
end,
}):find()
@@ -361,19 +397,19 @@ end
files.treesitter = function(opts)
opts.show_line = utils.get_default(opts.show_line, true)
local has_nvim_treesitter, _ = pcall(require, 'nvim-treesitter')
local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter")
if not has_nvim_treesitter then
print('You need to install nvim-treesitter')
print "You need to install nvim-treesitter"
return
end
local parsers = require('nvim-treesitter.parsers')
local parsers = require "nvim-treesitter.parsers"
if not parsers.has_parser() then
print('No parser for the current buffer')
print "No parser for the current buffer"
return
end
local ts_locals = require('nvim-treesitter.locals')
local ts_locals = require "nvim-treesitter.locals"
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
local results = {}
@@ -389,16 +425,16 @@ files.treesitter = function(opts)
end
pickers.new(opts, {
prompt_title = 'Treesitter Symbols',
finder = finders.new_table {
prompt_title = "Treesitter Symbols",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_treesitter(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_treesitter(opts),
},
previewer = conf.grep_previewer(opts),
sorter = conf.prefilter_sorter{
sorter = conf.prefilter_sorter {
tag = "kind",
sorter = conf.generic_sorter(opts)
}
sorter = conf.generic_sorter(opts),
},
}):find()
end
@@ -420,7 +456,7 @@ files.current_buffer_fuzzy_find = function(opts)
})
end
local ts_ok, ts_parsers = pcall(require, 'nvim-treesitter.parsers')
local ts_ok, ts_parsers = pcall(require, "nvim-treesitter.parsers")
if ts_ok then
filetype = ts_parsers.ft_to_lang(filetype)
end
@@ -454,7 +490,7 @@ files.current_buffer_fuzzy_find = function(opts)
else
local row = row1 + 1
for index = col1, #lines[row] do
line_highlights[row][index] = hl
line_highlights[row][index] = hl
end
while row < row2 + 1 do
@@ -472,7 +508,7 @@ files.current_buffer_fuzzy_find = function(opts)
end
pickers.new(opts, {
prompt_title = 'Current Buffer Fuzzy',
prompt_title = "Current Buffer Fuzzy",
finder = finders.new_table {
results = lines_with_numbers,
entry_maker = opts.entry_maker or make_entry.gen_from_buffer_lines(opts),
@@ -488,15 +524,15 @@ files.current_buffer_fuzzy_find = function(opts)
}
return true
end
end,
}):find()
end
files.tags = function(opts)
local ctags_file = opts.ctags_file or 'tags'
local ctags_file = opts.ctags_file or "tags"
if not vim.loop.fs_open(vim.fn.expand(ctags_file, true), "r", 438) then
print('Tags file does not exists. Create one with ctags -R')
print "Tags file does not exists. Create one with ctags -R"
return
end
@@ -505,10 +541,10 @@ files.tags = function(opts)
local data = assert(vim.loop.fs_read(fd, stat.size, 0))
assert(vim.loop.fs_close(fd))
local results = vim.split(data, '\n')
local results = vim.split(data, "\n")
pickers.new(opts,{
prompt_title = 'Tags',
pickers.new(opts, {
prompt_title = "Tags",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_ctags(opts),
@@ -521,29 +557,29 @@ files.tags = function(opts)
local selection = action_state.get_selected_entry()
if selection.scode then
local scode = string.gsub(selection.scode, '[$]$', '')
local scode = string.gsub(selection.scode, "[$]$", "")
scode = string.gsub(scode, [[\\]], [[\]])
scode = string.gsub(scode, [[\/]], [[/]])
scode = string.gsub(scode, '[*]', [[\*]])
scode = string.gsub(scode, "[*]", [[\*]])
vim.cmd('norm! gg')
vim.cmd "norm! gg"
vim.fn.search(scode)
vim.cmd('norm! zz')
vim.cmd "norm! zz"
else
vim.api.nvim_win_set_cursor(0, {selection.lnum, 0})
vim.api.nvim_win_set_cursor(0, { selection.lnum, 0 })
end
end,
}
return true
end
end,
}):find()
end
files.current_buffer_tags = function(opts)
return files.tags(vim.tbl_extend("force", {
prompt_title = 'Current Buffer Tags',
prompt_title = "Current Buffer Tags",
only_current_file = true,
path_display = 'hidden',
path_display = "hidden",
}, opts))
end

View File

@@ -1,15 +1,15 @@
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local pickers = require('telescope.pickers')
local previewers = require('telescope.previewers')
local utils = require('telescope.utils')
local entry_display = require('telescope.pickers.entry_display')
local strings = require('plenary.strings')
local Path = require('plenary.path')
local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local finders = require "telescope.finders"
local make_entry = require "telescope.make_entry"
local pickers = require "telescope.pickers"
local previewers = require "telescope.previewers"
local utils = require "telescope.utils"
local entry_display = require "telescope.pickers.entry_display"
local strings = require "plenary.strings"
local Path = require "plenary.path"
local conf = require('telescope.config').values
local conf = require("telescope.config").values
local git = {}
@@ -17,7 +17,7 @@ git.files = function(opts)
local show_untracked = utils.get_default(opts.show_untracked, true)
local recurse_submodules = utils.get_default(opts.recurse_submodules, false)
if show_untracked and recurse_submodules then
error("Git does not support both --others and --recurse-submodules")
error "Git does not support both --others and --recurse-submodules"
end
-- By creating the entry maker after the cwd options,
@@ -25,13 +25,16 @@ git.files = function(opts)
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
pickers.new(opts, {
prompt_title = 'Git Files',
prompt_title = "Git Files",
finder = finders.new_oneshot_job(
vim.tbl_flatten( {
"git", "ls-files", "--exclude-standard", "--cached",
vim.tbl_flatten {
"git",
"ls-files",
"--exclude-standard",
"--cached",
show_untracked and "--others" or nil,
recurse_submodules and "--recurse-submodules" or nil
} ),
recurse_submodules and "--recurse-submodules" or nil,
},
opts
),
previewer = conf.file_previewer(opts),
@@ -41,11 +44,16 @@ end
git.commits = function(opts)
local results = utils.get_os_command_output({
'git', 'log', '--pretty=oneline', '--abbrev-commit', '--', '.'
"git",
"log",
"--pretty=oneline",
"--abbrev-commit",
"--",
".",
}, opts.cwd)
pickers.new(opts, {
prompt_title = 'Git Commits',
prompt_title = "Git Commits",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_git_commits(opts),
@@ -60,17 +68,20 @@ git.commits = function(opts)
attach_mappings = function()
actions.select_default:replace(actions.git_checkout)
return true
end
end,
}):find()
end
git.stash = function(opts)
local results = utils.get_os_command_output({
'git', '--no-pager', 'stash', 'list',
"git",
"--no-pager",
"stash",
"list",
}, opts.cwd)
pickers.new(opts, {
prompt_title = 'Git Stash',
prompt_title = "Git Stash",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_git_stash(),
@@ -80,7 +91,7 @@ git.stash = function(opts)
attach_mappings = function()
actions.select_default:replace(actions.git_apply_stash)
return true
end
end,
}):find()
end
@@ -90,14 +101,18 @@ local get_current_buf_line = function(winnr)
end
git.bcommits = function(opts)
opts.current_line = (not opts.current_file) and get_current_buf_line(0) or nil
opts.current_file = opts.current_file or vim.fn.expand('%')
opts.current_line = not opts.current_file and get_current_buf_line(0) or nil
opts.current_file = opts.current_file or vim.fn.expand "%"
local results = utils.get_os_command_output({
'git', 'log', '--pretty=oneline', '--abbrev-commit', opts.current_file
"git",
"log",
"--pretty=oneline",
"--abbrev-commit",
opts.current_file,
}, opts.cwd)
pickers.new(opts, {
prompt_title = 'Git BCommits',
prompt_title = "Git BCommits",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_git_commits(opts),
@@ -112,64 +127,67 @@ git.bcommits = function(opts)
attach_mappings = function()
actions.select_default:replace(actions.git_checkout_current_buffer)
local transfrom_file = function()
return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or ''
return opts.current_file and Path:new(opts.current_file):make_relative(opts.cwd) or ""
end
local get_buffer_of_orig = function(selection)
local value = selection.value .. ':' .. transfrom_file()
local content = utils.get_os_command_output({ 'git', '--no-pager', 'show', value }, opts.cwd)
local value = selection.value .. ":" .. transfrom_file()
local content = utils.get_os_command_output({ "git", "--no-pager", "show", value }, opts.cwd)
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content)
vim.api.nvim_buf_set_name(bufnr, 'Original')
vim.api.nvim_buf_set_name(bufnr, "Original")
return bufnr
end
local vimdiff = function(selection, command)
local ft = vim.bo.filetype
vim.cmd("diffthis")
vim.cmd "diffthis"
local bufnr = get_buffer_of_orig(selection)
vim.cmd(string.format("%s %s", command, bufnr))
vim.bo.filetype = ft
vim.cmd("diffthis")
vim.cmd "diffthis"
vim.cmd(string.format(
"autocmd WinClosed <buffer=%s> ++nested ++once :lua vim.api.nvim_buf_delete(%s, { force = true })",
bufnr,
bufnr))
vim.cmd(
string.format(
"autocmd WinClosed <buffer=%s> ++nested ++once :lua vim.api.nvim_buf_delete(%s, { force = true })",
bufnr,
bufnr
)
)
end
actions.select_vertical:replace(function(prompt_bufnr)
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
vimdiff(selection, 'leftabove vert sbuffer')
vimdiff(selection, "leftabove vert sbuffer")
end)
actions.select_horizontal:replace(function(prompt_bufnr)
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
vimdiff(selection, 'belowright sbuffer')
vimdiff(selection, "belowright sbuffer")
end)
actions.select_tab:replace(function(prompt_bufnr)
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
vim.cmd('tabedit ' .. transfrom_file())
vimdiff(selection, 'leftabove vert sbuffer')
vim.cmd("tabedit " .. transfrom_file())
vimdiff(selection, "leftabove vert sbuffer")
end)
return true
end
end,
}):find()
end
git.branches = function(opts)
local format = '%(HEAD)'
.. '%(refname)'
.. '%(authorname)'
.. '%(upstream:lstrip=2)'
.. '%(committerdate:format-local:%Y/%m/%d%H:%M:%S)'
local output = utils.get_os_command_output({ 'git', 'for-each-ref', '--perl', '--format', format }, opts.cwd)
local format = "%(HEAD)"
.. "%(refname)"
.. "%(authorname)"
.. "%(upstream:lstrip=2)"
.. "%(committerdate:format-local:%Y/%m/%d%H:%M:%S)"
local output = utils.get_os_command_output({ "git", "for-each-ref", "--perl", "--format", format }, opts.cwd)
local results = {}
local widths = {
@@ -179,7 +197,7 @@ git.branches = function(opts)
committerdate = 0,
}
local unescape_single_quote = function(v)
return string.gsub(v, "\\([\\'])", "%1")
return string.gsub(v, "\\([\\'])", "%1")
end
local parse_line = function(line)
local fields = vim.split(string.sub(line, 2, -2), "''", true)
@@ -191,21 +209,21 @@ git.branches = function(opts)
committerdate = fields[5],
}
local prefix
if vim.startswith(entry.refname, 'refs/remotes/') then
prefix = 'refs/remotes/'
elseif vim.startswith(entry.refname, 'refs/heads/') then
prefix = 'refs/heads/'
if vim.startswith(entry.refname, "refs/remotes/") then
prefix = "refs/remotes/"
elseif vim.startswith(entry.refname, "refs/heads/") then
prefix = "refs/heads/"
else
return
end
local index = 1
if entry.head ~= '*' then
if entry.head ~= "*" then
index = #results + 1
end
entry.name = string.sub(entry.refname, string.len(prefix)+1)
entry.name = string.sub(entry.refname, string.len(prefix) + 1)
for key, value in pairs(widths) do
widths[key] = math.max(value, strings.strdisplaywidth(entry[key] or ''))
widths[key] = math.max(value, strings.strdisplaywidth(entry[key] or ""))
end
if string.len(entry.upstream) > 0 then
widths.upstream_indicator = 2
@@ -228,22 +246,22 @@ git.branches = function(opts)
{ width = widths.upstream_indicator },
{ width = widths.upstream },
{ width = widths.committerdate },
}
},
}
local make_display = function(entry)
return displayer {
{entry.head},
{entry.name, 'TelescopeResultsIdentifier'},
{entry.authorname},
{string.len(entry.upstream) > 0 and '=>' or ''},
{entry.upstream, 'TelescopeResultsIdentifier'},
{entry.committerdate}
{ entry.head },
{ entry.name, "TelescopeResultsIdentifier" },
{ entry.authorname },
{ string.len(entry.upstream) > 0 and "=>" or "" },
{ entry.upstream, "TelescopeResultsIdentifier" },
{ entry.committerdate },
}
end
pickers.new(opts, {
prompt_title = 'Git Branches',
prompt_title = "Git Branches",
finder = finders.new_table {
results = results,
entry_maker = function(entry)
@@ -251,58 +269,60 @@ git.branches = function(opts)
entry.ordinal = entry.name
entry.display = make_display
return entry
end
end,
},
previewer = previewers.git_branch_log.new(opts),
sorter = conf.file_sorter(opts),
attach_mappings = function(_, map)
actions.select_default:replace(actions.git_checkout)
map('i', '<c-t>', actions.git_track_branch)
map('n', '<c-t>', actions.git_track_branch)
map("i", "<c-t>", actions.git_track_branch)
map("n", "<c-t>", actions.git_track_branch)
map('i', '<c-r>', actions.git_rebase_branch)
map('n', '<c-r>', actions.git_rebase_branch)
map("i", "<c-r>", actions.git_rebase_branch)
map("n", "<c-r>", actions.git_rebase_branch)
map('i', '<c-a>', actions.git_create_branch)
map('n', '<c-a>', actions.git_create_branch)
map("i", "<c-a>", actions.git_create_branch)
map("n", "<c-a>", actions.git_create_branch)
map('i', '<c-s>', actions.git_switch_branch)
map('n', '<c-s>', actions.git_switch_branch)
map("i", "<c-s>", actions.git_switch_branch)
map("n", "<c-s>", actions.git_switch_branch)
map('i', '<c-d>', actions.git_delete_branch)
map('n', '<c-d>', actions.git_delete_branch)
map("i", "<c-d>", actions.git_delete_branch)
map("n", "<c-d>", actions.git_delete_branch)
return true
end
end,
}):find()
end
git.status = function(opts)
local gen_new_finder = function()
local expand_dir = utils.if_nil(opts.expand_dir, true, opts.expand_dir)
local git_cmd = {'git', 'status', '-s', '--', '.'}
local git_cmd = { "git", "status", "-s", "--", "." }
if expand_dir then
table.insert(git_cmd, table.getn(git_cmd) - 1, '-u')
table.insert(git_cmd, table.getn(git_cmd) - 1, "-u")
end
local output = utils.get_os_command_output(git_cmd, opts.cwd)
if table.getn(output) == 0 then
print('No changes found')
print "No changes found"
return
end
return finders.new_table {
results = output,
entry_maker = opts.entry_maker or make_entry.gen_from_git_status(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_git_status(opts),
}
end
local initial_finder = gen_new_finder()
if not initial_finder then return end
if not initial_finder then
return
end
pickers.new(opts, {
prompt_title = 'Git Status',
prompt_title = "Git Status",
finder = initial_finder,
previewer = previewers.git_file_diff.new(opts),
sorter = conf.file_sorter(opts),
@@ -313,10 +333,10 @@ git.status = function(opts)
end,
}
map('i', '<tab>', actions.git_staging_toggle)
map('n', '<tab>', actions.git_staging_toggle)
map("i", "<tab>", actions.git_staging_toggle)
map("n", "<tab>", actions.git_staging_toggle)
return true
end
end,
}):find()
end
@@ -334,7 +354,7 @@ local set_opts_cwd = function(opts)
if ret ~= 0 then
local output = utils.get_os_command_output({ "git", "rev-parse", "--is-inside-work-tree" }, opts.cwd)
if output[1] ~= "true" then
error(opts.cwd .. ' is not a git directory')
error(opts.cwd .. " is not a git directory")
end
else
if use_git_root then

View File

@@ -52,9 +52,9 @@
--- This will use the default configuration options. Other configuration options are still in flux at the moment
---@brief ]]
if 1 ~= vim.fn.has('nvim-0.5') then
vim.api.nvim_err_writeln("This plugins requires neovim 0.5")
vim.api.nvim_err_writeln("Please update your neovim.")
if 1 ~= vim.fn.has "nvim-0.5" then
vim.api.nvim_err_writeln "This plugins requires neovim 0.5"
vim.api.nvim_err_writeln "Please update your neovim."
return
end
@@ -70,14 +70,14 @@ local builtin = {}
---@param opts table: options to pass to the picker
---@field grep_open_files boolean: if true, restrict search to open files only, mutually exclusive with `search_dirs`
---@field search_dirs table: directory/directories to search in, mutually exclusive with `grep_open_files`
builtin.live_grep = require('telescope.builtin.files').live_grep
builtin.live_grep = require("telescope.builtin.files").live_grep
--- Searches for the string under your cursor in your current working directory
---@param opts table: options to pass to the picker
---@field search string: the query to search
---@field search_dirs table: directory/directories to search in
---@field use_regex boolean: if true, special characters won't be escaped, allows for using regex (default is false)
builtin.grep_string = require('telescope.builtin.files').grep_string
builtin.grep_string = require("telescope.builtin.files").grep_string
--- Lists files in your current working directory, respects .gitignore
---@param opts table: options to pass to the picker
@@ -85,7 +85,7 @@ builtin.grep_string = require('telescope.builtin.files').grep_string
---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command)
---@field hidden boolean: determines whether to show hidden files or not (default is false)
---@field search_dirs table: directory/directories to search in
builtin.find_files = require('telescope.builtin.files').find_files
builtin.find_files = require("telescope.builtin.files").find_files
--- This is an alias for the `find_files` picker
builtin.fd = builtin.find_files
@@ -102,28 +102,28 @@ builtin.fd = builtin.find_files
---@field cwd string: directory path to browse (default is cwd)
---@field depth number: file tree depth to display (default is 1)
---@field dir_icon string: change the icon for a directory. default: 
builtin.file_browser = require('telescope.builtin.files').file_browser
builtin.file_browser = require("telescope.builtin.files").file_browser
--- Lists function names, variables, and other symbols from treesitter queries
--- - Default keymaps:
--- - `<C-l>`: show autocompletion menu to prefilter your query by kind of ts node you want to see (i.e. `:var:`)
---@field show_line boolean: if true, shows the row:column that the result is found at (default is true)
builtin.treesitter = require('telescope.builtin.files').treesitter
builtin.treesitter = require("telescope.builtin.files").treesitter
--- Live fuzzy search inside of the currently open buffer
---@param opts table: options to pass to the picker
builtin.current_buffer_fuzzy_find = require('telescope.builtin.files').current_buffer_fuzzy_find
builtin.current_buffer_fuzzy_find = require("telescope.builtin.files").current_buffer_fuzzy_find
--- Lists tags in current directory with tag location file preview (users are required to run ctags -R to generate tags
--- or update when introducing new changes)
---@param opts table: options to pass to the picker
---@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 is true)
builtin.tags = require('telescope.builtin.files').tags
builtin.tags = require("telescope.builtin.files").tags
--- Lists all of the tags for the currently open buffer, with a preview
---@param opts table: options to pass to the picker
builtin.current_buffer_tags = require('telescope.builtin.files').current_buffer_tags
builtin.current_buffer_tags = require("telescope.builtin.files").current_buffer_tags
--
--
@@ -138,14 +138,14 @@ builtin.current_buffer_tags = require('telescope.builtin.files').current_buffer_
---@param opts table: options to pass to the picker
---@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default is true)
---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default is false)
builtin.git_files = require('telescope.builtin.git').files
builtin.git_files = require("telescope.builtin.git").files
--- Lists commits for current directory with diff preview
--- - Default keymaps:
--- - `<cr>`: checks out the currently selected commit
---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo
builtin.git_commits = require('telescope.builtin.git').commits
builtin.git_commits = require("telescope.builtin.git").commits
--- Lists commits for current buffer with diff preview
--- - Default keymaps or your overriden `select_` keys:
@@ -156,7 +156,7 @@ builtin.git_commits = require('telescope.builtin.git').commits
---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo
---@field current_file string: specify the current file that should be used for bcommits (default: current buffer)
builtin.git_bcommits = require('telescope.builtin.git').bcommits
builtin.git_bcommits = require("telescope.builtin.git").bcommits
--- List branches for current directory, with output from `git log --oneline` shown in the preview window
--- - Default keymaps:
@@ -166,20 +166,20 @@ builtin.git_bcommits = require('telescope.builtin.git').bcommits
--- - `<C-a>`: creates a new branch, with confirmation prompt before creation
--- - `<C-d>`: deletes the currently selected branch, with confirmation prompt before deletion
---@param opts table: options to pass to the picker
builtin.git_branches = require('telescope.builtin.git').branches
builtin.git_branches = require("telescope.builtin.git").branches
--- Lists git status for current directory
--- - Default keymaps:
--- - `<Tab>`: stages or unstages the currently selected file
--- - `<cr>`: opens the currently selected file
---@param opts table: options to pass to the picker
builtin.git_status = require('telescope.builtin.git').status
builtin.git_status = require("telescope.builtin.git").status
--- Lists stash items in current repository
--- - Default keymaps:
--- - `<cr>`: runs `git apply` for currently selected stash
---@param opts table: options to pass to the picker
builtin.git_stash = require('telescope.builtin.git').stash
builtin.git_stash = require("telescope.builtin.git").stash
--
--
@@ -189,59 +189,59 @@ builtin.git_stash = require('telescope.builtin.git').stash
--- Lists all of the community maintained pickers built into Telescope
---@param opts table: options to pass to the picker
builtin.builtin = require('telescope.builtin.internal').builtin
builtin.builtin = require("telescope.builtin.internal").builtin
--- Use the telescope...
---@param opts table: options to pass to the picker
builtin.planets = require('telescope.builtin.internal').planets
builtin.planets = require("telescope.builtin.internal").planets
--- Lists symbols inside of data/telescope-sources/*.json found in your runtime path. Check README for more info
---@param opts table: options to pass to the picker
builtin.symbols = require('telescope.builtin.internal').symbols
builtin.symbols = require("telescope.builtin.internal").symbols
--- Lists available plugin/user commands and runs them on `<cr>`
---@param opts table: options to pass to the picker
builtin.commands = require('telescope.builtin.internal').commands
builtin.commands = require("telescope.builtin.internal").commands
--- Lists items in the quickfix list, jumps to location on `<cr>`
---@param opts table: options to pass to the picker
builtin.quickfix = require('telescope.builtin.internal').quickfix
builtin.quickfix = require("telescope.builtin.internal").quickfix
--- Lists items from the current window's location list, jumps to location on `<cr>`
---@param opts table: options to pass to the picker
builtin.loclist = require('telescope.builtin.internal').loclist
builtin.loclist = require("telescope.builtin.internal").loclist
--- Lists previously open files, opens on `<cr>`
---@param opts table: options to pass to the picker
builtin.oldfiles = require('telescope.builtin.internal').oldfiles
builtin.oldfiles = require("telescope.builtin.internal").oldfiles
--- Lists commands that were executed recently, and reruns them on `<cr>`
--- - Default keymaps:
--- - `<C-e>`: open the command line with the text of the currently selected result populated in it
---@param opts table: options to pass to the picker
builtin.command_history = require('telescope.builtin.internal').command_history
builtin.command_history = require("telescope.builtin.internal").command_history
--- Lists searches that were executed recently, and reruns them on `<cr>`
--- - Default keymaps:
--- - `<C-e>`: open a search window with the text of the currently selected search result populated in it
---@param opts table: options to pass to the picker
builtin.search_history = require('telescope.builtin.internal').search_history
builtin.search_history = require("telescope.builtin.internal").search_history
--- Lists vim options, allows you to edit the current value on `<cr>`
---@param opts table: options to pass to the picker
builtin.vim_options = require('telescope.builtin.internal').vim_options
builtin.vim_options = require("telescope.builtin.internal").vim_options
--- Lists available help tags and opens a new window with the relevant help info on `<cr>`
---@param opts table: options to pass to the picker
builtin.help_tags = require('telescope.builtin.internal').help_tags
builtin.help_tags = require("telescope.builtin.internal").help_tags
--- Lists manpage entries, opens them in a help window on `<cr>`
---@param opts table: options to pass to the picker
builtin.man_pages = require('telescope.builtin.internal').man_pages
builtin.man_pages = require("telescope.builtin.internal").man_pages
--- Lists lua modules and reloads them on `<cr>`
---@param opts table: options to pass to the picker
builtin.reloader = require('telescope.builtin.internal').reloader
builtin.reloader = require("telescope.builtin.internal").reloader
--- Lists open buffers in current neovim instance, opens selected buffer on `<cr>`
---@param opts table: options to pass to the picker
@@ -251,50 +251,50 @@ builtin.reloader = require('telescope.builtin.internal').reloader
---@field sort_lastused boolean: Sorts current and last buffer to the top and selects the lastused (default false)
---@field sort_mru boolean: Sorts all buffers after most recent used. Not just the current and last one (default false)
---@field bufnr_width number: Defines the width of the buffer numbers in front of the filenames
builtin.buffers = require('telescope.builtin.internal').buffers
builtin.buffers = require("telescope.builtin.internal").buffers
--- Lists available colorschemes and applies them on `<cr>`
---@param opts table: options to pass to the picker
---@field enable_preview boolean: if true, will preview the selected color
builtin.colorscheme = require('telescope.builtin.internal').colorscheme
builtin.colorscheme = require("telescope.builtin.internal").colorscheme
--- Lists vim marks and their value, jumps to the mark on `<cr>`
---@param opts table: options to pass to the picker
builtin.marks = require('telescope.builtin.internal').marks
builtin.marks = require("telescope.builtin.internal").marks
--- Lists vim registers, pastes the contents of the register on `<cr>`
--- - Default keymaps:
--- - `<C-e>`: edit the contents of the currently selected register
---@param opts table: options to pass to the picker
builtin.registers = require('telescope.builtin.internal').registers
builtin.registers = require("telescope.builtin.internal").registers
--- Lists normal mode keymappings, runs the selected keymap on `<cr>`
---@param opts table: options to pass to the picker
builtin.keymaps = require('telescope.builtin.internal').keymaps
builtin.keymaps = require("telescope.builtin.internal").keymaps
--- Lists all available filetypes, sets currently open buffer's filetype to selected filetype in Telescope on `<cr>`
---@param opts table: options to pass to the picker
builtin.filetypes = require('telescope.builtin.internal').filetypes
builtin.filetypes = require("telescope.builtin.internal").filetypes
--- Lists all available highlights
---@param opts table: options to pass to the picker
builtin.highlights = require('telescope.builtin.internal').highlights
builtin.highlights = require("telescope.builtin.internal").highlights
--- Lists vim autocommands and goes to their declaration on `<cr>`
---@param opts table: options to pass to the picker
builtin.autocommands = require('telescope.builtin.internal').autocommands
builtin.autocommands = require("telescope.builtin.internal").autocommands
--- Lists spelling suggestions for the current word under the cursor, replaces word with selected suggestion on `<cr>`
---@param opts table: options to pass to the picker
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
builtin.spell_suggest = require("telescope.builtin.internal").spell_suggest
--- Lists the tag stack for the current window, jumps to tag on `<cr>`
---@param opts table: options to pass to the picker
builtin.tagstack = require('telescope.builtin.internal').tagstack
builtin.tagstack = require("telescope.builtin.internal").tagstack
--- Lists items from Vim's jumplist, jumps to location on `<cr>`
---@param opts table: options to pass to the picker
builtin.jumplist = require('telescope.builtin.internal').jumplist
builtin.jumplist = require("telescope.builtin.internal").jumplist
--
--
@@ -304,23 +304,23 @@ builtin.jumplist = require('telescope.builtin.internal').jumplist
--- Lists LSP references for word under the cursor, jumps to reference on `<cr>`
---@param opts table: options to pass to the picker
builtin.lsp_references = require('telescope.builtin.lsp').references
builtin.lsp_references = require("telescope.builtin.lsp").references
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
---@param opts table: options to pass to the picker
builtin.lsp_definitions = require('telescope.builtin.lsp').definitions
builtin.lsp_definitions = require("telescope.builtin.lsp").definitions
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
---@param opts table: options to pass to the picker
builtin.lsp_implementations = require('telescope.builtin.lsp').implementations
builtin.lsp_implementations = require("telescope.builtin.lsp").implementations
--- Lists any LSP actions for the word under the cursor which can be triggered with `<cr>`
---@param opts table: options to pass to the picker
builtin.lsp_code_actions = require('telescope.builtin.lsp').code_actions
builtin.lsp_code_actions = require("telescope.builtin.lsp").code_actions
--- Lists any LSP actions for a given range, that can be triggered with `<cr>`
---@param opts table: options to pass to the picker
builtin.lsp_range_code_actions = require('telescope.builtin.lsp').range_code_actions
builtin.lsp_range_code_actions = require("telescope.builtin.lsp").range_code_actions
--- Lists LSP document symbols in the current buffer
--- - Default keymaps:
@@ -328,7 +328,7 @@ builtin.lsp_range_code_actions = require('telescope.builtin.lsp').range_code_act
---@param opts table: options to pass to the picker
---@field ignore_filename type: string with file to ignore
---@field symbols string|table: filter results by symbol kind(s)
builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
builtin.lsp_document_symbols = require("telescope.builtin.lsp").document_symbols
--- Lists LSP document symbols in the current workspace
--- - Default keymaps:
@@ -336,13 +336,13 @@ builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
---@param opts table: options to pass to the picker
---@field ignore_filename string: file(s) to ignore
---@field symbols string|table: filter results by symbol kind(s)
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols
builtin.lsp_workspace_symbols = require("telescope.builtin.lsp").workspace_symbols
--- Dynamically lists LSP for all workspace symbols
--- - Default keymaps:
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
---@param opts table: options to pass to the picker
builtin.lsp_dynamic_workspace_symbols = require('telescope.builtin.lsp').dynamic_workspace_symbols
builtin.lsp_dynamic_workspace_symbols = require("telescope.builtin.lsp").dynamic_workspace_symbols
--- Lists LSP diagnostics for the current buffer
--- - Fields:
@@ -355,7 +355,7 @@ builtin.lsp_dynamic_workspace_symbols = require('telescope.builtin.lsp').dynamic
---@field severity_bound string|number: keep diagnostics equal or less severe wrt severity name (string) or id (number)
---@field no_sign bool: hide LspDiagnosticSigns from Results (default is false)
---@field line_width number: set length of diagnostic entry text in Results
builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
builtin.lsp_document_diagnostics = require("telescope.builtin.lsp").diagnostics
--- Lists LSP diagnostics for the current workspace if supported, otherwise searches in all open buffers
--- - Fields:
@@ -368,10 +368,10 @@ builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
---@field severity_bound string|number: keep diagnostics equal or less severe wrt severity name (string) or id (number)
---@field no_sign bool: hide LspDiagnosticSigns from Results (default is false)
---@field line_width number: set length of diagnostic entry text in Results
builtin.lsp_workspace_diagnostics = require('telescope.builtin.lsp').workspace_diagnostics
builtin.lsp_workspace_diagnostics = require("telescope.builtin.lsp").workspace_diagnostics
local apply_config = function(mod)
local pickers_conf = require('telescope.config').pickers
local pickers_conf = require("telescope.config").pickers
for k, v in pairs(mod) do
local pconf = vim.deepcopy(pickers_conf[k] or {})
if pconf.theme then

View File

@@ -1,15 +1,15 @@
local actions = require('telescope.actions')
local action_set = require('telescope.actions.set')
local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local Path = require('plenary.path')
local pickers = require('telescope.pickers')
local previewers = require('telescope.previewers')
local sorters = require('telescope.sorters')
local utils = require('telescope.utils')
local actions = require "telescope.actions"
local action_set = require "telescope.actions.set"
local action_state = require "telescope.actions.state"
local finders = require "telescope.finders"
local make_entry = require "telescope.make_entry"
local Path = require "plenary.path"
local pickers = require "telescope.pickers"
local previewers = require "telescope.previewers"
local sorters = require "telescope.sorters"
local utils = require "telescope.utils"
local conf = require('telescope.config').values
local conf = require("telescope.config").values
local filter = vim.tbl_filter
@@ -25,7 +25,7 @@ internal.builtin = function(opts)
local objs = {}
for k, v in pairs(require'telescope.builtin') do
for k, v in pairs(require "telescope.builtin") do
local debug_info = debug.getinfo(v)
table.insert(objs, {
filename = string.sub(debug_info.source, 2),
@@ -33,11 +33,11 @@ internal.builtin = function(opts)
})
end
local title = 'Telescope Builtin'
local title = "Telescope Builtin"
if opts.include_extensions then
title = 'Telescope Pickers'
for ext, funcs in pairs(require'telescope'.extensions) do
title = "Telescope Pickers"
for ext, funcs in pairs(require("telescope").extensions) do
for func_name, func_obj in pairs(funcs) do
local debug_info = debug.getinfo(func_obj)
table.insert(objs, {
@@ -50,7 +50,7 @@ internal.builtin = function(opts)
pickers.new(opts, {
prompt_title = title,
finder = finders.new_table {
finder = finders.new_table {
results = objs,
entry_maker = function(entry)
return {
@@ -58,44 +58,44 @@ internal.builtin = function(opts)
text = entry.text,
display = entry.text,
ordinal = entry.text,
filename = entry.filename
filename = entry.filename,
}
end
end,
},
previewer = previewers.builtin.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_)
actions.select_default:replace(actions.run_builtin)
return true
end
end,
}):find()
end
internal.planets = function(opts)
local show_pluto = opts.show_pluto or false
local sourced_file = require('plenary.debug_utils').sourced_filepath()
local sourced_file = require("plenary.debug_utils").sourced_filepath()
local base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h:h")
local globbed_files = vim.fn.globpath(base_directory .. '/data/memes/planets/', '*', true, true)
local globbed_files = vim.fn.globpath(base_directory .. "/data/memes/planets/", "*", true, true)
local acceptable_files = {}
for _, v in ipairs(globbed_files) do
if show_pluto or not v:find("pluto") then
table.insert(acceptable_files,vim.fn.fnamemodify(v, ':t'))
if show_pluto or not v:find "pluto" then
table.insert(acceptable_files, vim.fn.fnamemodify(v, ":t"))
end
end
pickers.new {
prompt_title = 'Planets',
pickers.new({
prompt_title = "Planets",
finder = finders.new_table {
results = acceptable_files,
entry_maker = function(line)
return {
ordinal = line,
display = line,
filename = base_directory .. '/data/memes/planets/' .. line,
filename = base_directory .. "/data/memes/planets/" .. line,
}
end
end,
},
previewer = previewers.cat.new(opts),
sorter = conf.generic_sorter(opts),
@@ -109,14 +109,16 @@ internal.planets = function(opts)
return true
end,
}:find()
}):find()
end
internal.symbols = function(opts)
local files = vim.api.nvim_get_runtime_file('data/telescope-sources/*.json', true)
local files = vim.api.nvim_get_runtime_file("data/telescope-sources/*.json", true)
if table.getn(files) == 0 then
print("No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim " ..
"for some prebuild symbols or how to create you own symbol source.")
print(
"No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim "
.. "for some prebuild symbols or how to create you own symbol source."
)
return
end
@@ -142,31 +144,31 @@ internal.symbols = function(opts)
end
pickers.new(opts, {
prompt_title = 'Symbols',
finder = finders.new_table {
results = results,
prompt_title = "Symbols",
finder = finders.new_table {
results = results,
entry_maker = function(entry)
return {
value = entry,
ordinal = entry[1] .. ' ' .. entry[2],
display = entry[1] .. ' ' .. entry[2],
ordinal = entry[1] .. " " .. entry[2],
display = entry[1] .. " " .. entry[2],
}
end
end,
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(_)
actions.select_default:replace(actions.insert_symbol)
return true
end
end,
}):find()
end
internal.commands = function(opts)
pickers.new(opts, {
prompt_title = 'Commands',
prompt_title = "Commands",
finder = finders.new_table {
results = (function()
local command_iter = vim.api.nvim_get_commands({})
local command_iter = vim.api.nvim_get_commands {}
local commands = {}
for _, cmd in pairs(command_iter) do
@@ -195,7 +197,7 @@ internal.commands = function(opts)
end)
return true
end
end,
}):find()
end
@@ -207,9 +209,9 @@ internal.quickfix = function(opts)
end
pickers.new(opts, {
prompt_title = 'Quickfix',
finder = finders.new_table {
results = locations,
prompt_title = "Quickfix",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts),
},
previewer = conf.qflist_previewer(opts),
@@ -230,9 +232,9 @@ internal.loclist = function(opts)
end
pickers.new(opts, {
prompt_title = 'Loclist',
finder = finders.new_table {
results = locations,
prompt_title = "Loclist",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts),
},
previewer = conf.qflist_previewer(opts),
@@ -248,8 +250,8 @@ internal.oldfiles = function(opts)
local results = {}
if opts.include_current_session then
for _, buffer in ipairs(vim.split(vim.fn.execute(':buffers! t'), "\n")) do
local match = tonumber(string.match(buffer, '%s*(%d+)'))
for _, buffer in ipairs(vim.split(vim.fn.execute ":buffers! t", "\n")) do
local match = tonumber(string.match(buffer, "%s*(%d+)"))
if match then
local file = vim.api.nvim_buf_get_name(match)
if vim.loop.fs_stat(file) and match ~= current_buffer then
@@ -267,15 +269,15 @@ internal.oldfiles = function(opts)
if opts.cwd_only then
local cwd = vim.loop.cwd()
cwd = cwd:gsub([[\]],[[\\]])
cwd = cwd:gsub([[\]], [[\\]])
results = vim.tbl_filter(function(file)
return vim.fn.matchstrpos(file, cwd)[2] ~= -1
end, results)
end
pickers.new(opts, {
prompt_title = 'Oldfiles',
finder = finders.new_table{
prompt_title = "Oldfiles",
finder = finders.new_table {
results = results,
entry_maker = opts.entry_maker or make_entry.gen_from_file(opts),
},
@@ -285,7 +287,7 @@ internal.oldfiles = function(opts)
end
internal.command_history = function(opts)
local history_string = vim.fn.execute('history cmd')
local history_string = vim.fn.execute "history cmd"
local history_list = vim.split(history_string, "\n")
local results = {}
@@ -296,15 +298,15 @@ internal.command_history = function(opts)
end
pickers.new(opts, {
prompt_title = 'Command History',
prompt_title = "Command History",
finder = finders.new_table(results),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
map('i', '<CR>', actions.set_command_line)
map('n', '<CR>', actions.set_command_line)
map('n', '<C-e>', actions.edit_command_line)
map('i', '<C-e>', actions.edit_command_line)
map("i", "<CR>", actions.set_command_line)
map("n", "<CR>", actions.set_command_line)
map("n", "<C-e>", actions.edit_command_line)
map("i", "<C-e>", actions.edit_command_line)
-- TODO: Find a way to insert the text... it seems hard.
-- map('i', '<C-i>', actions.insert_value, { expr = true })
@@ -315,7 +317,7 @@ internal.command_history = function(opts)
end
internal.search_history = function(opts)
local search_string = vim.fn.execute('history search')
local search_string = vim.fn.execute "history search"
local search_list = vim.split(search_string, "\n")
local results = {}
@@ -326,15 +328,15 @@ internal.search_history = function(opts)
end
pickers.new(opts, {
prompt_title = 'Search History',
prompt_title = "Search History",
finder = finders.new_table(results),
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
map('i', '<CR>', actions.set_search_line)
map('n', '<CR>', actions.set_search_line)
map('n', '<C-e>', actions.edit_search_line)
map('i', '<C-e>', actions.edit_search_line)
map("i", "<CR>", actions.set_search_line)
map("n", "<CR>", actions.set_search_line)
map("n", "<C-e>", actions.edit_search_line)
map("i", "<C-e>", actions.edit_search_line)
-- TODO: Find a way to insert the text... it seems hard.
-- map('i', '<C-i>', actions.insert_value, { expr = true })
@@ -346,12 +348,10 @@ end
internal.vim_options = function(opts)
-- Load vim options.
local vim_opts = loadfile(
Path:new({utils.data_directory(), 'options', 'options.lua'}):absolute()
)().options
local vim_opts = loadfile(Path:new({ utils.data_directory(), "options", "options.lua" }):absolute())().options
pickers.new(opts, {
prompt_title = 'options',
prompt_title = "options",
finder = finders.new_table {
results = vim_opts,
entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts),
@@ -403,7 +403,7 @@ internal.vim_options = function(opts)
end)
return true
end
end,
}):find()
end
@@ -411,9 +411,9 @@ internal.help_tags = function(opts)
opts.lang = utils.get_default(opts.lang, vim.o.helplang)
opts.fallback = utils.get_default(opts.fallback, true)
local langs = vim.split(opts.lang, ',', true)
if opts.fallback and not vim.tbl_contains(langs, 'en') then
table.insert(langs, 'en')
local langs = vim.split(opts.lang, ",", true)
if opts.fallback and not vim.tbl_contains(langs, "en") then
table.insert(langs, "en")
end
local langs_map = {}
for _, lang in ipairs(langs) do
@@ -426,18 +426,18 @@ internal.help_tags = function(opts)
if tag_files[lang] then
table.insert(tag_files[lang], file)
else
tag_files[lang] = {file}
tag_files[lang] = { file }
end
end
end
local help_files = {}
local all_files = vim.fn.globpath(vim.o.runtimepath, 'doc/*', 1, 1)
local all_files = vim.fn.globpath(vim.o.runtimepath, "doc/*", 1, 1)
for _, fullpath in ipairs(all_files) do
local file = utils.path_tail(fullpath)
if file == 'tags' then
add_tag_file('en', fullpath)
elseif file:match('^tags%-..$') then
if file == "tags" then
add_tag_file("en", fullpath)
elseif file:match "^tags%-..$" then
local lang = file:sub(-2)
add_tag_file(lang, fullpath)
else
@@ -450,10 +450,10 @@ internal.help_tags = function(opts)
local delimiter = string.char(9)
for _, lang in ipairs(langs) do
for _, file in ipairs(tag_files[lang] or {}) do
local lines = vim.split(Path:new(file):read(), '\n', true)
local lines = vim.split(Path:new(file):read(), "\n", true)
for _, line in ipairs(lines) do
-- TODO: also ignore tagComment starting with ';'
if not line:match'^!_TAG_' then
if not line:match "^!_TAG_" then
local fields = vim.split(line, delimiter, true)
if #fields == 3 and not tags_map[fields[1]] then
table.insert(tags, {
@@ -470,16 +470,16 @@ internal.help_tags = function(opts)
end
pickers.new(opts, {
prompt_title = 'Help',
prompt_title = "Help",
finder = finders.new_table {
results = tags,
entry_maker = function(entry)
return {
value = entry.name .. '@' .. entry.lang,
value = entry.name .. "@" .. entry.lang,
display = entry.name,
ordinal = entry.name,
filename = entry.filename,
cmd = entry.cmd
cmd = entry.cmd,
}
end,
},
@@ -489,51 +489,51 @@ internal.help_tags = function(opts)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if cmd == 'default' or cmd == 'horizontal' then
vim.cmd('help ' .. selection.value)
elseif cmd == 'vertical' then
vim.cmd('vert bo help ' .. selection.value)
elseif cmd == 'tab' then
vim.cmd('tab help ' .. selection.value)
if cmd == "default" or cmd == "horizontal" then
vim.cmd("help " .. selection.value)
elseif cmd == "vertical" then
vim.cmd("vert bo help " .. selection.value)
elseif cmd == "tab" then
vim.cmd("tab help " .. selection.value)
end
end)
return true
end
end,
}):find()
end
internal.man_pages = function(opts)
opts.sections = utils.get_default(opts.sections, {'1'})
assert(vim.tbl_islist(opts.sections), 'sections should be a list')
opts.sections = utils.get_default(opts.sections, { "1" })
assert(vim.tbl_islist(opts.sections), "sections should be a list")
opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function()
local is_darwin = vim.loop.os_uname().sysname == 'Darwin'
return is_darwin and {'apropos', ' '} or {'apropos', ''}
local is_darwin = vim.loop.os_uname().sysname == "Darwin"
return is_darwin and { "apropos", " " } or { "apropos", "" }
end)
opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts)
pickers.new(opts, {
prompt_title = 'Man',
finder = finders.new_oneshot_job(opts.man_cmd, opts),
prompt_title = "Man",
finder = finders.new_oneshot_job(opts.man_cmd, opts),
previewer = previewers.man.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
local args = selection.section .. ' ' .. selection.value
local args = selection.section .. " " .. selection.value
actions.close(prompt_bufnr)
if cmd == 'default' or cmd == 'horizontal' then
vim.cmd('Man ' .. args)
elseif cmd == 'vertical' then
vim.cmd('vert bo Man ' .. args)
elseif cmd == 'tab' then
vim.cmd('tab Man ' .. args)
if cmd == "default" or cmd == "horizontal" then
vim.cmd("Man " .. args)
elseif cmd == "vertical" then
vim.cmd("vert bo Man " .. args)
elseif cmd == "tab" then
vim.cmd("tab Man " .. args)
end
end)
return true
end
end,
}):find()
end
@@ -543,9 +543,11 @@ internal.reloader = function(opts)
-- filter out packages we don't want and track the longest package name
opts.column_len = 0
for index, module_name in pairs(package_list) do
if type(require(module_name)) ~= 'table' or
module_name:sub(1,1) == "_" or
package.searchpath(module_name, package.path) == nil then
if
type(require(module_name)) ~= "table"
or module_name:sub(1, 1) == "_"
or package.searchpath(module_name, package.path) == nil
then
table.remove(package_list, index)
elseif #module_name > opts.column_len then
opts.column_len = #module_name
@@ -553,7 +555,7 @@ internal.reloader = function(opts)
end
pickers.new(opts, {
prompt_title = 'Packages',
prompt_title = "Packages",
finder = finders.new_table {
results = package_list,
entry_maker = opts.entry_maker or make_entry.gen_from_packages(opts),
@@ -566,19 +568,19 @@ internal.reloader = function(opts)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
require('plenary.reload').reload_module(selection.value)
require("plenary.reload").reload_module(selection.value)
print(string.format("[%s] - module reloaded", selection.value))
end)
return true
end
end,
}):find()
end
internal.buffers = function(opts)
local bufnrs = filter(function(b)
if 1 ~= vim.fn.buflisted(b) then
return false
return false
end
-- only hide unloaded buffers if opts.show_all_buffers is false, keep them listed if true or nil
if opts.show_all_buffers == false and not vim.api.nvim_buf_is_loaded(b) then
@@ -592,7 +594,9 @@ internal.buffers = function(opts)
end
return true
end, vim.api.nvim_list_bufs())
if not next(bufnrs) then return end
if not next(bufnrs) then
return
end
if opts.sort_mru then
table.sort(bufnrs, function(a, b)
return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused
@@ -602,7 +606,7 @@ internal.buffers = function(opts)
local buffers = {}
local default_selection_idx = 1
for _, bufnr in ipairs(bufnrs) do
local flag = bufnr == vim.fn.bufnr('') and '%' or (bufnr == vim.fn.bufnr('#') and '#' or ' ')
local flag = bufnr == vim.fn.bufnr "" and "%" or (bufnr == vim.fn.bufnr "#" and "#" or " ")
if opts.sort_lastused and not opts.ignore_current_buffer and flag == "#" then
default_selection_idx = 2
@@ -628,10 +632,10 @@ internal.buffers = function(opts)
end
pickers.new(opts, {
prompt_title = 'Buffers',
finder = finders.new_table {
prompt_title = "Buffers",
finder = finders.new_table {
results = buffers,
entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_buffer(opts),
},
previewer = conf.grep_previewer(opts),
sorter = conf.generic_sorter(opts),
@@ -640,7 +644,7 @@ internal.buffers = function(opts)
end
internal.colorscheme = function(opts)
local before_color = vim.api.nvim_exec('colorscheme', true)
local before_color = vim.api.nvim_exec("colorscheme", true)
local need_restore = true
local colors = opts.colors or { before_color }
@@ -652,10 +656,7 @@ internal.colorscheme = function(opts)
colors,
vim.tbl_filter(function(color)
return color ~= before_color
end, vim.fn.getcompletion(
'',
'color'
))
end, vim.fn.getcompletion("", "color"))
)
local previewer
@@ -681,7 +682,7 @@ internal.colorscheme = function(opts)
del_win(status.preview_win)
del_win(status.preview_border_win)
end
vim.cmd('colorscheme ' .. entry.value)
vim.cmd("colorscheme " .. entry.value)
end,
}
else
@@ -697,14 +698,14 @@ internal.colorscheme = function(opts)
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
end
vim.cmd('colorscheme ' .. entry.value)
vim.cmd("colorscheme " .. entry.value)
end,
}
end
end
local picker = pickers.new(opts, {
prompt_title = 'Change Colorscheme',
prompt_title = "Change Colorscheme",
finder = finders.new_table {
results = colors,
},
@@ -716,7 +717,7 @@ internal.colorscheme = function(opts)
actions.close(prompt_bufnr)
need_restore = false
vim.cmd('colorscheme ' .. selection.value)
vim.cmd("colorscheme " .. selection.value)
end)
return true
@@ -729,7 +730,7 @@ internal.colorscheme = function(opts)
picker.close_windows = function(status)
close_windows(status)
if need_restore then
vim.cmd('colorscheme ' .. before_color)
vim.cmd("colorscheme " .. before_color)
end
end
end
@@ -744,8 +745,8 @@ internal.marks = function(opts)
-- Pop off the header.
table.remove(marks_table, 1)
pickers.new(opts,{
prompt_title = 'Marks',
pickers.new(opts, {
prompt_title = "Marks",
finder = finders.new_table {
results = marks_table,
entry_maker = opts.entry_maker or make_entry.gen_from_marks(opts),
@@ -756,7 +757,7 @@ internal.marks = function(opts)
end
internal.registers = function(opts)
local registers_table = {"\"", "_", "#", "=", "_", "/", "*", "+", ":", ".", "%"}
local registers_table = { '"', "_", "#", "=", "_", "/", "*", "+", ":", ".", "%" }
-- named
for i = 0, 9 do
@@ -768,8 +769,8 @@ internal.registers = function(opts)
table.insert(registers_table, string.char(i))
end
pickers.new(opts,{
prompt_title = 'Registers',
pickers.new(opts, {
prompt_title = "Registers",
finder = finders.new_table {
results = registers_table,
entry_maker = opts.entry_maker or make_entry.gen_from_registers(opts),
@@ -778,7 +779,7 @@ internal.registers = function(opts)
sorter = sorters.get_levenshtein_sorter(),
attach_mappings = function(_, map)
actions.select_default:replace(actions.paste_register)
map('i', '<C-e>', actions.edit_register)
map("i", "<C-e>", actions.edit_register)
return true
end,
@@ -787,7 +788,7 @@ end
-- TODO: make filtering include the mapping and the action
internal.keymaps = function(opts)
local modes = {"n", "i", "c"}
local modes = { "n", "i", "c" }
local keymaps_table = {}
for _, mode in pairs(modes) do
@@ -802,7 +803,7 @@ internal.keymaps = function(opts)
end
pickers.new(opts, {
prompt_title = 'Key Maps',
prompt_title = "Key Maps",
finder = finders.new_table {
results = keymaps_table,
entry_maker = function(line)
@@ -810,29 +811,27 @@ internal.keymaps = function(opts)
valid = line ~= "",
value = line,
ordinal = utils.display_termcodes(line.lhs) .. line.rhs,
display = line.mode .. ' ' .. utils.display_termcodes(line.lhs) .. ' ' .. line.rhs
display = line.mode .. " " .. utils.display_termcodes(line.lhs) .. " " .. line.rhs,
}
end
end,
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true),
"t", true)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(selection.value.lhs, true, false, true), "t", true)
return actions.close(prompt_bufnr)
end)
return true
end
end,
}):find()
end
internal.filetypes = function(opts)
local filetypes = vim.fn.getcompletion('', 'filetype')
local filetypes = vim.fn.getcompletion("", "filetype")
pickers.new(opts, {
prompt_title = 'Filetypes',
prompt_title = "Filetypes",
finder = finders.new_table {
results = filetypes,
},
@@ -841,28 +840,28 @@ internal.filetypes = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('setfiletype ' .. selection[1])
vim.cmd("setfiletype " .. selection[1])
end)
return true
end
end,
}):find()
end
internal.highlights = function(opts)
local highlights = vim.fn.getcompletion('', 'highlight')
local highlights = vim.fn.getcompletion("", "highlight")
pickers.new(opts, {
prompt_title = 'Highlights',
prompt_title = "Highlights",
finder = finders.new_table {
results = highlights,
entry_maker = opts.entry_maker or make_entry.gen_from_highlights(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_highlights(opts),
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('hi ' .. selection.value)
vim.cmd("hi " .. selection.value)
end)
return true
end,
@@ -873,10 +872,10 @@ end
internal.autocommands = function(opts)
local autocmd_table = {}
local pattern = {}
local pattern = {}
pattern.BUFFER = "<buffer=%d+>"
pattern.EVENT = "[%a]+"
pattern.GROUP = "[%a%d_:]+"
pattern.EVENT = "[%a]+"
pattern.GROUP = "[%a%d_:]+"
pattern.INDENT = "^%s%s%s%s" -- match indentation of 4 spaces
local event, group, ft_pat, cmd, source_file, source_lnum
@@ -902,7 +901,7 @@ internal.autocommands = function(opts)
-- non event/group lines
ft_pat = line:match(pattern.INDENT .. "(%S+)")
if ft_pat then
if ft_pat:match("^%d+") then
if ft_pat:match "^%d+" then
ft_pat = "<buffer=" .. ft_pat .. ">"
end
current_ft = ft_pat
@@ -920,13 +919,13 @@ internal.autocommands = function(opts)
end
if current_ft and cmd then
source_file, source_lnum = line:match("Last set from (.*) line (.*)")
source_file, source_lnum = line:match "Last set from (.*) line (.*)"
if source_file then
local autocmd = {}
autocmd.event = current_event
autocmd.group = current_group
autocmd.ft_pattern = current_ft
autocmd.command = cmd
autocmd.event = current_event
autocmd.group = current_group
autocmd.ft_pattern = current_ft
autocmd.command = cmd
autocmd.source_file = source_file
autocmd.source_lnum = source_lnum
table.insert(autocmd_table, autocmd)
@@ -937,12 +936,12 @@ internal.autocommands = function(opts)
end
local cmd_output = vim.fn.execute("verb autocmd *", "silent")
for line in cmd_output:gmatch("[^\r\n]+") do
for line in cmd_output:gmatch "[^\r\n]+" do
inner_loop(line)
end
pickers.new(opts,{
prompt_title = 'autocommands',
pickers.new(opts, {
prompt_title = "autocommands",
finder = finders.new_table {
results = autocmd_table,
entry_maker = opts.entry_maker or make_entry.gen_from_autocommands(opts),
@@ -953,22 +952,24 @@ internal.autocommands = function(opts)
action_set.select:replace(function(_, type)
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd(action_state.select_key_to_edit_key(type) .. ' ' .. selection.value)
vim.cmd(action_state.select_key_to_edit_key(type) .. " " .. selection.value)
end)
return true
end
end,
}):find()
end
internal.spell_suggest = function(opts)
if not vim.wo.spell then return false end
if not vim.wo.spell then
return false
end
local cursor_word = vim.fn.expand("<cword>")
local cursor_word = vim.fn.expand "<cword>"
local suggestions = vim.fn.spellsuggest(cursor_word)
pickers.new(opts, {
prompt_title = 'Spelling Suggestions',
prompt_title = "Spelling Suggestions",
finder = finders.new_table {
results = suggestions,
},
@@ -977,11 +978,11 @@ internal.spell_suggest = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd('normal! ciw' .. selection[1])
vim.cmd('stopinsert')
vim.cmd("normal! ciw" .. selection[1])
vim.cmd "stopinsert"
end)
return true
end
end,
}):find()
end
@@ -999,22 +1000,17 @@ internal.tagstack = function(opts)
tag.lnum = tag.from[2]
tag.col = tag.from[3]
tag.text = vim.api.nvim_buf_get_lines(
tag.bufnr,
tag.lnum - 1,
tag.lnum,
false
)[1] or ''
tag.text = vim.api.nvim_buf_get_lines(tag.bufnr, tag.lnum - 1, tag.lnum, false)[1] or ""
end
end
if vim.tbl_isempty(tags) then
print("No tagstack available")
print "No tagstack available"
return
end
pickers.new(opts, {
prompt_title = 'TagStack',
prompt_title = "TagStack",
finder = finders.new_table {
results = tags,
entry_maker = make_entry.gen_from_quickfix(opts),
@@ -1032,14 +1028,14 @@ internal.jumplist = function(opts)
local sorted_jumplist = {}
for i = #jumplist, 1, -1 do
if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum+1,
false)[1] or ''
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum + 1, false)[1]
or ""
table.insert(sorted_jumplist, jumplist[i])
end
end
pickers.new(opts, {
prompt_title = 'Jumplist',
prompt_title = "Jumplist",
finder = finders.new_table {
results = sorted_jumplist,
entry_maker = make_entry.gen_from_quickfix(opts),

View File

@@ -1,16 +1,16 @@
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local pickers = require('telescope.pickers')
local entry_display = require('telescope.pickers.entry_display')
local utils = require('telescope.utils')
local strings = require('plenary.strings')
local a = require('plenary.async_lib')
local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local finders = require "telescope.finders"
local make_entry = require "telescope.make_entry"
local pickers = require "telescope.pickers"
local entry_display = require "telescope.pickers.entry_display"
local utils = require "telescope.utils"
local strings = require "plenary.strings"
local a = require "plenary.async_lib"
local async, await = a.async, a.await
local channel = a.util.channel
local conf = require('telescope.config').values
local conf = require("telescope.config").values
local lsp = {}
@@ -36,8 +36,8 @@ lsp.references = function(opts)
end
pickers.new(opts, {
prompt_title = 'LSP References',
finder = finders.new_table {
prompt_title = "LSP References",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts),
},
@@ -81,11 +81,11 @@ local function list_or_jump(action, title, opts)
end
lsp.definitions = function(opts)
return list_or_jump("textDocument/definition", 'LSP Definitions', opts)
return list_or_jump("textDocument/definition", "LSP Definitions", opts)
end
lsp.implementations = function(opts)
return list_or_jump("textDocument/implementation", 'LSP Implementations', opts)
return list_or_jump("textDocument/implementation", "LSP Implementations", opts)
end
lsp.document_symbols = function(opts)
@@ -97,7 +97,7 @@ lsp.document_symbols = function(opts)
end
if not results_lsp or vim.tbl_isempty(results_lsp) then
print("No results from textDocument/documentSymbol")
print "No results from textDocument/documentSymbol"
return
end
@@ -118,16 +118,16 @@ lsp.document_symbols = function(opts)
opts.ignore_filename = opts.ignore_filename or true
pickers.new(opts, {
prompt_title = 'LSP Document Symbols',
finder = finders.new_table {
prompt_title = "LSP Document Symbols",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts),
},
previewer = conf.qflist_previewer(opts),
sorter = conf.prefilter_sorter{
sorter = conf.prefilter_sorter {
tag = "symbol_type",
sorter = conf.generic_sorter(opts)
}
sorter = conf.generic_sorter(opts),
},
}):find()
end
@@ -135,7 +135,7 @@ lsp.code_actions = function(opts)
local params = opts.params or vim.lsp.util.make_range_params()
params.context = {
diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
diagnostics = vim.lsp.diagnostic.get_line_diagnostics(),
}
local results_lsp, err = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, opts.timeout or 10000)
@@ -146,7 +146,7 @@ lsp.code_actions = function(opts)
end
if not results_lsp or vim.tbl_isempty(results_lsp) then
print("No results from textDocument/codeAction")
print "No results from textDocument/codeAction"
return
end
@@ -181,7 +181,7 @@ lsp.code_actions = function(opts)
end
if #results == 0 then
print("No code actions available")
print "No code actions available"
return
end
@@ -196,15 +196,15 @@ lsp.code_actions = function(opts)
local function make_display(entry)
return displayer {
{entry.idx .. ":", "TelescopePromptPrefix"},
{entry.command_title},
{entry.client_name, "TelescopeResultsComment"},
{ entry.idx .. ":", "TelescopePromptPrefix" },
{ entry.command_title },
{ entry.client_name, "TelescopeResultsComment" },
}
end
pickers.new(opts, {
prompt_title = 'LSP Code Actions',
finder = finders.new_table {
prompt_title = "LSP Code Actions",
finder = finders.new_table {
results = results,
entry_maker = function(line)
return {
@@ -216,7 +216,7 @@ lsp.code_actions = function(opts)
client_name = line.client_name,
display = make_display,
}
end
end,
},
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
@@ -243,12 +243,12 @@ lsp.code_actions = function(opts)
end
lsp.range_code_actions = function(opts)
opts.params = vim.lsp.util.make_given_range_params()
lsp.code_actions(opts)
opts.params = vim.lsp.util.make_given_range_params()
lsp.code_actions(opts)
end
lsp.workspace_symbols = function(opts)
local params = {query = opts.query or ''}
local params = { query = opts.query or "" }
local results_lsp, err = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000)
if err then
vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err)
@@ -273,24 +273,26 @@ lsp.workspace_symbols = function(opts)
end
if vim.tbl_isempty(locations) then
print("No results from workspace/symbol. Maybe try a different query: " ..
"Telescope lsp_workspace_symbols query=example")
print(
"No results from workspace/symbol. Maybe try a different query: "
.. "Telescope lsp_workspace_symbols query=example"
)
return
end
opts.ignore_filename = utils.get_default(opts.ignore_filename, false)
pickers.new(opts, {
prompt_title = 'LSP Workspace Symbols',
finder = finders.new_table {
prompt_title = "LSP Workspace Symbols",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts),
},
previewer = conf.qflist_previewer(opts),
sorter = conf.prefilter_sorter{
sorter = conf.prefilter_sorter {
tag = "symbol_type",
sorter = conf.generic_sorter(opts)
}
sorter = conf.generic_sorter(opts),
},
}):find()
end
@@ -300,7 +302,7 @@ local function get_workspace_symbols_requester(bufnr)
return async(function(prompt)
local tx, rx = channel.oneshot()
cancel()
_, cancel = vim.lsp.buf_request(bufnr, "workspace/symbol", {query = prompt}, tx)
_, cancel = vim.lsp.buf_request(bufnr, "workspace/symbol", { query = prompt }, tx)
local err, _, results_lsp = await(rx())
assert(not err, err)
@@ -314,13 +316,13 @@ lsp.dynamic_workspace_symbols = function(opts)
local curr_bufnr = vim.api.nvim_get_current_buf()
pickers.new(opts, {
prompt_title = 'LSP Dynamic Workspace Symbols',
finder = finders.new_dynamic {
prompt_title = "LSP Dynamic Workspace Symbols",
finder = finders.new_dynamic {
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts),
fn = get_workspace_symbols_requester(curr_bufnr),
},
previewer = conf.qflist_previewer(opts),
sorter = conf.generic_sorter()
sorter = conf.generic_sorter(),
}):find()
end
@@ -328,29 +330,29 @@ lsp.diagnostics = function(opts)
local locations = utils.diagnostics_to_tbl(opts)
if vim.tbl_isempty(locations) then
print('No diagnostics found')
print "No diagnostics found"
return
end
opts.path_display = utils.get_default(opts.path_display, 'hidden')
opts.path_display = utils.get_default(opts.path_display, "hidden")
pickers.new(opts, {
prompt_title = 'LSP Document Diagnostics',
prompt_title = "LSP Document Diagnostics",
finder = finders.new_table {
results = locations,
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_diagnostics(opts)
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_diagnostics(opts),
},
previewer = conf.qflist_previewer(opts),
sorter = conf.prefilter_sorter{
sorter = conf.prefilter_sorter {
tag = "type",
sorter = conf.generic_sorter(opts)
}
sorter = conf.generic_sorter(opts),
},
}):find()
end
lsp.workspace_diagnostics = function(opts)
opts = utils.get_default(opts, {})
opts.path_display = utils.get_default(opts.path_display, {})
opts.prompt_title = 'LSP Workspace Diagnostics'
opts.prompt_title = "LSP Workspace Diagnostics"
opts.get_all = true
lsp.diagnostics(opts)
end
@@ -361,14 +363,16 @@ local function check_capabilities(feature)
local supported_client = false
for _, client in pairs(clients) do
supported_client = client.resolved_capabilities[feature]
if supported_client then break end
if supported_client then
break
end
end
if supported_client then
return true
else
if #clients == 0 then
print("LSP: no client attached")
print "LSP: no client attached"
else
print("LSP: server does not support " .. feature)
end
@@ -377,11 +381,11 @@ local function check_capabilities(feature)
end
local feature_map = {
["code_actions"] = "code_action",
["document_symbols"] = "document_symbol",
["references"] = "find_references",
["definitions"] = "goto_definition",
["implementations"] = "implementation",
["code_actions"] = "code_action",
["document_symbols"] = "document_symbol",
["references"] = "find_references",
["definitions"] = "goto_definition",
["implementations"] = "implementation",
["workspace_symbols"] = "workspace_symbol",
}