extensive playing with LSP setup
This commit is contained in:
parent
f8806fff98
commit
864e126424
2 changed files with 179 additions and 81 deletions
169
nix/home.nix
169
nix/home.nix
|
|
@ -48,7 +48,8 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
git-plan
|
git-plan
|
||||||
htop
|
htop
|
||||||
|
|
@ -148,103 +149,109 @@ in {
|
||||||
|
|
||||||
vim-commentary
|
vim-commentary
|
||||||
vim-airline
|
vim-airline
|
||||||
{ plugin = rainbow;
|
{
|
||||||
config = ''
|
plugin = rainbow;
|
||||||
let g:rainbow_conf = {
|
config = ''
|
||||||
\ 'guifgs': ['RoyalBlue3', 'SeaGreen3', 'DarkOrchid3', 'firebrick3', 'RoyalBlue3', 'SeaGreen3', 'DarkOrchid3', 'firebrick3', 'RoyalBlue3', 'DarkOrchid3', 'firebrick3', 'RoyalBlue3', 'SeaGreen3', 'DarkOrchid3', 'firebrick3'],
|
let g:rainbow_conf = {
|
||||||
\ 'ctermfgs': ['red', 'brown', 'blue', 'gray', 'green', 'magenta', 'cyan', 'darkred', 'brown', 'darkblue', 'gray', 'darkgreen', 'darkmagenta', 'darkcyan', 'red'],
|
\ 'guifgs': ['RoyalBlue3', 'SeaGreen3', 'DarkOrchid3', 'firebrick3', 'RoyalBlue3', 'SeaGreen3', 'DarkOrchid3', 'firebrick3', 'RoyalBlue3', 'DarkOrchid3', 'firebrick3', 'RoyalBlue3', 'SeaGreen3', 'DarkOrchid3', 'firebrick3'],
|
||||||
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold']
|
\ 'ctermfgs': ['red', 'brown', 'blue', 'gray', 'green', 'magenta', 'cyan', 'darkred', 'brown', 'darkblue', 'gray', 'darkgreen', 'darkmagenta', 'darkcyan', 'red'],
|
||||||
\}
|
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold']
|
||||||
let g:rainbow_active = 1
|
\}
|
||||||
|
let g:rainbow_active = 1
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
vim-signify
|
vim-signify
|
||||||
vim-indent-guides
|
vim-indent-guides
|
||||||
vim-surround
|
vim-surround
|
||||||
fugitive
|
fugitive
|
||||||
{ plugin = easymotion;
|
{
|
||||||
config = ''
|
plugin = easymotion;
|
||||||
map / <Plug>(easymotion-sn)
|
config = ''
|
||||||
omap / <Plug>(easymotion-tn)
|
map / <Plug>(easymotion-sn)
|
||||||
map n <Plug>(easymotion-next)
|
omap / <Plug>(easymotion-tn)
|
||||||
map N <Plug>(easymotion-prev)
|
map n <Plug>(easymotion-next)
|
||||||
let g:EasyMotion_landing_highlight = 0
|
map N <Plug>(easymotion-prev)
|
||||||
|
let g:EasyMotion_landing_highlight = 0
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
vinegar
|
vinegar
|
||||||
undotree
|
undotree
|
||||||
{ plugin = vim-test;
|
{
|
||||||
config = ''
|
plugin = vim-test;
|
||||||
nmap <silent> <leader>t :TestNearest<CR>
|
config = ''
|
||||||
nmap <silent> <leader>T :TestFile<CR>
|
nmap <silent> <leader>t :TestNearest<CR>
|
||||||
nmap <silent> <leader>a :TestSuite<CR>
|
nmap <silent> <leader>T :TestFile<CR>
|
||||||
nmap <silent> <leader>l :TestLast<CR>
|
nmap <silent> <leader>a :TestSuite<CR>
|
||||||
nmap <silent> <leader>g :TestVisit<CR>
|
nmap <silent> <leader>l :TestLast<CR>
|
||||||
let test#strategy = "neovim"
|
nmap <silent> <leader>g :TestVisit<CR>
|
||||||
|
let test#strategy = "neovim"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{ plugin = ale;
|
{
|
||||||
config = ''
|
plugin = ale;
|
||||||
let g:ale_fix_on_save = 1
|
config = ''
|
||||||
let g:ale_elixir_credo_strict = 1
|
let g:ale_fix_on_save = 1
|
||||||
let g:ale_fixers = {
|
let g:ale_elixir_credo_strict = 1
|
||||||
\ 'elm': ['elm-format', 'format'],
|
let g:ale_fixers = {
|
||||||
\ 'javascript': ['prettier'],
|
\ 'javascript': ['prettier'],
|
||||||
\ 'javascript.jsx': ['prettier'],
|
\ 'javascript.jsx': ['prettier'],
|
||||||
\ 'javascriptreact': ['prettier'],
|
\ 'javascriptreact': ['prettier'],
|
||||||
\ 'typescriptreact': ['prettier'],
|
\ 'ruby': ['sorbet'],
|
||||||
\ 'typescript': ['prettier'],
|
\ 'rust': ['rustfmt'],
|
||||||
\ 'ruby': ['sorbet'],
|
\}
|
||||||
\ 'rust': ['rustfmt'],
|
let g:ale_linters_explicit = 1
|
||||||
\ 'elixir': ['mix_format']
|
|
||||||
\}
|
|
||||||
let g:ale_linters_explicit = 1
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
fzf-vim
|
fzf-vim
|
||||||
fzfWrapper
|
fzfWrapper
|
||||||
{ plugin = nvim-compe;
|
{
|
||||||
config = ''
|
plugin = nvim-compe;
|
||||||
set completeopt=menuone,noselect
|
config = ''
|
||||||
let g:compe = {}
|
set completeopt=menuone,noselect
|
||||||
let g:compe.enabled = v:true
|
let g:compe = {}
|
||||||
let g:compe.autocomplete = v:true
|
let g:compe.enabled = v:true
|
||||||
let g:compe.debug = v:false
|
let g:compe.autocomplete = v:true
|
||||||
let g:compe.min_length = 1
|
let g:compe.debug = v:false
|
||||||
let g:compe.preselect = 'enable'
|
let g:compe.min_length = 1
|
||||||
let g:compe.throttle_time = 80
|
let g:compe.preselect = 'enable'
|
||||||
let g:compe.source_timeout = 200
|
let g:compe.throttle_time = 80
|
||||||
let g:compe.resolve_timeout = 800
|
let g:compe.source_timeout = 200
|
||||||
let g:compe.incomplete_delay = 400
|
let g:compe.resolve_timeout = 800
|
||||||
let g:compe.max_abbr_width = 100
|
let g:compe.incomplete_delay = 400
|
||||||
let g:compe.max_kind_width = 100
|
let g:compe.max_abbr_width = 100
|
||||||
let g:compe.max_menu_width = 100
|
let g:compe.max_kind_width = 100
|
||||||
let g:compe.documentation = v:true
|
let g:compe.max_menu_width = 100
|
||||||
|
let g:compe.documentation = v:true
|
||||||
|
|
||||||
let g:compe.source = {}
|
let g:compe.source = {}
|
||||||
let g:compe.source.path = v:true
|
let g:compe.source.path = v:true
|
||||||
let g:compe.source.buffer = v:true
|
let g:compe.source.buffer = v:true
|
||||||
let g:compe.source.calc = v:true
|
let g:compe.source.calc = v:true
|
||||||
let g:compe.source.nvim_lsp = v:true
|
let g:compe.source.nvim_lsp = v:true
|
||||||
let g:compe.source.nvim_lua = v:true
|
let g:compe.source.nvim_lua = v:true
|
||||||
let g:compe.source.vsnip = v:true
|
let g:compe.source.vsnip = v:true
|
||||||
let g:compe.source.ultisnips = v:true
|
let g:compe.source.ultisnips = v:true
|
||||||
let g:compe.source.luasnip = v:true
|
let g:compe.source.luasnip = v:true
|
||||||
let g:compe.source.emoji = v:true
|
let g:compe.source.emoji = v:true
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
vim-goyo
|
vim-goyo
|
||||||
{ plugin = nvim-lspconfig ;
|
{
|
||||||
config = ''
|
plugin = nvim-lspconfig;
|
||||||
lua << EOF
|
config = ''
|
||||||
require'lspconfig'.elmls.setup{}
|
lua << EOF
|
||||||
require'lspconfig'.tsserver.setup{}
|
${readFile (
|
||||||
require'lspconfig'.elixirls.setup{
|
pkgs.substituteAll {
|
||||||
cmd = { "${pkgs.elixir_ls}/bin/elixir-ls" };
|
src = ./vim/nvim-lspconfig.lua;
|
||||||
|
# since both of these are used for actually configuring the system,
|
||||||
|
# we'll probably always want them around.
|
||||||
|
lua_ls = pkgs.sumneko-lua-language-server;
|
||||||
|
rnix_lsp = pkgs.rnix-lsp;
|
||||||
}
|
}
|
||||||
EOF
|
) }
|
||||||
|
EOF
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
extraConfig = readFile ./vim/init.vim;
|
extraConfig = readFile ./vim/init.vim;
|
||||||
|
|
|
||||||
91
nix/vim/nvim-lspconfig.lua
Normal file
91
nix/vim/nvim-lspconfig.lua
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
local nvim_lsp = require("lspconfig")
|
||||||
|
|
||||||
|
local format_async = function(err, _, result, _, bufnr)
|
||||||
|
if err ~= nil or result == nil then return end
|
||||||
|
if not vim.api.nvim_buf_get_option(bufnr, "modified") then
|
||||||
|
local view = vim.fn.winsaveview()
|
||||||
|
vim.lsp.util.apply_text_edits(result, bufnr)
|
||||||
|
vim.fn.winrestview(view)
|
||||||
|
if bufnr == vim.api.nvim_get_current_buf() then
|
||||||
|
vim.api.nvim_command("noautocmd :update")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.lsp.handlers["textDocument/formatting"] = format_async
|
||||||
|
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
local buf_map = vim.api.nvim_buf_set_keymap
|
||||||
|
|
||||||
|
vim.cmd("command! LspDef lua vim.lsp.buf.definition()")
|
||||||
|
vim.cmd("command! LspFormatting lua vim.lsp.buf.formatting()")
|
||||||
|
vim.cmd("command! LspCodeAction lua vim.lsp.buf.code_action()")
|
||||||
|
vim.cmd("command! LspHover lua vim.lsp.buf.hover()")
|
||||||
|
vim.cmd("command! LspRename lua vim.lsp.buf.rename()")
|
||||||
|
vim.cmd("command! LspOrganize lua lsp_organize_imports()")
|
||||||
|
vim.cmd("command! LspRefs lua vim.lsp.buf.references()")
|
||||||
|
vim.cmd("command! LspTypeDef lua vim.lsp.buf.type_definition()")
|
||||||
|
vim.cmd("command! LspImplementation lua vim.lsp.buf.implementation()")
|
||||||
|
vim.cmd("command! LspDiagPrev lua vim.lsp.diagnostic.goto_prev()")
|
||||||
|
vim.cmd("command! LspDiagNext lua vim.lsp.diagnostic.goto_next()")
|
||||||
|
vim.cmd("command! LspDiagLine lua vim.lsp.diagnostic.show_line_diagnostics()")
|
||||||
|
vim.cmd("command! LspSignatureHelp lua vim.lsp.buf.signature_help()")
|
||||||
|
|
||||||
|
buf_map(bufnr, "n", "gd", ":LspDef<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "gr", ":LspRename<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "gR", ":LspRefs<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "gy", ":LspTypeDef<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "K", ":LspHover<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "gs", ":LspOrganize<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "[a", ":LspDiagPrev<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "]a", ":LspDiagNext<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "ga", ":LspCodeAction<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "n", "<Leader>a", ":LspDiagLine<CR>", {silent = true})
|
||||||
|
buf_map(bufnr, "i", "<C-x><C-x>", "<cmd> LspSignatureHelp<CR>", {silent = true})
|
||||||
|
|
||||||
|
if client.resolved_capabilities.document_formatting then
|
||||||
|
vim.api.nvim_exec([[
|
||||||
|
augroup LspAutocommands
|
||||||
|
autocmd! * <buffer>
|
||||||
|
autocmd BufWritePost <buffer> LspFormatting
|
||||||
|
augroup END
|
||||||
|
]], true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
nvim_lsp.diagnosticls.setup {
|
||||||
|
on_attach = on_attach
|
||||||
|
}
|
||||||
|
|
||||||
|
nvim_lsp.elmls.setup{
|
||||||
|
on_attach = on_attach;
|
||||||
|
}
|
||||||
|
nvim_lsp.tsserver.setup {
|
||||||
|
on_attach = function(client)
|
||||||
|
-- Avoid conflict with prettier
|
||||||
|
client.resolved_capabilities.document_formatting = false
|
||||||
|
on_attach(client)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
nvim_lsp.elixirls.setup{
|
||||||
|
cmd = { "elixir-ls" };
|
||||||
|
on_attach = on_attach;
|
||||||
|
}
|
||||||
|
nvim_lsp.rnix.setup{
|
||||||
|
cmd = { "@rnix_lsp@/bin/rnix-lsp" };
|
||||||
|
on_attach = on_attach;
|
||||||
|
}
|
||||||
|
nvim_lsp.rust_analyzer.setup{
|
||||||
|
on_attach = on_attach;
|
||||||
|
}
|
||||||
|
|
||||||
|
nvim_lsp.sumneko_lua.setup{
|
||||||
|
cmd = { "@lua_ls@/bin/lua-language-server" };
|
||||||
|
on_attach = on_attach;
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
diagnostics = {
|
||||||
|
globals = { 'vim' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue