refactor: Don't bind keys in global buffer

Bind only when LSP is loaded in buffer.
Remove unneeded plugins.
general cleanup
This commit is contained in:
Patrick Michl 2021-09-06 09:56:36 +02:00
parent 0bc8580653
commit ad50027cd3
5 changed files with 71 additions and 90 deletions

View File

@ -7,16 +7,5 @@ vim.cmd([[autocmd BufNewFile,BufRead *.md setlocal filetype=notes]])
key('n', ';', ':Files<CR>', {}) key('n', ';', ':Files<CR>', {})
key('', '<C-n>', ':NERDTreeToggle<CR>', {}) key('', '<C-n>', ':NERDTreeToggle<CR>', {})
-- LSP Key Config key('i', '<TAB>', 'pumvisible() ? "<C-n>" : "<Tab>"', {expr = true, silent = true})
local silent_opts = {silent = true} key('i', '<S-TAB>', 'pumvisible() ? "<C-p>" : "<S-Tab>"', {expr = true, silent = true})
key('n', '<c-]>', ':lua vim.lsp.buf.definition()<CR>', silent_opts)
key('n', 'K', ':lua vim.lsp.buf.hover()<CR>', silent_opts)
key('n', 'gD', ':lua vim.lsp.buf.implementation()<CR>', silent_opts)
key('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>', silent_opts)
key('n', '1gD', ':lua vim.lsp.buf.type_definition()<CR>', silent_opts)
key('n', 'gr', ':lua vim.lsp.buf.references()<CR>', silent_opts)
key('n', 'g0', ':lua vim.lsp.buf.document_symbol()<CR>', silent_opts)
key('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()<CR>', silent_opts)
key('n', 'gd', ':lua vim.lsp.buf.definition()<CR>', silent_opts)
key('n', 'ga', ':lua vim.lsp.buf.code_action()<CR>', silent_opts)
key('n', 'ff', ':lua vim.lsp.buf.formatting()<CR>', silent_opts)

View File

@ -1,69 +1,58 @@
require'lspinstall'.setup()
local u = require('utils')
local nvim_lsp = require'lspconfig' local nvim_lsp = require'lspconfig'
local function setup_servers() local on_attach = function(client, bufnr)
require'lspinstall'.setup() local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local servers = require'lspinstall'.installed_servers() local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
for _, lsp in pairs(servers) do
nvim_lsp[lsp].setup{} buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
local opts = { noremap=true, silent=true }
buf_set_keymap('n', '<c-]>', ':lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gD', ':lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '1gD', ':lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', 'gr', ':lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', 'g0', ':lua vim.lsp.buf.document_symbol()<CR>', opts)
buf_set_keymap('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()<CR>', opts)
buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'ga', ':lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'ff', ':lua vim.lsp.buf.formatting()<CR>', opts)
require'completion'.on_attach(client)
-- Set highlight colors
local highlights = {
Error = "Red",
Warning = "Yellow",
Information = "Blue",
Hint = "Green",
}
for typ, color in pairs(highlights) do
u.hi('LspDiagnosticsDefault'..typ, {ctermfg = color})
u.hi('LspDiagnosticsUnderline'..typ, {cterm = 'underline'})
end end
vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics,
{
virtual_text = true,
signs = true,
update_in_insert = true,
underline = true
}
)
end end
local opts = { local servers = require'lspinstall'.installed_servers()
tools = { for _, lsp in ipairs(servers) do
autoSetHints = true, nvim_lsp[lsp].setup{
hover_with_actions = true, on_attach = on_attach,
runnables = { flags = {debounce_text_changes = 150}
use_telescope = true }
},
inlay_hints = {
show_parameter_hints = false,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
server = {}, -- rust-analyer options
}
require('rust-tools').setup(opts)
setup_servers()
require'lspinstall'.post_install_hook = function ()
setup_servers()
vim.cmd("bufdo e")
end end
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
},
})

View File

