Simplify LSP and remap a few LSP keybindings

writing
Nick Zana 3 years ago
parent 3f17c0ca75
commit 0f8b79f10a
No known key found for this signature in database
GPG Key ID: A6E59E60FE474883

@ -3,3 +3,4 @@ require('nvim_opts') -- Basic vim options
require('autocmd') -- Convenient Autocommands require('autocmd') -- Convenient Autocommands
require('lsp') require('lsp')
require('keybindings') require('keybindings')
require('nvim-cmp-cfg')

@ -3,28 +3,20 @@ local map = vim.api.nvim_set_keymap
-- Avoid infinitely recursive definitions -- Avoid infinitely recursive definitions
options = { noremap = true } options = { noremap = true }
-- Copy/paste
map('n', '<leader>y', '"+y', options)
map('v', '<leader>y', '"+y', options)
-- WINDOW MANAGEMENT -- WINDOW MANAGEMENT
-- Move windows TODO
-- Terminal -- Terminal
map('t', '<C-e>', '<C-\\><C-n>', options) -- Exit Terminal mode enter Normal map('t', '<C-e>', '<C-\\><C-n>', options) -- Exit Terminal mode enter Normal
-- FILE NAVIGATION -- FILE NAVIGATION
-- NerdTree map('n', '<leader>f', '<cmd>Telescope git_files<CR>', options)
map('n', '<leader>nt', '<cmd>NERDTreeToggle<CR>', options) map('n', '<leader>af', '<cmd>Telescope find_files<CR>', options)
map('n', '<C-p>', '<cmd>Telescope git_files<CR>', options)
map('n', '<C-f>', '<cmd>Telescope find_files<CR>', options)
-- Grep project file contents with live results, respecting .gitignore -- Grep project file contents with live results, respecting .gitignore
map('n', '<leader>ps', "<cmd>lua require('telescope.builtin').live_grep()<CR>", options) map('n', '<leader>g', "<cmd>lua require('telescope.builtin').live_grep()<CR>", options)
-- Grep for prompted str project wide
map('n', '<leader>fs', "<cmd>lua require('telescope.builtin').grep_string({ search = vim.fn.input(\"Grep For > \")})<CR>", options)
-- Telescope fuzzy search for buffers -- Telescope fuzzy search for buffers
map('n', '<leader>pb', "<cmd>lua require('telescope.builtin').buffers()<CR>", options) map('n', '<leader>b', "<cmd>lua require('telescope.builtin').buffers()<CR>", options)
map('n', 'ga', '<C-^><CR>', options) -- ga to switch to last used buffer
-- CODE NAVIGATOIN -- CODE NAVIGATOIN
@ -66,17 +58,16 @@ local on_attach = function(client, bufnr)
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', options) buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', options)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', options) buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', options)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.hover()<CR>', options) buf_set_keymap('n', '<leader>k', '<cmd>lua vim.lsp.buf.hover()<CR>', options)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', options)
buf_set_keymap('n', '<leader>s', '<cmd>lua vim.lsp.buf.signature_help()<CR>', options) buf_set_keymap('n', '<leader>s', '<cmd>lua vim.lsp.buf.signature_help()<CR>', options)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', options) buf_set_keymap('n', '<leader>r', '<cmd>lua vim.lsp.buf.rename()<CR>', options)
buf_set_keymap('n', 'ga', '<cmd>lua vim.lsp.buf.code_action()<CR>', { noremap = true }) buf_set_keymap('n', '<leader>a', '<cmd>lua vim.lsp.buf.code_action()<CR>', { noremap = true })
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', options) buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', options)
buf_set_keymap('n', '<leader>d', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', options) buf_set_keymap('n', '<leader>d', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', options)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', options) buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', options)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', options) buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', options)
buf_set_keymap('n', '<leader>q', '<cmd>lua vim.diagnostic.set_qflist()<CR>', options) buf_set_keymap('n', '<leader>Q', '<cmd>lua vim.diagnostic.set_qflist()<CR>', options)
buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', options) buf_set_keymap('n', '<leader>F', '<cmd>lua vim.lsp.buf.formatting()<CR>', options)
end end

