convert fully to LSP for all the things

This commit is contained in:
2022-01-20 13:16:41 +01:00
parent 31c617f1e4
commit 5dd8ae6223
18 changed files with 190 additions and 481 deletions

View File

@@ -1,4 +1,13 @@
local cmp = require'cmp'
local lspkind = require('lspkind')
local source_mapping = {
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
cmp_tabnine = "[TN]",
path = "[Path]",
}
cmp.setup({
-- snippet = {
@@ -14,22 +23,29 @@ cmp.setup({
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
{ name = 'cmp_tabnine' },
{ name = 'nvim_lsp' },
},
{
{ name = 'buffer' },
}),
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
local menu = source_mapping[entry.source.name]
if entry.source.name == 'cmp_tabnine' then
if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then
menu = entry.completion_item.data.detail .. ' ' .. menu
end
vim_item.kind = '?'
end
vim_item.menu = menu
return vim_item
end
}
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
@@ -48,6 +64,20 @@ cmp.setup.cmdline(':', {
})
})
-- Setup tabnine
local tabnine = require('cmp_tabnine.config')
tabnine:setup({
max_lines = 1000;
max_num_results = 20;
sort = true;
run_on_every_keystroke = true;
snippet_placeholder = '..';
ignored_file_types = { -- default is not to ignore
-- uncomment to ignore in lua:
-- lua = true
};
})
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

View File

@@ -1,70 +0,0 @@
vim.o.completeopt = "menuone,noselect"
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = true;
source = {
path = true;
buffer = true;
calc = true;
vsnip = false;
nvim_lsp = true;
nvim_lua = true;
spell = true;
tags = true;
snippets_nvim = true;
treesitter = true;
};
}
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
--elseif vim.fn.call("vsnip#available", {1}) == 1 then
--return t "<Plug>(vsnip-expand-or-jump)"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
--elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
--return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {noremap = true, expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {noremap = true, expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {noremap = true, expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {noremap = true, expr = true})

View File

@@ -19,7 +19,7 @@ require('telescope').setup {
file_ignore_patterns = {},
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
shorten_path = true,
winblend = 0,
winblend = 0,
width = 0.75,
preview_cutoff = 120,
results_height = 1,

View File

@@ -1,130 +0,0 @@
require("which-key").setup {
plugins = {
marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
-- No actual key bindings are created
presets = {
operators = true, -- adds help for operators like d, y, ...
motions = true, -- adds help for motions
text_objects = true, -- help for text objects triggered after entering an operator
windows = true, -- default bindings on <c-w>
nav = true, -- misc bindings to work with windows
z = true, -- bindings for folds, spelling and others prefixed with z
g = true -- bindings for prefixed with g
}
},
icons = {
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
separator = "", -- symbol used between a key and it's label
group = "+" -- symbol prepended to a group
},
window = {
border = "single", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = {1, 0, 1, 0}, -- extra window margin [top, right, bottom, left]
padding = {2, 2, 2, 2} -- extra window padding [top, right, bottom, left]
},
layout = {
height = {min = 4, max = 25}, -- min and max height of the columns
width = {min = 20, max = 50}, -- min and max width of the columns
spacing = 3 -- spacing between columns
},
hidden = {"<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
show_help = true -- show help message on the command line when the popup is visible
}
local opts = {
mode = "n", -- NORMAL mode
prefix = "<leader>",
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
silent = true, -- use `silent` when creating keymaps
noremap = true, -- use `noremap` when creating keymaps
nowait = false -- use `nowait` when creating keymaps
}
-- Set leader
vim.api.nvim_set_keymap('n', '<Space>', '<NOP>', {noremap = true, silent = true})
vim.g.mapleader = ' '
-- explorer
vim.api.nvim_set_keymap('n', '<Leader>e', ':NERDTreeToggle<CR>', {noremap = true, silent = true})
-- TODO create entire treesitter section
local mappings = {
["e"] = "Explorer",
["c"] = "NERDCommenter",
b = {
name = "+Buffers",
b = {"<C-^>", "Toggle Buffer"},
d = {"<cmd>bd<cr>", "Close Buffer"},
k = {"<cmd>bd!<cr>", "Kill Buffer"},
},
f = {
name = "Find",
f = {"<cmd>Telescope find_files<cr>", "Find File"},
p = {"<cmd>lua require'telescope'.extensions.project.project{}<CR>", "Project"},
g = {"<cmd>lua require'telescope.builtin'.live_grep()<cr>", "Grep files"},
b = {"<cmd>lua require'telescope.builtin'.buffers{}<cr>", "Buffers"},
t = {"<cmd>lua require'telescope.builtin'.help_tags{}<cr>", "Tags"},
},
g = {
name = "+Git",
j = {"<cmd>GitGutterNextHunk<cr>", "Next Hunk"},
k = {"<cmd>GitGutterPrevHunk<cr>", "Prev Hunk"},
p = {"<cmd>GitGutterPreviewHunk<cr>", "Preview Hunk"},
r = {"<cmd>GitGutterResetHunk<cr>", "Reset Hunk"},
s = {"<cmd>GitGutterStageHunk<cr>", "Stage Hunk"},
u = {"<cmd>GitGutterUndoHunk<cr>", "Undo Stage Hunk"},
o = {"<cmd>Telescope git_status<cr>", "Open changed file"},
b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
c = {"<cmd>Telescope git_commits<cr>", "Checkout commit"},
C = {"<cmd>Telescope git_bcommits<cr>", "Checkout commit(for current file)"},
},
l = {
name = "+LSP",
a = {"<cmd>Lspsaga code_action<cr>", "Code Action"},
A = {"<cmd>Lspsaga range_code_action<cr>", "Selected Action"},
d = {"<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics"},
D = {"<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics"},
i = {"<cmd>LspInfo<cr>", "Info"},
l = {"<cmd>Lspsaga lsp_finder<cr>", "LSP Finder"},
L = {"<cmd>Lspsaga show_line_diagnostics<cr>", "Line Diagnostics"},
p = {"<cmd>Lspsaga preview_definition<cr>", "Preview Definition"},
q = {"<cmd>Telescope quickfix<cr>", "Quickfix"},
r = {"<cmd>Lspsaga rename<cr>", "Rename"},
t = {"<cmd>LspTypeDefinition<cr>", "Type Definition"},
x = {"<cmd>cclose<cr>", "Close Quickfix"},
s = {"<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols"},
S = {"<cmd>Telescope lsp_workspace_symbols<cr>", "Workspace Symbols"}
},
d = {
f = {":lua require'functions'.edit_dotfiles()<cr>", "Dotfiles search"}
},
s = {
name = "+Search",
b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
c = {"<cmd>Telescope colorscheme<cr>", "Colorscheme"},
d = {"<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics"},
D = {"<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics"},
f = {"<cmd>Telescope find_files<cr>", "Find File"},
m = {"<cmd>Telescope marks<cr>", "Marks"},
M = {"<cmd>Telescope man_pages<cr>", "Man Pages"},
r = {"<cmd>Telescope oldfiles<cr>", "Open Recent File"},
R = {"<cmd>Telescope registers<cr>", "Registers"},
t = {"<cmd>Telescope live_grep<cr>", "Text"}
},
S = {
name = "+Session",
s = {"<cmd>SessionSave<cr>", "Save Session"},
l = {"<cmd>SessionLoad<cr>", "Load Session"}
},
t = {
name = "+Tagbar",
t = {"<cmd>TagbarToggle<cr>", "Toggle Tagbar"},
}
}
local wk = require("which-key")
wk.register(mappings, opts)