@ -1,6 +1,8 @@
local vim = vim -- Workaround to get rid of warnings
vim.cmd([[autocmd BufWritePost plugins.lua source <afile> | PackerCompile]]) vim.cmd([[autocmd BufWritePost plugins.lua source <afile> | PackerCompile]])
return require('packer').startup({function() return require('packer').startup({function()
local use = use
-- Packer can manage itself -- Packer can manage itself
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
@ -8,7 +10,6 @@ return require('packer').startup({function()
use 'scrooloose/nerdtree' use 'scrooloose/nerdtree'
use 'Xuyuanp/nerdtree-git-plugin' use 'Xuyuanp/nerdtree-git-plugin'
use 'liuchengxu/space-vim-dark' use 'liuchengxu/space-vim-dark'
use 'tpope/vim-fugitive' use 'tpope/vim-fugitive'
use 'tpope/vim-commentary' use 'tpope/vim-commentary'
use { 'tpope/vim-dispatch', opt = true, cmd = { 'Dispatch', 'Dispatch!' } } use { 'tpope/vim-dispatch', opt = true, cmd = { 'Dispatch', 'Dispatch!' } }
@ -19,8 +20,6 @@ return require('packer').startup({function()
use 'rodjek/vim-puppet' use 'rodjek/vim-puppet'
use 'tpope/vim-rails' use 'tpope/vim-rails'
use 'tpope/vim-haml' use 'tpope/vim-haml'
use 'vim-scripts/bash-support.vim'
use "akinsho/nvim-toggleterm.lua"
use 'xolox/vim-notes' use 'xolox/vim-notes'
use 'xolox/vim-misc' use 'xolox/vim-misc'
use 'jremmen/vim-ripgrep' use 'jremmen/vim-ripgrep'
@ -28,15 +27,10 @@ return require('packer').startup({function()
-- LSP Setup -- LSP Setup
use 'neovim/nvim-lspconfig' use 'neovim/nvim-lspconfig'
use 'kabouzeid/nvim-lspinstall' use 'kabouzeid/nvim-lspinstall'
use 'hrsh7th/nvim-cmp' use 'nvim-lua/lsp_extensions.nvim'
use 'hrsh7th/cmp-nvim-lsp' use 'nvim-lua/completion-nvim'
use 'hrsh7th/cmp-vsnip'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-buffer'
use 'simrat39/rust-tools.nvim'
use 'nvim-lua/popup.nvim' use 'nvim-lua/popup.nvim'
use 'nvim-lua/plenary.nvim' use 'nvim-lua/plenary.nvim'
use 'nvim-telescope/telescope.nvim'
end, end,
config = { config = {
display = { display = {

View File

@ -1,9 +1,13 @@
local o = vim.o local o = vim.o
local wo = vim.wo local wo = vim.wo
local bo = vim.bo local bo = vim.bo
local cmd = vim.cmd
cmd('syntax on')
cmd('set number')
cmd('set completeopt=menuone,noinsert,noselect')
cmd('set shortmess+=c')
vim.cmd('syntax on')
vim.cmd('set number')
o.startofline = true o.startofline = true
wo.cursorline = true wo.cursorline = true
@ -11,7 +15,6 @@ o.updatetime = 300
wo.signcolumn='yes' wo.signcolumn='yes'
o.showcmd = true o.showcmd = true
o.shell = 'bash' o.shell = 'bash'
o.mouse = 'a' o.mouse = 'a'
@ -22,5 +25,3 @@ bo.expandtab = true
wo.relativenumber = true wo.relativenumber = true
vim.cmd('set completeopt=menuone,noinsert,noselect')
vim.cmd('set shortmess+=c')

View File

@ -9,6 +9,14 @@ function M.create_augroup(autocmds, name)
vim.cmd('augroup END') vim.cmd('augroup END')
end end
function M.hi(name, opts)
local options = ""
for k, v in pairs(opts) do
options = options.." "..k.."="..v
end
vim.cmd("highlight "..name..options)
end
function M.create_function(body, name) function M.create_function(body, name)
vim.cmd('function! ' .. name) vim.cmd('function! ' .. name)
for _, line in ipairs(body) do for _, line in ipairs(body) do