LSP nvim stuff
This commit is contained in:
parent
82bceebbfd
commit
1d7acb6a57
4 changed files with 114 additions and 99 deletions
|
@ -1,21 +1,21 @@
|
||||||
for _,keys in ipairs{'jj', 'jJ', 'Jj', 'JJ', 'jk', 'jK', 'Jk', 'JK'} do vim.api.nvim_set_keymap('i', keys, '<Esc>', {}) end
|
for _, keys in ipairs { 'jj', 'jJ', 'Jj', 'JJ', 'jk', 'jK', 'Jk', 'JK' } do vim.api.nvim_set_keymap('i', keys, '<Esc>', {}) end
|
||||||
|
|
||||||
local m = {
|
local m = {
|
||||||
s = {silent = true},
|
s = { silent = true },
|
||||||
n = {noremap = true},
|
n = { noremap = true },
|
||||||
sn = {silent = true, noremap = true},
|
sn = { silent = true, noremap = true },
|
||||||
}
|
}
|
||||||
local keymap = {
|
local keymap = {
|
||||||
n = {
|
n = {
|
||||||
['<leader>/'] = {':let @/ = ""<cr>:<BACKSPACE>', m.s},
|
['<leader>/'] = { ':let @/ = ""<cr>:<BACKSPACE>', m.s },
|
||||||
|
|
||||||
['<leader>r'] = {':luafile ' .. vim.g.vimdir .. '/init.lua<cr>:echo \'Reloaded init.lua\'<cr>', m.s},
|
['<leader>r'] = { ':luafile ' .. vim.g.vimdir .. '/init.lua<cr>:echo \'Reloaded init.lua\'<cr>', m.s },
|
||||||
['<leader>gv'] = {':e ' .. vim.g.vimdir .. '/init.lua<cr>', m.s},
|
['<leader>gv'] = { ':e ' .. vim.g.vimdir .. '/init.lua<cr>', m.s },
|
||||||
|
|
||||||
['<leader>w'] = {':bd<cr>', m.s},
|
['<leader>w'] = { ':bd<cr>', m.s },
|
||||||
['<leader>h'] = {':b#<cr>', m.s},
|
['<leader>h'] = { ':b#<cr>', m.s },
|
||||||
['<leader>k'] = {':bnext<cr>', m.s},
|
['<leader>k'] = { ':bnext<cr>', m.s },
|
||||||
['<leader>j'] = {':bprevious<cr>', m.s},
|
['<leader>j'] = { ':bprevious<cr>', m.s },
|
||||||
|
|
||||||
['<c-q>'] = ':qa<cr>',
|
['<c-q>'] = ':qa<cr>',
|
||||||
|
|
||||||
|
@ -44,37 +44,32 @@ local keymap = {
|
||||||
t = {},
|
t = {},
|
||||||
|
|
||||||
[''] = {
|
[''] = {
|
||||||
['<space>'] = {'<nop>', m.sn},
|
['<space>'] = { '<nop>', m.sn },
|
||||||
|
|
||||||
-- remove trailing whitespace
|
-- remove trailing whitespace
|
||||||
['<f3>'] = 'mw:%s/\\s\\+$//<cr>:let @/ = ""<cr>\'w',
|
['<f3>'] = 'mw:%s/\\s\\+$//<cr>:let @/ = ""<cr>\'w',
|
||||||
['<leader>gs'] = ':setlocal spell!<cr>',
|
['<leader>gs'] = ':setlocal spell!<cr>',
|
||||||
[',w'] = {'<Plug>CamelCaseMotion_w', m.s},
|
[',w'] = { '<Plug>CamelCaseMotion_w', m.s },
|
||||||
[',b'] = {'<Plug>CamelCaseMotion_b', m.s},
|
[',b'] = { '<Plug>CamelCaseMotion_b', m.s },
|
||||||
[',e'] = {'<Plug>CamelCaseMotion_e', m.s},
|
[',e'] = { '<Plug>CamelCaseMotion_e', m.s },
|
||||||
[',ge'] = {'<Plug>CamelCaseMotion_ge', m.s},
|
[',ge'] = { '<Plug>CamelCaseMotion_ge', m.s },
|
||||||
},
|
},
|
||||||
o = {
|
o = {
|
||||||
['ib'] = {'<Plug>CamelCaseMotion_ib', m.s},
|
['ib'] = { '<Plug>CamelCaseMotion_ib', m.s },
|
||||||
['ie'] = {'<Plug>CamelCaseMotion_ie', m.s},
|
['ie'] = { '<Plug>CamelCaseMotion_ie', m.s },
|
||||||
},
|
},
|
||||||
x = {
|
x = {
|
||||||
['<'] = '<gv',
|
['<'] = '<gv',
|
||||||
['>'] = '>gv',
|
['>'] = '>gv',
|
||||||
['ib'] = {'<Plug>CamelCaseMotion_ib', m.s},
|
['ib'] = { '<Plug>CamelCaseMotion_ib', m.s },
|
||||||
['ie'] = {'<Plug>CamelCaseMotion_ie', m.s},
|
['ie'] = { '<Plug>CamelCaseMotion_ie', m.s },
|
||||||
},
|
|
||||||
c = {
|
|
||||||
['<c-n>'] = '<down>',
|
|
||||||
['<c-p>'] = '<up>',
|
|
||||||
},
|
},
|
||||||
i = {
|
i = {
|
||||||
['<c-q>'] = '<esc><c-q>',
|
['<c-q>'] = '<esc><c-q>',
|
||||||
['<c-n>'] = {'<Plug>(completion_trigger)', m.s},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for mode,mappings in pairs(keymap) do
|
for mode, mappings in pairs(keymap) do
|
||||||
for key,bind in pairs(mappings) do
|
for key, bind in pairs(mappings) do
|
||||||
if type(bind) == 'table' then
|
if type(bind) == 'table' then
|
||||||
vim.api.nvim_set_keymap(mode, key, bind[1], bind[2])
|
vim.api.nvim_set_keymap(mode, key, bind[1], bind[2])
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local lsp = require'lspconfig'
|
local lsp = require 'lspconfig'
|
||||||
-- local coq = require'coq'
|
-- local coq = require'coq'
|
||||||
|
|
||||||
-- TODO: replace with nvim lsp bindings for jumping to next linting issue?
|
-- TODO: replace with nvim lsp bindings for jumping to next linting issue?
|
||||||
|
@ -9,7 +9,7 @@ local opts = {
|
||||||
silent = true,
|
silent = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local lsp_format = require'lsp-format'
|
local lsp_format = require 'lsp-format'
|
||||||
|
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
lsp_format.on_attach(client)
|
lsp_format.on_attach(client)
|
||||||
|
@ -31,11 +31,12 @@ local on_attach = function(client, bufnr)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting_seq_sync()<CR>', opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local capabilities = require 'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
local common_config = {
|
local common_config = {
|
||||||
capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
flags = {
|
flags = {
|
||||||
debounce_text_changes = 150
|
debounce_text_changes = 150
|
||||||
|
@ -45,13 +46,19 @@ local common_config = {
|
||||||
local lsp_configs = {
|
local lsp_configs = {
|
||||||
gopls = {},
|
gopls = {},
|
||||||
elixirls = {
|
elixirls = {
|
||||||
cmd = { vim.fn.expand'~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' },
|
cmd = { vim.fn.expand '~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' },
|
||||||
|
settings = {
|
||||||
|
elixirLS = {
|
||||||
|
dialyzerEnabled = true,
|
||||||
|
fetchDeps = false,
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
sumneko_lua = {
|
sumneko_lua = {
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
globals = {'vim'}
|
globals = { 'vim' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,11 +73,11 @@ local lsp_configs = {
|
||||||
}
|
}
|
||||||
|
|
||||||
for server, config in pairs(lsp_configs) do
|
for server, config in pairs(lsp_configs) do
|
||||||
for k,v in pairs(common_config) do config[k] = v end
|
for k, v in pairs(common_config) do config[k] = v end
|
||||||
lsp[server].setup(config)
|
lsp[server].setup(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
local lsp_installer = require'nvim-lsp-installer'
|
local lsp_installer = require 'nvim-lsp-installer'
|
||||||
lsp_installer.on_server_ready(function(server)
|
lsp_installer.on_server_ready(function(server)
|
||||||
local server_opts = {}
|
local server_opts = {}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local packer_install_path = vim.fn.stdpath'data' .. '/site/pack/packer/start/packer.nvim'
|
local packer_install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
|
||||||
if #vim.fn.glob(packer_install_path) == 0 then
|
if #vim.fn.glob(packer_install_path) == 0 then
|
||||||
vim.fn.system{'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path}
|
vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path }
|
||||||
vim.api.nvim_command'packadd packer.nvim'
|
vim.api.nvim_command 'packadd packer.nvim'
|
||||||
end
|
end
|
||||||
|
|
||||||
local has_words_before = function()
|
local has_words_before = function()
|
||||||
|
@ -9,7 +9,7 @@ local has_words_before = function()
|
||||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local packer = require'packer'
|
local packer = require 'packer'
|
||||||
|
|
||||||
packer.startup(function()
|
packer.startup(function()
|
||||||
local plugins = {
|
local plugins = {
|
||||||
|
@ -22,7 +22,7 @@ packer.startup(function()
|
||||||
'christoomey/vim-tmux-navigator', -- navigate vim splits and tmux panes fluidly
|
'christoomey/vim-tmux-navigator', -- navigate vim splits and tmux panes fluidly
|
||||||
'machakann/vim-sandwich', -- edit surrounding characters
|
'machakann/vim-sandwich', -- edit surrounding characters
|
||||||
'michaeljsmith/vim-indent-object', -- adds indent-level text objects
|
'michaeljsmith/vim-indent-object', -- adds indent-level text objects
|
||||||
'wellle/targets.vim', -- add many other text objects
|
-- 'wellle/targets.vim', -- add many other text objects
|
||||||
'bkad/CamelCaseMotion', -- invaluable motions for properly operating on various casings
|
'bkad/CamelCaseMotion', -- invaluable motions for properly operating on various casings
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ packer.startup(function()
|
||||||
'olimorris/persisted.nvim',
|
'olimorris/persisted.nvim',
|
||||||
config = function()
|
config = function()
|
||||||
local should_autoload = #vim.v.argv == 1
|
local should_autoload = #vim.v.argv == 1
|
||||||
require'persisted'.setup{
|
require 'persisted'.setup {
|
||||||
autoload = should_autoload,
|
autoload = should_autoload,
|
||||||
autosave = should_autoload,
|
autosave = should_autoload,
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ packer.startup(function()
|
||||||
-- toggle comments
|
-- toggle comments
|
||||||
'terrortylor/nvim-comment',
|
'terrortylor/nvim-comment',
|
||||||
config = function()
|
config = function()
|
||||||
require'nvim_comment'.setup()
|
require 'nvim_comment'.setup()
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ packer.startup(function()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'tzachar/cmp-fuzzy-path',
|
'tzachar/cmp-fuzzy-path',
|
||||||
requires = {'hrsh7th/nvim-cmp', 'tzachar/fuzzy.nvim'},
|
requires = { 'hrsh7th/nvim-cmp', 'tzachar/fuzzy.nvim' },
|
||||||
},
|
},
|
||||||
-- TODO: add keymap <leader>ig for toggling these
|
-- TODO: add keymap <leader>ig for toggling these
|
||||||
'lukas-reineke/indent-blankline.nvim', -- indentation guide lines
|
'lukas-reineke/indent-blankline.nvim', -- indentation guide lines
|
||||||
|
@ -70,34 +70,26 @@ packer.startup(function()
|
||||||
'hrsh7th/cmp-buffer', -- add buffer information to completion engine
|
'hrsh7th/cmp-buffer', -- add buffer information to completion engine
|
||||||
'hrsh7th/cmp-path', -- add filesystem information to complete enging
|
'hrsh7th/cmp-path', -- add filesystem information to complete enging
|
||||||
'hrsh7th/cmp-cmdline', -- add completion for vim commands
|
'hrsh7th/cmp-cmdline', -- add completion for vim commands
|
||||||
|
'onsails/lspkind-nvim',
|
||||||
'saadparwaiz1/cmp_luasnip',
|
'saadparwaiz1/cmp_luasnip',
|
||||||
{
|
{
|
||||||
-- completion engine
|
-- completion engine
|
||||||
'hrsh7th/nvim-cmp',
|
'hrsh7th/nvim-cmp',
|
||||||
config = function()
|
config = function()
|
||||||
local cmp = require'cmp'
|
local cmp = require 'cmp'
|
||||||
local luasnip = require'luasnip'
|
local luasnip = require 'luasnip'
|
||||||
|
|
||||||
cmp.setup{
|
local prev_item = function(fallback)
|
||||||
snippet = {
|
if cmp.visible() then
|
||||||
expand = function(args)
|
cmp.select_prev_item()
|
||||||
luasnip.lsp_expand(args.body)
|
elseif luasnip.jumpable(-1) then
|
||||||
end,
|
luasnip.jump(-1)
|
||||||
},
|
else
|
||||||
mapping = {
|
fallback()
|
||||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
end
|
||||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
end
|
||||||
['<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(),
|
|
||||||
},
|
|
||||||
['<Tab>'] = cmp.config.disable,
|
|
||||||
['<S-Tab>'] = cmp.config.disable,
|
|
||||||
['<CR>'] = cmp.mapping.confirm{select = true}, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
||||||
--[[ ["<Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
|
|
||||||
|
local next_item = function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_next_item()
|
cmp.select_next_item()
|
||||||
elseif luasnip.expand_or_jumpable() then
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
@ -107,17 +99,28 @@ packer.startup(function()
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.select_prev_item()
|
|
||||||
elseif luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
|
||||||
]]--
|
cmp.setup {
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = {
|
||||||
|
['<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,
|
||||||
|
['<C-e>'] = cmp.mapping {
|
||||||
|
i = cmp.mapping.abort(),
|
||||||
|
c = cmp.mapping.close(),
|
||||||
|
},
|
||||||
|
['<CR>'] = cmp.mapping.confirm { select = false },
|
||||||
|
["<Tab>"] = cmp.mapping(next_item, { "i", "s" }),
|
||||||
|
["<S-Tab>"] = cmp.mapping(prev_item, { "i", "s" }),
|
||||||
|
['<C-n>'] = cmp.mapping(next_item, { "i", "s" }),
|
||||||
|
['<C-p>'] = cmp.mapping(prev_item, { "i", "s" }),
|
||||||
},
|
},
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
|
@ -128,20 +131,30 @@ packer.startup(function()
|
||||||
{ name = 'path' },
|
{ name = 'path' },
|
||||||
{ name = 'fuzzy_path' },
|
{ name = 'fuzzy_path' },
|
||||||
}),
|
}),
|
||||||
|
formatting = {
|
||||||
|
format = require("lspkind").cmp_format {
|
||||||
|
with_text = true,
|
||||||
|
menu = {
|
||||||
|
nvim_lsp = "[LSP]",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmp.setup.cmdline('/', {
|
cmp.setup.cmdline('/', {
|
||||||
|
-- mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = {
|
sources = {
|
||||||
{name = 'buffer'},
|
{ name = 'buffer' },
|
||||||
{name = 'fuzzy_path'},
|
{ name = 'fuzzy_path' },
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
cmp.setup.cmdline(':', {
|
cmp.setup.cmdline(':', {
|
||||||
|
-- mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{name = 'path'}
|
{ name = 'path' }
|
||||||
}, {
|
}, {
|
||||||
{name = 'cmdline'}
|
{ name = 'cmdline' }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
@ -154,8 +167,8 @@ packer.startup(function()
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
run = ':TSUpdate',
|
run = ':TSUpdate',
|
||||||
config = function()
|
config = function()
|
||||||
require'nvim-treesitter.configs'.setup {
|
require 'nvim-treesitter.configs'.setup {
|
||||||
ensure_installed = "maintained",
|
ensure_installed = "all",
|
||||||
sync_install = false,
|
sync_install = false,
|
||||||
ignore_install = {},
|
ignore_install = {},
|
||||||
indent = {
|
indent = {
|
||||||
|
@ -175,5 +188,5 @@ packer.startup(function()
|
||||||
},
|
},
|
||||||
'lukas-reineke/lsp-format.nvim',
|
'lukas-reineke/lsp-format.nvim',
|
||||||
}
|
}
|
||||||
for _,plugin in pairs(plugins) do packer.use(plugin) end
|
for _, plugin in pairs(plugins) do packer.use(plugin) end
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -30,7 +30,7 @@ set -g monitor-activity on
|
||||||
set -g visual-bell on
|
set -g visual-bell on
|
||||||
set -g bell-action other
|
set -g bell-action other
|
||||||
set -g mode-keys vi
|
set -g mode-keys vi
|
||||||
set -g history-limit 102400000
|
set -g history-limit 1024000
|
||||||
set -g status on
|
set -g status on
|
||||||
set -g status-position bottom
|
set -g status-position bottom
|
||||||
set -g status-bg colour0
|
set -g status-bg colour0
|
||||||
|
|
Reference in a new issue