no coq for latex

This commit is contained in:
EvilMuffinHa 2022-11-08 20:32:39 -05:00
parent 5989e4213d
commit 914b98ff69
4 changed files with 492 additions and 439 deletions

View File

@ -1,5 +1,5 @@
vim.g.coq_settings = { vim.g.coq_settings = {
auto_start = 'shut-up', -- auto_start = 'shut-up',
keymap = { keymap = {
eval_snips = "<Leader>se", eval_snips = "<Leader>se",
}, },
@ -26,9 +26,9 @@ vim.g.coq_settings = {
local coq = require('coq') local coq = require('coq')
require('coq_3p') { require('coq_3p') {
{ src = 'vimtex', short_name = 'TEX'}, { src = 'vimtex', short_name = 'TEX' },
{ src = 'nvimlua', short_name = 'NLUA', conf_only = true}, { src = 'nvimlua', short_name = 'NLUA', conf_only = true },
{ src = 'bc', short_name = 'CALC', precision = 8}, { src = 'bc', short_name = 'CALC', precision = 8 },
} }
@ -38,8 +38,8 @@ lspstatus.register_progress()
local function find_repo_root(names) local function find_repo_root(names)
local util = require("lspconfig.util") local util = require("lspconfig.util")
local config = names.configfiles local config = names.configfiles
for _, i in ipairs(config) do local function matcher(filename, _bufnr)
local gitroot = util.root_pattern('.git')(i) local gitroot = util.root_pattern('.git')(filename)
if gitroot then if gitroot then
for _, file in ipairs(config) do for _, file in ipairs(config) do
if util.path.is_file(util.path.join(gitroot, file)) then if util.path.is_file(util.path.join(gitroot, file)) then
@ -47,49 +47,52 @@ local function find_repo_root(names)
end end
end end
end end
return util.root_pattern(unpack(config))(filename)
end end
return matcher
end end
local lsp_confs = { local lsp_confs = {
sumneko_lua = { sumneko_lua = {
settings = { settings = {
Lua = { Lua = {
-- Settings for working with nvim (copied from https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua) -- Settings for working with nvim (copied from https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua)
runtime = { runtime = {
version = 'LuaJIT', version = 'LuaJIT',
path = runtime_path, path = runtime_path,
}, },
diagnostics = { diagnostics = {
globals = {'vim'}, globals = { 'vim' },
}, },
workspace = { workspace = {
library = vim.api.nvim_get_runtime_file("", true), library = vim.api.nvim_get_runtime_file("", true),
}, },
}, },
}, },
}, },
rust_analyzer = { rust_analyzer = {
cmd_env = { cmd_env = {
CARGO_TARGET_DIR = "/tmp/rust-analyzer" CARGO_TARGET_DIR = "/tmp/rust-analyzer"
}, },
settings = { settings = {
["rust-analyzer"] = { ["rust-analyzer"] = {
checkOnSave = { checkOnSave = {
command = "clippy", command = "clippy",
allTargets = false, allTargets = false,
}, },
cargo = { cargo = {
features = "all", features = "all",
} }
}, },
}, },
}, },
ccls = {}, ccls = {},
jedi_language_server = { jedi_language_server = {
filetypes = { "python", "sage.python" }, filetypes = { "python", "sage.python" },
}, },
gopls = {}, gopls = {},
dartls = {}, dartls = {},
tsserver = { tsserver = {
root_dir = find_repo_root({ root_dir = find_repo_root({
@ -100,17 +103,17 @@ local lsp_confs = {
root_dir = find_repo_root({ root_dir = find_repo_root({
configfiles = { ".eslintrc", ".eslintrc.js", "package.json" } configfiles = { ".eslintrc", ".eslintrc.js", "package.json" }
}), }),
on_new_config = function (config, new_root_dir) on_new_config = function(config, new_root_dir)
local default_config = require('lspconfig.server_configurations.eslint').default_config local default_config = require('lspconfig.server_configurations.eslint').default_config
default_config.on_new_config(config, new_root_dir) default_config.on_new_config(config, new_root_dir)
local util = require('lspconfig.util') local util = require('lspconfig.util')
local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs') local pnp_cjs = util.path.join(new_root_dir, '.pnp.cjs')
local pnp_js = util.path.join(new_root_dir, '.pnp.js') local pnp_js = util.path.join(new_root_dir, '.pnp.js')
if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then if util.path.exists(pnp_cjs) or util.path.exists(pnp_js) then
config.cmd = { 'yarn', 'exec', unpack(default_config.cmd) } config.cmd = { 'yarn', 'exec', unpack(default_config.cmd) }
end end
end end
}, },
svelte = {}, svelte = {},
svls = {}, svls = {},
@ -120,89 +123,123 @@ local lsp_confs = {
local lsp_special_setup = { local lsp_special_setup = {
} }
local function on_attach(client, _bufnr)
lspstatus.on_attach(client)
end
local lspconfig = require('lspconfig') local lspconfig = require('lspconfig')
for server, conf in pairs(lsp_confs) do for server, conf in pairs(lsp_confs) do
local source_on_attach = conf.on_attach local source_on_attach = conf.on_attach
if source_on_attach == nil then if source_on_attach == nil then
conf.on_attach = on_attach conf.on_attach = on_attach
else else
conf.on_attach = function(client, bufnr) conf.on_attach = function(client, bufnr)
on_attach(client, bufnr) on_attach(client, bufnr)
source_on_attach(client, bufnr) source_on_attach(client, bufnr)
end end
end end
conf.capabilities = vim.tbl_deep_extend( conf.capabilities = vim.tbl_deep_extend(
"keep", "keep",
conf.capabilities or {}, conf.capabilities or {},
lspstatus.capabilities lspstatus.capabilities
) )
local final_config = coq.lsp_ensure_capabilities(conf) local final_config = coq.lsp_ensure_capabilities(conf)
local special_setup = lsp_special_setup[server] local special_setup = lsp_special_setup[server]
if special_setup then if special_setup then
special_setup(final_config) special_setup(final_config)
else else
lspconfig[server].setup(final_config) lspconfig[server].setup(final_config)
end end
end end
local null_ls = require('null-ls') local null_ls = require('null-ls')
null_ls.setup({ null_ls.setup({
sources = { sources = {
null_ls.builtins.diagnostics.chktex, null_ls.builtins.diagnostics.chktex,
null_ls.builtins.diagnostics.cppcheck, null_ls.builtins.diagnostics.cppcheck,
null_ls.builtins.diagnostics.shellcheck, null_ls.builtins.diagnostics.shellcheck,
null_ls.builtins.code_actions.gitsigns, null_ls.builtins.code_actions.gitsigns,
}, },
}) })
vim.diagnostic.config({ vim.diagnostic.config({
severity_sort = true, severity_sort = true,
update_in_insert = true, update_in_insert = true,
float = { float = {
source = true, source = true,
}, },
}) })
do -- signs do -- signs
local signs = { local signs = {
{'DiagnosticSignError', text='×', texthl='DiagnosticSignError'}, { 'DiagnosticSignError', text = '×', texthl = 'DiagnosticSignError' },
{'DiagnosticSignWarn', text='>', texthl='DiagnosticSignWarn'}, { 'DiagnosticSignWarn', text = '>', texthl = 'DiagnosticSignWarn' },
{'DiagnosticSignInfo', text='I', texthl='DiagnosticSignInfo'}, { 'DiagnosticSignInfo', text = 'I', texthl = 'DiagnosticSignInfo' },
{'DiagnosticSignHint', text='H', texthl='DiagnosticSignHint'}, { 'DiagnosticSignHint', text = 'H', texthl = 'DiagnosticSignHint' },
} }
for _, sign in pairs(signs) do for _, sign in pairs(signs) do
local name = sign[1] local name = sign[1]
local opts = sign local opts = sign
opts[1] = nil opts[1] = nil
vim.fn.sign_define(name, opts) vim.fn.sign_define(name, opts)
end end
end end
local map = vim.api.nvim_set_keymap local map = vim.api.nvim_set_keymap
map( map(
'n', 'n',
'K', 'K',
[[luaeval('next(vim.lsp.buf_get_clients()) == nil') ? 'K' : '<Cmd>lua vim.lsp.buf.hover()<CR>']], [[luaeval('next(vim.lsp.buf_get_clients()) == nil') ? 'K' : '<Cmd>lua vim.lsp.buf.hover()<CR>']],
{noremap = true, expr = true} { noremap = true, expr = true }
) )
map( map(
'n', 'n',
'<C-]>', '<C-]>',
[[luaeval('next(vim.lsp.buf_get_clients()) == nil') ? '<C-]>' : '<Cmd>lua vim.lsp.buf.definition()<CR>']], [[luaeval('next(vim.lsp.buf_get_clients()) == nil') ? '<C-]>' : '<Cmd>lua vim.lsp.buf.definition()<CR>']],
{noremap = true, expr = true} { noremap = true, expr = true }
) )
local M = {}
M.format_on_save_hook = function()
local enabled = vim.b.format_on_save
if enabled == nil then
enabled = true
end
if enabled ~= 0 and enabled ~= false then
vim.lsp.buf.format({ async = false })
end
end
vim.cmd [[ vim.cmd [[
augroup lspconfig augroup hoverlspconfig
au! au!
" diagnostic on hover " diagnostic on hover
au BufWritePre * lua require'lsp'.format_on_save_hook()
au CursorHold * lua vim.diagnostic.open_float({focus = false}) au CursorHold * lua vim.diagnostic.open_float({focus = false})
augroup END augroup END
]] ]]
vim.api.nvim_create_autocmd('FileType', {
pattern = "*",
callback = function()
if vim.bo.filetype ~= "plaintex" and vim.bo.filetype ~= "tex" and vim.bo.filetype ~= "latex" then
vim.cmd [[ :COQnow -s ]]
end
end
})
-- vim.cmd [[
-- augroup disabletexlsp
-- autocmd!
-- autocmd FileType tex :COQstop
-- augroup END
-- ]]
return M

View File

@ -18,32 +18,32 @@ o.termguicolors = true
vim.cmd('colorscheme theme') vim.cmd('colorscheme theme')
vim.g.airline_theme='theme' vim.g.airline_theme = 'theme'
map('n', '<Leader>s', ':%s//g<Left><Left>', {}) map('n', '<Leader>s', ':%s//g<Left><Left>', {})
map('n', '<Leader>e', ':make!<CR>', {noremap = true}) map('n', '<Leader>e', ':make!<CR>', { noremap = true })
map('n', '<C-o>', ':cclose<CR>', {noremap = true}) map('n', '<C-o>', ':cclose<CR>', { noremap = true })
map('n', '<C-L>', ':nohlsearch<CR><C-L>', {noremap = true, silent = true}) map('n', '<C-L>', ':nohlsearch<CR><C-L>', { noremap = true, silent = true })
map('n', ';', ':', {noremap = true}) map('n', ';', ':', { noremap = true })
map('v', ';', ':', {noremap = true}) map('v', ';', ':', { noremap = true })
for i = 1,9,1 do for i = 1, 9, 1 do
map('', '<Leader>' .. tostring(i), tostring(i) .. 'gt', {noremap = true}) map('', '<Leader>' .. tostring(i), tostring(i) .. 'gt', { noremap = true })
end end
map('n', '<C-Left>', ':tabprevious<CR>', {noremap = true}) map('n', '<C-Left>', ':tabprevious<CR>', { noremap = true })
map('n', '<C-Right>', ':tabnext<CR>', {noremap = true}) map('n', '<C-Right>', ':tabnext<CR>', { noremap = true })
map('', '<Leader>0', ':tablast<CR>', {noremap = true}) map('', '<Leader>0', ':tablast<CR>', { noremap = true })
map('n', 'ZX', '<Cmd>q<CR>', {noremap = true, silent = true}) map('n', 'ZX', '<Cmd>q<CR>', { noremap = true, silent = true })
map('t', '<Esc>', '<C-\\><C-n>', {noremap = true}) map('t', '<Esc>', '<C-\\><C-n>', { noremap = true })
o.list=true o.list = true
o.listchars = { o.listchars = {
tab = '', tab = '',
eol = '¬', eol = '¬',
trail = '·', trail = '·',
extends = '' extends = ''
} }
vim.cmd [[ vim.cmd [[

View File

@ -1,69 +1,73 @@
local bootstrap = require('bootstrap') local bootstrap = require('bootstrap')
local function import(name) local function import(name)
return ([[require '%s']]):format(name) return ([[require '%s']]):format(name)
end end
return require('packer').startup({function(use) return require('packer').startup({ function(use)
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
use { use {
'vim-airline/vim-airline', 'vim-airline/vim-airline',
requires = { requires = {
'ryanoasis/vim-devicons', 'ryanoasis/vim-devicons',
} }
}
use {
'mustache/vim-mustache-handlebars'
} }
use { use {
'nvim-treesitter/nvim-treesitter', 'mustache/vim-mustache-handlebars'
run = ':TSUpdate'
} }
use { use {
'petRUShka/vim-sage' 'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
} }
use { use {
'evanleck/vim-svelte' 'petRUShka/vim-sage'
} }
use { use {
'tpope/vim-fugitive', 'evanleck/vim-svelte'
config = function() }
local map = vim.api.nvim_set_keymap
map('n', '<Leader>g', '<Cmd>Git<CR>', {noremap = true})
end,
}
use { use {
'tpope/vim-surround', 'tpope/vim-fugitive',
} config = function()
local map = vim.api.nvim_set_keymap
map('n', '<Leader>g', '<Cmd>Git<CR>', { noremap = true })
end,
}
use { use {
'tpope/vim-repeat', 'tpope/vim-surround',
} }
use { use {
'lewis6991/gitsigns.nvim', 'tpope/vim-repeat',
requires = { }
'nvim-lua/plenary.nvim'
}, use {
config = function() 'lewis6991/gitsigns.nvim',
require('gitsigns').setup { requires = {
signs = { 'nvim-lua/plenary.nvim'
add = {hl = 'GitSignsAdd' , text = '', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'}, },
change = {hl = 'GitSignsChange', text = '', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, config = function()
delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, require('gitsigns').setup {
topdelete = {hl = 'GitSignsDelete', text = '', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'}, signs = {
changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'}, add = { hl = 'GitSignsAdd', text = '', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' },
}, change = { hl = 'GitSignsChange', text = '', numhl = 'GitSignsChangeNr',
} linehl = 'GitSignsChangeLn' },
end delete = { hl = 'GitSignsDelete', text = '_', numhl = 'GitSignsDeleteNr',
} linehl = 'GitSignsDeleteLn' },
topdelete = { hl = 'GitSignsDelete', text = '', numhl = 'GitSignsDeleteNr',
linehl = 'GitSignsDeleteLn' },
changedelete = { hl = 'GitSignsChange', text = '~', numhl = 'GitSignsChangeNr',
linehl = 'GitSignsChangeLn' },
},
}
end
}
use { use {
'akinsho/flutter-tools.nvim', 'akinsho/flutter-tools.nvim',
@ -71,7 +75,7 @@ return require('packer').startup({function(use)
'nvim-lua/plenary.nvim' 'nvim-lua/plenary.nvim'
}, },
config = function() config = function()
require('flutter-tools').setup{ require('flutter-tools').setup {
lsp = { lsp = {
color = { color = {
enabled = false enabled = false
@ -81,106 +85,117 @@ return require('packer').startup({function(use)
end end
} }
use { use {
'numToStr/Comment.nvim', 'numToStr/Comment.nvim',
config = function() config = function()
local map = vim.api.nvim_set_keymap local map = vim.api.nvim_set_keymap
require('Comment').setup({}) require('Comment').setup({})
map('n', '<C-_>', map('n', '<C-_>',
'<Cmd>lua require("Comment.api").toggle_linewise_op(vim.fn.visualmode())<CR>', '<Cmd>lua require("Comment.api").toggle_linewise_op(vim.fn.visualmode())<CR>',
{noremap = true, silent = true}) { noremap = true, silent = true })
end end
}
use {
'nvim-telescope/telescope.nvim',
requires = {
'nvim-lua/plenary.nvim',
{
'nvim-telescope/telescope-fzf-native.nvim',
run = 'make',
},
'nvim-telescope/telescope-symbols.nvim',
},
config = import('tel'),
}
use {
'stevearc/dressing.nvim',
config = function()
require('dressing').setup({
input = {
default_prompt = '',
winhighlight = 'NormalFloat:Normal',
},
})
vim.cmd [[highlight link FloatTitle NonText]]
vim.cmd [[highlight link DressingInputText Normal]]
end,
}
use {
'antoinemadec/FixCursorHold.nvim',
config = function()
vim.g.cursorhold_updatetime = 500
end,
}
use {
'neovim/nvim-lspconfig',
-- commit = "607ff48b970b89c3e4e3825b88d9cfd05b7aaea5",
requires = {
'nvim-lua/lsp-status.nvim',
'ms-jpq/coq.thirdparty',
{
'ms-jpq/coq_nvim',
run = ':COQdeps',
requires = {
'ms-jpq/coq.artifacts',
},
},
{
'jose-elias-alvarez/null-ls.nvim',
requires = {
'nvim-lua/plenary.nvim',
},
},
},
config = import('lsp'),
}
use {
'lervag/vimtex',
config = function()
vim.g.vimtex_view_general_viewer = 'zathura'
-- vim.g.vimtex_view_general_options = = '-x nvim -n -c "Vimtex'
-- 'file:@pdf\\#src:@line@tex'
-- vim.g.vimtex_quickfix_enabled = 0
-- vim.g.Tex_GotoError = 0
-- vim.g.Tex_ShowErrorContext = 0
end,
}
use {
'iamcco/markdown-preview.nvim',
commit = "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96",
run = "cd app && npm install",
setup = function() vim.g.mkdp_filetypes = { "markdown" } end, ft = { "markdown" },
config = function()
local map = vim.api.nvim_set_keymap
map('n', '<C-m>', '<Plug>MarkdownPreviewToggle', {})
map('n', '<Leader>m', '<Plug>MarkdownPreviewToggle', {})
vim.g.mkdp_markdown_css = os.getenv("HOME") .. "/.config/nvim/lua/markdownStyle.css"
vim.g.mkdp_highlight_css = os.getenv("HOME") .. "/.cache/wal/colors.css"
end
} }
if bootstrap.is_bootstrap then use {
require('packer').sync() 'nvim-telescope/telescope.nvim',
end requires = {
'nvim-lua/plenary.nvim',
{
'nvim-telescope/telescope-fzf-native.nvim',
run = 'make',
},
'nvim-telescope/telescope-symbols.nvim',
},
config = import('tel'),
}
use {
'stevearc/dressing.nvim',
config = function()
require('dressing').setup({
input = {
default_prompt = '',
winhighlight = 'NormalFloat:Normal',
},
})
vim.cmd [[highlight link FloatTitle NonText]]
vim.cmd [[highlight link DressingInputText Normal]]
end,
}
use {
'antoinemadec/FixCursorHold.nvim',
config = function()
vim.g.cursorhold_updatetime = 500
end,
}
use {
'sirver/ultisnips',
ft = { 'latex', 'plaintex', 'tex' },
config = function()
vim.g.UltiSnipsExpandTrigger = '<tab>'
vim.g.UltiSnipsJumpForwardTrigger = '<tab>'
vim.g.UltiSnipsJumpBackwardTrigger = '<s-tab>'
end
}
use {
'neovim/nvim-lspconfig',
-- commit = "607ff48b970b89c3e4e3825b88d9cfd05b7aaea5",
requires = {
'nvim-lua/lsp-status.nvim',
{
'ms-jpq/coq.thirdparty',
},
{
'ms-jpq/coq_nvim',
run = ':COQdeps',
requires = {
'ms-jpq/coq.artifacts',
},
},
{
'jose-elias-alvarez/null-ls.nvim',
requires = {
'nvim-lua/plenary.nvim',
},
},
},
config = import('lsp'),
}
use {
'lervag/vimtex',
config = function()
vim.g.vimtex_view_general_viewer = 'zathura'
-- vim.g.vimtex_view_general_options = = '-x nvim -n -c "Vimtex'
-- 'file:@pdf\\#src:@line@tex'
-- vim.g.vimtex_quickfix_enabled = 0
-- vim.g.Tex_GotoError = 0
-- vim.g.Tex_ShowErrorContext = 0
end,
}
use {
'iamcco/markdown-preview.nvim',
commit = "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96",
run = "cd app && npm install",
setup = function() vim.g.mkdp_filetypes = { "markdown" } end, ft = { "markdown" },
config = function()
local map = vim.api.nvim_set_keymap
map('n', '<C-m>', '<Plug>MarkdownPreviewToggle', {})
map('n', '<Leader>m', '<Plug>MarkdownPreviewToggle', {})
vim.g.mkdp_markdown_css = os.getenv("HOME") .. "/.config/nvim/lua/markdownStyle.css"
vim.g.mkdp_highlight_css = os.getenv("HOME") .. "/.cache/wal/colors.css"
end
}
if bootstrap.is_bootstrap then
require('packer').sync()
end
end, end,
config = { config = {
compile_path = require('packer.util').join_paths(vim.fn.stdpath('data'), 'site', 'plugin', 'packer_compiled.lua'), compile_path = require('packer.util').join_paths(vim.fn.stdpath('data'), 'site', 'plugin', 'packer_compiled.lua'),
}}) } })

View File

@ -1,198 +1,200 @@
local telescope = require('telescope') local telescope = require('telescope')
telescope.setup({ telescope.setup({
defaults = { defaults = {
file_ignore_patterns = {'.git'}, file_ignore_patterns = { '.git' },
mappings = { mappings = {
i = { i = {
['<C-o>'] = { '<Esc>', type = 'command' }, ['<C-o>'] = { '<Esc>', type = 'command' },
['<Esc>'] = 'close', ['<Esc>'] = 'close',
['<C-s>'] = 'select_horizontal', ['<C-s>'] = 'select_horizontal',
}, },
n = { n = {
q = 'close', q = 'close',
['<C-o>'] = { '<Nop>', type = 'command' }, ['<C-o>'] = { '<Nop>', type = 'command' },
['<C-s>'] = 'select_horizontal', ['<C-s>'] = 'select_horizontal',
}, },
}, },
sorting_strategy = 'ascending', sorting_strategy = 'ascending',
layout_config = { layout_config = {
prompt_position = 'top', prompt_position = 'top',
}, },
prompt_prefix = ' ', prompt_prefix = ' ',
selection_caret = ' ', selection_caret = ' ',
multi_icon = '', multi_icon = '',
}, },
pickers = { pickers = {
buffers = { buffers = {
mappings = { mappings = {
n = { n = {
dd = 'delete_buffer', dd = 'delete_buffer',
}, },
}, },
}, },
find_files = { find_files = {
hidden = true, hidden = true,
}, },
lsp_code_actions = { lsp_code_actions = {
initial_mode = 'normal', initial_mode = 'normal',
}, },
lsp_range_code_actions = { lsp_range_code_actions = {
initial_mode = 'normal', initial_mode = 'normal',
}, },
}, },
}) })
telescope.load_extension('fzf') telescope.load_extension('fzf')
-- taken from https://github.com/nvim-telescope/telescope-ui-select.nvim for code actions -- taken from https://github.com/nvim-telescope/telescope-ui-select.nvim for code actions
telescope.register_extension { telescope.register_extension {
setup = function(topts) setup = function(topts)
local specific_opts = vim.F.if_nil(topts.specific_opts, {}) local specific_opts = vim.F.if_nil(topts.specific_opts, {})
topts.specific_opts = nil topts.specific_opts = nil
if #topts == 1 and topts[1] ~= nil then if #topts == 1 and topts[1] ~= nil then
topts = topts[1] topts = topts[1]
end end
local pickers = require "telescope.pickers" local pickers = require "telescope.pickers"
local finders = require "telescope.finders" local finders = require "telescope.finders"
local conf = require("telescope.config").values local conf = require("telescope.config").values
local actions = require "telescope.actions" local actions = require "telescope.actions"
local action_state = require "telescope.actions.state" local action_state = require "telescope.actions.state"
local strings = require "plenary.strings" local strings = require "plenary.strings"
local entry_display = require "telescope.pickers.entry_display" local entry_display = require "telescope.pickers.entry_display"
local utils = require "telescope.utils" local utils = require "telescope.utils"
__TelescopeUISelectSpecificOpts = vim.F.if_nil( __TelescopeUISelectSpecificOpts = vim.F.if_nil(
__TelescopeUISelectSpecificOpts, __TelescopeUISelectSpecificOpts,
vim.tbl_extend("keep", specific_opts, { vim.tbl_extend("keep", specific_opts, {
["codeaction"] = { ["codeaction"] = {
make_indexed = function(items) make_indexed = function(items)
local indexed_items = {} local indexed_items = {}
local widths = { local widths = {
idx = 0, idx = 0,
command_title = 0, command_title = 0,
client_name = 0, client_name = 0,
} }
for idx, item in ipairs(items) do for idx, item in ipairs(items) do
local client = vim.lsp.get_client_by_id(item[1]) local client = vim.lsp.get_client_by_id(item[1])
local entry = { local entry = {
idx = idx, idx = idx,
["add"] = { ["add"] = {
command_title = item[2].title:gsub("\r\n", "\\r\\n"):gsub("\n", "\\n"), command_title = item[2].title:gsub("\r\n", "\\r\\n"):gsub("\n", "\\n"),
client_name = client and client.name or "", client_name = client and client.name or "",
}, },
text = item, text = item,
} }
table.insert(indexed_items, entry) table.insert(indexed_items, entry)
widths.idx = math.max(widths.idx, strings.strdisplaywidth(entry.idx)) widths.idx = math.max(widths.idx, strings.strdisplaywidth(entry.idx))
widths.command_title = math.max(widths.command_title, strings.strdisplaywidth(entry.add.command_title)) widths.command_title = math.max(widths.command_title,
widths.client_name = math.max(widths.client_name, strings.strdisplaywidth(entry.add.client_name)) strings.strdisplaywidth(entry.add.command_title))
end widths.client_name = math.max(widths.client_name,
return indexed_items, widths strings.strdisplaywidth(entry.add.client_name))
end, end
make_displayer = function(widths) return indexed_items, widths
return entry_display.create { end,
separator = " ", make_displayer = function(widths)
items = { return entry_display.create {
{ width = widths.idx + 1 }, -- +1 for ":" suffix separator = " ",
{ width = widths.command_title }, items = {
{ width = widths.client_name }, { width = widths.idx + 1 }, -- +1 for ":" suffix
}, { width = widths.command_title },
} { width = widths.client_name },
end, },
make_display = function(displayer) }
return function(e) end,
return displayer { make_display = function(displayer)
{ e.value.idx .. ":", "TelescopePromptPrefix" }, return function(e)
{ e.value.add.command_title }, return displayer {
{ e.value.add.client_name, "TelescopeResultsComment" }, { e.value.idx .. ":", "TelescopePromptPrefix" },
} { e.value.add.command_title },
end { e.value.add.client_name, "TelescopeResultsComment" },
end, }
make_ordinal = function(e) end
return e.idx .. e.add["command_title"] end,
end, make_ordinal = function(e)
}, return e.idx .. e.add["command_title"]
}) end,
) },
})
)
vim.ui.select = function(items, opts, on_choice) vim.ui.select = function(items, opts, on_choice)
opts = opts or {} opts = opts or {}
local prompt = vim.F.if_nil(opts.prompt, "Select one of") local prompt = vim.F.if_nil(opts.prompt, "Select one of")
if prompt:sub(-1, -1) == ":" then if prompt:sub(-1, -1) == ":" then
prompt = prompt:sub(1, -2) prompt = prompt:sub(1, -2)
end end
opts.format_item = vim.F.if_nil(opts.format_item, function(e) opts.format_item = vim.F.if_nil(opts.format_item, function(e)
return tostring(e) return tostring(e)
end) end)
-- We want or here because __TelescopeUISelectSpecificOpts[x] can be either nil or even false -> {} -- We want or here because __TelescopeUISelectSpecificOpts[x] can be either nil or even false -> {}
local sopts = __TelescopeUISelectSpecificOpts[vim.F.if_nil(opts.kind, "")] or {} local sopts = __TelescopeUISelectSpecificOpts[vim.F.if_nil(opts.kind, "")] or {}
local indexed_items, widths = vim.F.if_nil(sopts.make_indexed, function(items_) local indexed_items, widths = vim.F.if_nil(sopts.make_indexed, function(items_)
local indexed_items = {} local indexed_items = {}
for idx, item in ipairs(items_) do for idx, item in ipairs(items_) do
table.insert(indexed_items, { idx = idx, text = item }) table.insert(indexed_items, { idx = idx, text = item })
end end
return indexed_items return indexed_items
end)(items) end)(items)
local displayer = vim.F.if_nil(sopts.make_displayer, function() end)(widths) local displayer = vim.F.if_nil(sopts.make_displayer, function() end)(widths)
local make_display = vim.F.if_nil(sopts.make_display, function(_) local make_display = vim.F.if_nil(sopts.make_display, function(_)
return function(e) return function(e)
local x, _ = opts.format_item(e.value.text) local x, _ = opts.format_item(e.value.text)
return x return x
end end
end)(displayer) end)(displayer)
local make_ordinal = vim.F.if_nil(sopts.make_ordinal, function(e) local make_ordinal = vim.F.if_nil(sopts.make_ordinal, function(e)
return opts.format_item(e.text) return opts.format_item(e.text)
end) end)
pickers.new(topts, { pickers.new(topts, {
prompt_title = prompt, prompt_title = prompt,
finder = finders.new_table { finder = finders.new_table {
results = indexed_items, results = indexed_items,
entry_maker = function(e) entry_maker = function(e)
return { return {
value = e, value = e,
display = make_display, display = make_display,
ordinal = make_ordinal(e), ordinal = make_ordinal(e),
} }
end, end,
}, },
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function() actions.select_default:replace(function()
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
if selection == nil then if selection == nil then
utils.__warn_no_selection "ui-select" utils.__warn_no_selection "ui-select"
return return
end end
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
on_choice(selection.value.text, selection.value.idx) on_choice(selection.value.text, selection.value.idx)
end) end)
return true return true
end, end,
sorter = conf.generic_sorter(topts), sorter = conf.generic_sorter(topts),
}):find() }):find()
end end
end, end,
} }
local map = vim.api.nvim_set_keymap local map = vim.api.nvim_set_keymap
map('n', '<Leader>pf', '<Cmd>Telescope find_files<CR>', {noremap = true}) map('n', '<Leader>pf', '<Cmd>Telescope find_files<CR>', { noremap = true })
map('n', '<Leader>pb', '<Cmd>Telescope buffers<CR>', {noremap = true}) map('n', '<Leader>pb', '<Cmd>Telescope buffers<CR>', { noremap = true })
map('n', '<Leader>po', '<Cmd>Telescope lsp_document_symbols<CR>', {noremap = true}) map('n', '<Leader>po', '<Cmd>Telescope lsp_document_symbols<CR>', { noremap = true })
map('n', '<Leader>ps', '<Cmd>Telescope lsp_workspace_symbols<CR>', {noremap = true}) map('n', '<Leader>ps', '<Cmd>Telescope lsp_workspace_symbols<CR>', { noremap = true })
map('n', '<Leader>pd', '<Cmd>Telescope lsp_definitions<CR>', {noremap = true}) map('n', '<Leader>pd', '<Cmd>Telescope lsp_definitions<CR>', { noremap = true })
map('n', '<Leader>pr', '<Cmd>Telescope lsp_references<CR>', {noremap = true}) map('n', '<Leader>pr', '<Cmd>Telescope lsp_references<CR>', { noremap = true })
map('n', '<Leader>p', ':Telescope ', {noremap = true}) map('n', '<Leader>pp', '<C-^>', { noremap = true })
map('n', '<Leader>p ', ':Telescope ', {noremap = true}) map('n', '<Leader>p', ':Telescope ', { noremap = true })
map('n', '<Leader>p ', ':Telescope ', { noremap = true })
map('n', '<Leader>.', ':lua vim.lsp.buf.code_action()<CR>', {noremap = true}) map('n', '<Leader>.', ':lua vim.lsp.buf.code_action()<CR>', { noremap = true })
-- vim.cmd [[ -- vim.cmd [[
-- function! s:telescope_hlsetup() abort -- function! s:telescope_hlsetup() abort
@ -205,4 +207,3 @@ map('n', '<Leader>.', ':lua vim.lsp.buf.code_action()<CR>', {noremap = true})
-- au ColorScheme * call s:telescope_hlsetup() -- au ColorScheme * call s:telescope_hlsetup()
-- augroup END -- augroup END
-- ]] -- ]]