feat: switch to telescope.lua (#1873)
Co-authored-by: Christian Clason <christian.clason@uni-due.de>
This commit is contained in:
@@ -27,8 +27,7 @@
|
||||
---@brief ]]
|
||||
|
||||
if 1 ~= vim.fn.has "nvim-0.7.0" then
|
||||
vim.api.nvim_err_writeln "This plugins requires neovim 0.7.0"
|
||||
vim.api.nvim_err_writeln "Please update your neovim."
|
||||
vim.api.nvim_err_writeln "Telescope.nvim requires at least nvim-0.7.0. See `:h telescope.changelog-1851`"
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
144
plugin/telescope.lua
Normal file
144
plugin/telescope.lua
Normal file
@@ -0,0 +1,144 @@
|
||||
if 1 ~= vim.fn.has "nvim-0.7.0" then
|
||||
vim.api.nvim_err_writeln "Telescope.nvim requires at least nvim-0.7.0. See `:h telescope.changelog-1851`"
|
||||
return
|
||||
end
|
||||
|
||||
if vim.g.loaded_telescope == 1 then
|
||||
return
|
||||
end
|
||||
vim.g.loaded_telescope = 1
|
||||
|
||||
local highlights = {
|
||||
-- Sets the highlight for selected items within the picker.
|
||||
TelescopeSelection = { default = true, link = "Visual" },
|
||||
TelescopeSelectionCaret = { default = true, link = "TelescopeSelection" },
|
||||
TelescopeMultiSelection = { default = true, link = "Type" },
|
||||
TelescopeMultiIcon = { default = true, link = "Identifier" },
|
||||
|
||||
-- "Normal" in the floating windows created by telescope.
|
||||
TelescopeNormal = { default = true, link = "Normal" },
|
||||
TelescopePreviewNormal = { default = true, link = "TelescopeNormal" },
|
||||
TelescopePromptNormal = { default = true, link = "TelescopeNormal" },
|
||||
TelescopeResultsNormal = { default = true, link = "TelescopeNormal" },
|
||||
|
||||
-- Border highlight groups.
|
||||
-- Use TelescopeBorder to override the default.
|
||||
-- Otherwise set them specifically
|
||||
TelescopeBorder = { default = true, link = "TelescopeNormal" },
|
||||
TelescopePromptBorder = { default = true, link = "TelescopeBorder" },
|
||||
TelescopeResultsBorder = { default = true, link = "TelescopeBorder" },
|
||||
TelescopePreviewBorder = { default = true, link = "TelescopeBorder" },
|
||||
|
||||
-- Title highlight groups.
|
||||
-- Use TelescopeTitle to override the default.
|
||||
-- Otherwise set them specifically
|
||||
TelescopeTitle = { default = true, link = "TelescopeBorder" },
|
||||
TelescopePromptTitle = { default = true, link = "TelescopeTitle" },
|
||||
TelescopeResultsTitle = { default = true, link = "TelescopeTitle" },
|
||||
TelescopePreviewTitle = { default = true, link = "TelescopeTitle" },
|
||||
|
||||
TelescopePromptCounter = { default = true, link = "NonText" },
|
||||
|
||||
-- Used for highlighting characters that you match.
|
||||
TelescopeMatching = { default = true, link = "Special" },
|
||||
|
||||
-- Used for the prompt prefix
|
||||
TelescopePromptPrefix = { default = true, link = "Identifier" },
|
||||
|
||||
-- Used for highlighting the matched line inside Previewer. Works only for (vim_buffer_ previewer)
|
||||
TelescopePreviewLine = { default = true, link = "Visual" },
|
||||
TelescopePreviewMatch = { default = true, link = "Search" },
|
||||
|
||||
TelescopePreviewPipe = { default = true, link = "Constant" },
|
||||
TelescopePreviewCharDev = { default = true, link = "Constant" },
|
||||
TelescopePreviewDirectory = { default = true, link = "Directory" },
|
||||
TelescopePreviewBlock = { default = true, link = "Constant" },
|
||||
TelescopePreviewLink = { default = true, link = "Special" },
|
||||
TelescopePreviewSocket = { default = true, link = "Statement" },
|
||||
TelescopePreviewRead = { default = true, link = "Constant" },
|
||||
TelescopePreviewWrite = { default = true, link = "Statement" },
|
||||
TelescopePreviewExecute = { default = true, link = "String" },
|
||||
TelescopePreviewHyphen = { default = true, link = "NonText" },
|
||||
TelescopePreviewSticky = { default = true, link = "Keyword" },
|
||||
TelescopePreviewSize = { default = true, link = "String" },
|
||||
TelescopePreviewUser = { default = true, link = "Constant" },
|
||||
TelescopePreviewGroup = { default = true, link = "Constant" },
|
||||
TelescopePreviewDate = { default = true, link = "Directory" },
|
||||
TelescopePreviewMessage = { default = true, link = "TelescopePreviewNormal" },
|
||||
TelescopePreviewMessageFillchar = { default = true, link = "TelescopePreviewMessage" },
|
||||
|
||||
-- Used for Picker specific Results highlighting
|
||||
TelescopeResultsClass = { default = true, link = "Function" },
|
||||
TelescopeResultsConstant = { default = true, link = "Constant" },
|
||||
TelescopeResultsField = { default = true, link = "Function" },
|
||||
TelescopeResultsFunction = { default = true, link = "Function" },
|
||||
TelescopeResultsMethod = { default = true, link = "Method" },
|
||||
TelescopeResultsOperator = { default = true, link = "Operator" },
|
||||
TelescopeResultsStruct = { default = true, link = "Struct" },
|
||||
TelescopeResultsVariable = { default = true, link = "SpecialChar" },
|
||||
|
||||
TelescopeResultsLineNr = { default = true, link = "LineNr" },
|
||||
TelescopeResultsIdentifier = { default = true, link = "Identifier" },
|
||||
TelescopeResultsNumber = { default = true, link = "Number" },
|
||||
TelescopeResultsComment = { default = true, link = "Comment" },
|
||||
TelescopeResultsSpecialComment = { default = true, link = "SpecialComment" },
|
||||
TelescopeResultsFileIcon = { default = true, link = "Normal" },
|
||||
|
||||
-- Used for git status Results highlighting
|
||||
TelescopeResultsDiffChange = { default = true, link = "DiffChange" },
|
||||
TelescopeResultsDiffAdd = { default = true, link = "DiffAdd" },
|
||||
TelescopeResultsDiffDelete = { default = true, link = "DiffDelete" },
|
||||
TelescopeResultsDiffUntracked = { default = true, link = "NonText" },
|
||||
}
|
||||
|
||||
for k, v in pairs(highlights) do
|
||||
vim.api.nvim_set_hl(0, k, v)
|
||||
end
|
||||
|
||||
-- This is like "<C-R>" in your terminal.
|
||||
-- To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)
|
||||
vim.keymap.set(
|
||||
"c",
|
||||
"<Plug>(TelescopeFuzzyCommandSearch)",
|
||||
"<C-\\>e \"lua require('telescope.builtin').command_history "
|
||||
.. '{ default_text = [=[" . escape(getcmdline(), \'"\') . "]=] }"<CR><CR>',
|
||||
{ silent = true, noremap = true }
|
||||
)
|
||||
|
||||
vim.api.nvim_create_user_command("Telescope", function(opts)
|
||||
require("telescope.command").load_command(opts.line1, opts.line2, opts.count, unpack(opts.fargs))
|
||||
end, {
|
||||
nargs = "*",
|
||||
range = true,
|
||||
complete = function(_, line)
|
||||
local builtin_list = vim.tbl_keys(require "telescope.builtin")
|
||||
local extensions_list = vim.tbl_keys(require("telescope._extensions").manager)
|
||||
|
||||
local l = vim.split(line, "%s+")
|
||||
local n = #l - 2
|
||||
|
||||
if n == 0 then
|
||||
return vim.tbl_filter(function(val)
|
||||
return vim.startswith(val, l[2])
|
||||
end, vim.tbl_extend("force", builtin_list, extensions_list))
|
||||
end
|
||||
|
||||
if n == 1 then
|
||||
local is_extension = vim.tbl_filter(function(val)
|
||||
return val == l[2]
|
||||
end, extensions_list)
|
||||
|
||||
if #is_extension > 0 then
|
||||
local extensions_subcommand_dict = require("telescope.command").get_extensions_subcommand()
|
||||
return vim.tbl_filter(function(val)
|
||||
return vim.startswith(val, l[3])
|
||||
end, extensions_subcommand_dict[l[2]])
|
||||
end
|
||||
end
|
||||
|
||||
local options_list = vim.tbl_keys(require("telescope.config").values)
|
||||
return vim.tbl_filter(function(val)
|
||||
return vim.startswith(val, l[#l])
|
||||
end, options_list)
|
||||
end,
|
||||
})
|
||||
@@ -1,128 +0,0 @@
|
||||
if !has('nvim-0.7.0')
|
||||
echoerr "Telescope.nvim requires at least nvim-0.7.0. See `:h telescope.changelog-1851`"
|
||||
finish
|
||||
end
|
||||
|
||||
if exists('g:loaded_telescope')
|
||||
finish
|
||||
endif
|
||||
let g:loaded_telescope = 1
|
||||
|
||||
" Sets the highlight for selected items within the picker.
|
||||
highlight default link TelescopeSelection Visual
|
||||
highlight default link TelescopeSelectionCaret TelescopeSelection
|
||||
highlight default link TelescopeMultiSelection Type
|
||||
highlight default link TelescopeMultiIcon Identifier
|
||||
|
||||
" "Normal" in the floating windows created by telescope.
|
||||
highlight default link TelescopeNormal Normal
|
||||
highlight default link TelescopePreviewNormal TelescopeNormal
|
||||
highlight default link TelescopePromptNormal TelescopeNormal
|
||||
highlight default link TelescopeResultsNormal TelescopeNormal
|
||||
|
||||
" Border highlight groups.
|
||||
" Use TelescopeBorder to override the default.
|
||||
" Otherwise set them specifically
|
||||
highlight default link TelescopeBorder TelescopeNormal
|
||||
highlight default link TelescopePromptBorder TelescopeBorder
|
||||
highlight default link TelescopeResultsBorder TelescopeBorder
|
||||
highlight default link TelescopePreviewBorder TelescopeBorder
|
||||
|
||||
" Title highlight groups.
|
||||
" Use TelescopeTitle to override the default.
|
||||
" Otherwise set them specifically
|
||||
highlight default link TelescopeTitle TelescopeBorder
|
||||
highlight default link TelescopePromptTitle TelescopeTitle
|
||||
highlight default link TelescopeResultsTitle TelescopeTitle
|
||||
highlight default link TelescopePreviewTitle TelescopeTitle
|
||||
|
||||
highlight default link TelescopePromptCounter NonText
|
||||
|
||||
" Used for highlighting characters that you match.
|
||||
highlight default link TelescopeMatching Special
|
||||
|
||||
" Used for the prompt prefix
|
||||
highlight default link TelescopePromptPrefix Identifier
|
||||
|
||||
" Used for highlighting the matched line inside Previewer. Works only for (vim_buffer_ previewer)
|
||||
highlight default link TelescopePreviewLine Visual
|
||||
highlight default link TelescopePreviewMatch Search
|
||||
|
||||
highlight default link TelescopePreviewPipe Constant
|
||||
highlight default link TelescopePreviewCharDev Constant
|
||||
highlight default link TelescopePreviewDirectory Directory
|
||||
highlight default link TelescopePreviewBlock Constant
|
||||
highlight default link TelescopePreviewLink Special
|
||||
highlight default link TelescopePreviewSocket Statement
|
||||
highlight default link TelescopePreviewNormal Normal
|
||||
highlight default link TelescopePreviewRead Constant
|
||||
highlight default link TelescopePreviewWrite Statement
|
||||
highlight default link TelescopePreviewExecute String
|
||||
highlight default link TelescopePreviewHyphen NonText
|
||||
highlight default link TelescopePreviewSticky Keyword
|
||||
highlight default link TelescopePreviewSize String
|
||||
highlight default link TelescopePreviewUser Constant
|
||||
highlight default link TelescopePreviewGroup Constant
|
||||
highlight default link TelescopePreviewDate Directory
|
||||
highlight default link TelescopePreviewMessage TelescopePreviewNormal
|
||||
highlight default link TelescopePreviewMessageFillchar TelescopePreviewMessage
|
||||
|
||||
" Used for Picker specific Results highlighting
|
||||
highlight default link TelescopeResultsClass Function
|
||||
highlight default link TelescopeResultsConstant Constant
|
||||
highlight default link TelescopeResultsField Function
|
||||
highlight default link TelescopeResultsFunction Function
|
||||
highlight default link TelescopeResultsMethod Method
|
||||
highlight default link TelescopeResultsOperator Operator
|
||||
highlight default link TelescopeResultsStruct Struct
|
||||
highlight default link TelescopeResultsVariable SpecialChar
|
||||
|
||||
highlight default link TelescopeResultsLineNr LineNr
|
||||
highlight default link TelescopeResultsIdentifier Identifier
|
||||
highlight default link TelescopeResultsNumber Number
|
||||
highlight default link TelescopeResultsComment Comment
|
||||
highlight default link TelescopeResultsSpecialComment SpecialComment
|
||||
highlight default link TelescopeResultsFileIcon Normal
|
||||
|
||||
" Used for git status Results highlighting
|
||||
highlight default link TelescopeResultsDiffChange DiffChange
|
||||
highlight default link TelescopeResultsDiffAdd DiffAdd
|
||||
highlight default link TelescopeResultsDiffDelete DiffDelete
|
||||
highlight default link TelescopeResultsDiffUntracked NonText
|
||||
|
||||
" This is like "<C-R>" in your terminal.
|
||||
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)
|
||||
cnoremap <silent> <Plug>(TelescopeFuzzyCommandSearch) <C-\>e
|
||||
\ "lua require('telescope.builtin').command_history {
|
||||
\ default_text = [=[" . escape(getcmdline(), '"') . "]=]
|
||||
\ }"<CR><CR>
|
||||
|
||||
" Telescope builtin lists
|
||||
function! s:telescope_complete(arg,line,pos)
|
||||
let l:builtin_list = luaeval('vim.tbl_keys(require("telescope.builtin"))')
|
||||
let l:extensions_list = luaeval('vim.tbl_keys(require("telescope._extensions").manager)')
|
||||
let l:options_list = luaeval('vim.tbl_keys(require("telescope.config").values)')
|
||||
let l:extensions_subcommand_dict = luaeval('require("telescope.command").get_extensions_subcommand()')
|
||||
|
||||
let list = [extend(l:builtin_list,l:extensions_list),l:options_list]
|
||||
let l = split(a:line[:a:pos-1], '\%(\%(\%(^\|[^\\]\)\\\)\@<!\s\)\+', 1)
|
||||
let n = len(l) - index(l, 'Telescope') - 2
|
||||
|
||||
if n == 0
|
||||
return join(list[0],"\n")
|
||||
endif
|
||||
|
||||
if n == 1
|
||||
if index(l:extensions_list,l[1]) >= 0
|
||||
return join(get(l:extensions_subcommand_dict, l[1], []),"\n")
|
||||
endif
|
||||
return join(list[1],"\n")
|
||||
endif
|
||||
|
||||
if n > 1
|
||||
return join(list[1],"\n")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Telescope Commands with complete
|
||||
command! -nargs=* -range -complete=custom,s:telescope_complete Telescope lua require('telescope.command').load_command(<line1>, <line2>, <count>, unpack({<f-args>}))
|
||||
@@ -3,4 +3,4 @@ set rtp+=../plenary.nvim/
|
||||
set rtp+=../tree-sitter-lua/
|
||||
|
||||
runtime! plugin/plenary.vim
|
||||
runtime! plugin/telescope.vim
|
||||
runtime! plugin/telescope.lua
|
||||
|
||||
Reference in New Issue
Block a user