LSP nvim stuff

This commit is contained in:
Daniel Flanagan 2022-04-15 12:52:46 -05:00
parent 82bceebbfd
commit 1d7acb6a57
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
4 changed files with 114 additions and 99 deletions

View file

@ -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 = {
s = {silent = true},
n = {noremap = true},
sn = {silent = true, noremap = true},
s = { silent = true },
n = { noremap = true },
sn = { silent = true, noremap = true },
}
local keymap = {
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>gv'] = {':e ' .. vim.g.vimdir .. '/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>w'] = {':bd<cr>', m.s},
['<leader>h'] = {':b#<cr>', m.s},
['<leader>k'] = {':bnext<cr>', m.s},
['<leader>j'] = {':bprevious<cr>', m.s},
['<leader>w'] = { ':bd<cr>', m.s },
['<leader>h'] = { ':b#<cr>', m.s },
['<leader>k'] = { ':bnext<cr>', m.s },
['<leader>j'] = { ':bprevious<cr>', m.s },
['<c-q>'] = ':qa<cr>',
@ -44,37 +44,32 @@ local keymap = {
t = {},
[''] = {
['<space>'] = {'<nop>', m.sn},
['<space>'] = { '<nop>', m.sn },
-- remove trailing whitespace
['<f3>'] = 'mw:%s/\\s\\+$//<cr>:let @/ = ""<cr>\'w',
['<leader>gs'] = ':setlocal spell!<cr>',
[',w'] = {'<Plug>CamelCaseMotion_w', m.s},
[',b'] = {'<Plug>CamelCaseMotion_b', m.s},
[',e'] = {'<Plug>CamelCaseMotion_e', m.s},
[',ge'] = {'<Plug>CamelCaseMotion_ge', m.s},
[',w'] = { '<Plug>CamelCaseMotion_w', m.s },
[',b'] = { '<Plug>CamelCaseMotion_b', m.s },
[',e'] = { '<Plug>CamelCaseMotion_e', m.s },
[',ge'] = { '<Plug>CamelCaseMotion_ge', m.s },
},
o = {
['ib'] = {'<Plug>CamelCaseMotion_ib', m.s},
['ie'] = {'<Plug>CamelCaseMotion_ie', m.s},
['ib'] = { '<Plug>CamelCaseMotion_ib', m.s },
['ie'] = { '<Plug>CamelCaseMotion_ie', m.s },
},
x = {
['<'] = '<gv',
['>'] = '>gv',
['ib'] = {'<Plug>CamelCaseMotion_ib', m.s},
['ie'] = {'<Plug>CamelCaseMotion_ie', m.s},
},
c = {
['<c-n>'] = '<down>',
['<c-p>'] = '<up>',
['ib'] = { '<Plug>CamelCaseMotion_ib', m.s },
['ie'] = { '<Plug>CamelCaseMotion_ie', m.s },
},
i = {
['<c-q>'] = '<esc><c-q>',
['<c-n>'] = {'<Plug>(completion_trigger)', m.s},
},
}
for mode,mappings in pairs(keymap) do
for key,bind in pairs(mappings) do
for mode, mappings in pairs(keymap) do
for key, bind in pairs(mappings) do
if type(bind) == 'table' then
vim.api.nvim_set_keymap(mode, key, bind[1], bind[2])
else

View file

@ -1,4 +1,4 @@
local lsp = require'lspconfig'
local lsp = require 'lspconfig'
-- local coq = require'coq'
-- TODO: replace with nvim lsp bindings for jumping to next linting issue?
@ -9,7 +9,7 @@ local opts = {
silent = true,
}
local lsp_format = require'lsp-format'
local lsp_format = require 'lsp-format'
local on_attach = function(client, bufnr)
lsp_format.on_attach(client)
@ -18,24 +18,25 @@ local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'g]', '<cmd>lua vim.diagnostic.goto_next()<cr>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'g[', '<cmd>lua vim.diagnostic.goto_prev()<cr>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-a>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'i', '<C-a>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<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', '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', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-a>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'i', '<C-a>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<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', '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_seq_sync()<CR>', opts)
end
local capabilities = require 'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities())
local common_config = {
capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities()),
capabilities = capabilities,
on_attach = on_attach,
flags = {
debounce_text_changes = 150
@ -45,13 +46,19 @@ local common_config = {
local lsp_configs = {
gopls = {},
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 = {
settings = {
Lua = {
diagnostics = {
globals = {'vim'}
globals = { 'vim' }
}
}
}
@ -66,17 +73,17 @@ local lsp_configs = {
}
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)
end
local lsp_installer = require'nvim-lsp-installer'
local lsp_installer = require 'nvim-lsp-installer'
lsp_installer.on_server_ready(function(server)
local server_opts = {}
local server_opts = {}
-- if server.name == "elixirls" then
-- server_opts.cmd = { vim.fn.expand'~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' }
-- end
-- if server.name == "elixirls" then
-- server_opts.cmd = { vim.fn.expand'~/.local/share/nvim/lsp_servers/elixir/elixir-ls/language_server.sh' }
-- end
server:setup(server_opts)
server:setup(server_opts)
end)

View file

@ -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
vim.fn.system{'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path}
vim.api.nvim_command'packadd packer.nvim'
vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_install_path }
vim.api.nvim_command 'packadd packer.nvim'
end
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
end
local packer = require'packer'
local packer = require 'packer'
packer.startup(function()
local plugins = {
@ -22,7 +22,7 @@ packer.startup(function()
'christoomey/vim-tmux-navigator', -- navigate vim splits and tmux panes fluidly
'machakann/vim-sandwich', -- edit surrounding characters
'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
{
@ -30,7 +30,7 @@ packer.startup(function()
'olimorris/persisted.nvim',
config = function()
local should_autoload = #vim.v.argv == 1
require'persisted'.setup{
require 'persisted'.setup {
autoload = should_autoload,
autosave = should_autoload,
}
@ -40,7 +40,7 @@ packer.startup(function()
-- toggle comments
'terrortylor/nvim-comment',
config = function()
require'nvim_comment'.setup()
require 'nvim_comment'.setup()
end
},
{
@ -57,7 +57,7 @@ packer.startup(function()
},
{
'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
'lukas-reineke/indent-blankline.nvim', -- indentation guide lines
@ -70,15 +70,38 @@ packer.startup(function()
'hrsh7th/cmp-buffer', -- add buffer information to completion engine
'hrsh7th/cmp-path', -- add filesystem information to complete enging
'hrsh7th/cmp-cmdline', -- add completion for vim commands
'onsails/lspkind-nvim',
'saadparwaiz1/cmp_luasnip',
{
-- completion engine
'hrsh7th/nvim-cmp',
config = function()
local cmp = require'cmp'
local luasnip = require'luasnip'
local cmp = require 'cmp'
local luasnip = require 'luasnip'
cmp.setup{
local prev_item = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end
local next_item = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
@ -88,36 +111,16 @@ packer.startup(function()
['<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{
['<C-y>'] = cmp.config.disable,
['<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)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
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, { "i", "s" }),
]]--
['<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({
{ name = 'nvim_lsp' },
@ -128,20 +131,30 @@ packer.startup(function()
{ name = 'path' },
{ name = 'fuzzy_path' },
}),
formatting = {
format = require("lspkind").cmp_format {
with_text = true,
menu = {
nvim_lsp = "[LSP]",
},
}
},
}
cmp.setup.cmdline('/', {
-- mapping = cmp.mapping.preset.cmdline(),
sources = {
{name = 'buffer'},
{name = 'fuzzy_path'},
{ name = 'buffer' },
{ name = 'fuzzy_path' },
}
})
cmp.setup.cmdline(':', {
-- mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{name = 'path'}
{ name = 'path' }
}, {
{name = 'cmdline'}
{ name = 'cmdline' }
})
})
end,
@ -154,8 +167,8 @@ packer.startup(function()
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate',
config = function()
require'nvim-treesitter.configs'.setup {
ensure_installed = "maintained",
require 'nvim-treesitter.configs'.setup {
ensure_installed = "all",
sync_install = false,
ignore_install = {},
indent = {
@ -175,5 +188,5 @@ packer.startup(function()
},
'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)

View file

@ -30,7 +30,7 @@ set -g monitor-activity on
set -g visual-bell on
set -g bell-action other
set -g mode-keys vi
set -g history-limit 102400000
set -g history-limit 1024000
set -g status on
set -g status-position bottom
set -g status-bg colour0