@ -1,11 +1,14 @@
local on_attach = require'keybindings'.on_attach local on_attach = require'keybindings'.on_attach
local capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()) -- Add additional capabilities supported by nvim-cmp
local cmp = require'nvim-cmp-cfg'.cmp local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local lspconfig = require('lspconfig')
-- SERVERS -- SERVERS
-- rust_analyzer -- rust_analyzer
vim.g.rustfmt_autosave = 1 vim.g.rustfmt_autosave = 1
require'lspconfig'.rust_analyzer.setup{ lspconfig.rust_analyzer.setup{
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
settings = { settings = {
@ -20,3 +23,9 @@ require'lspconfig'.rust_analyzer.setup{
} }
} }
} }
-- clangd
lspconfig.clangd.setup{
on_attach = on_attach,
capabilities = capabilities,
}

@ -1,56 +1,47 @@
-- TODO: Improve docs -- luasnip setup
-- Setup nvim-cmp. local luasnip = require 'luasnip'
local cmp = require'cmp'
-- Ensure vsnip is installed
require'cmp_vsnip'
cmp.setup({ -- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = { snippet = {
expand = function(args) expand = function(args)
vim.fn["vsnip#anonymous"](args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
mapping = { window = {
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), completion = cmp.config.window.bordered(),
['<CR>'] = cmp.mapping.confirm({ select = true }), documentation = cmp.config.window.bordered(),
['<Tab>'] = function(fallback) },
mapping = cmp.mapping.preset.insert({
['<C-j>'] = cmp.mapping.scroll_docs(4),
['<C-k>'] = cmp.mapping.scroll_docs(-4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<C-n>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else else
fallback() fallback()
end end
end, end, { 'i', 's' }),
['<S-Tab>'] = function(fallback) ['<C-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else else
fallback() fallback()
end end
end, end, { 'i', 's' }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
}, {
{ name = 'buffer' },
}), }),
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = { sources = {
{ name = 'buffer' } { name = 'nvim_lsp' },
--{ name = 'luasnip' },
},
} }
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
return { cmp = cmp }

@ -14,28 +14,24 @@ local plugins = require('packer').startup(function(use)
commit = '80cdb00b221f69348afc4fb4b701f51eb8dd3120', -- for neovim 0.5.0 compatibility commit = '80cdb00b221f69348afc4fb4b701f51eb8dd3120', -- for neovim 0.5.0 compatibility
requires = { {'nvim-lua/plenary.nvim'} } requires = { {'nvim-lua/plenary.nvim'} }
} }
use 'preservim/nerdtree'
-- git -- git
use 'tpope/vim-fugitive' use 'tpope/vim-fugitive'
-- LSP -- LSP
use 'neovim/nvim-lspconfig' -- Common lsp server configurations use 'neovim/nvim-lspconfig' -- Common lsp server configurations
use 'tjdevries/lsp_extensions.nvim' -- Provides type inlay hint support use 'hrsh7th/nvim-cmp' -- Autocompletion plugin
use 'hrsh7th/cmp-nvim-lsp' -- Completion LSP integeration use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/nvim-cmp' -- Autocompletion
-- Snippets (Required for nvim-cmp) -- LSP Extensions
use 'hrsh7th/cmp-vsnip' use 'nvim-lua/lsp_extensions.nvim'
use 'hrsh7th/vim-vsnip'
-- Snippets (required for nvim-cmp)
use 'L3MON4D3/LuaSnip'
use 'saadparwaiz1/cmp_luasnip'
-- Language Specfic -- Language Specfic
use 'rust-lang/rust.vim' use 'rust-lang/rust.vim'
use 'cespare/vim-toml'
use 'stephpy/vim-yaml'
if packer_bootstrap then if packer_bootstrap then
require('packer').sync() require('packer').sync()

@ -0,0 +1,22 @@
require('treesitter-context').setup{
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
throttle = true, -- Throttles plugin updates (may improve performance)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries.
-- For all filetypes
default = {
'class',
'function',
'method',
'for',
'while',
-- 'if',
-- 'switch',
-- 'case',
},
rust = {
'loop_expression',
'impl_item',
},
},
}
Loading…
Cancel
Save