lspconfig is good, actually
This commit is contained in:
parent
42e39a94a8
commit
f3fdf5a234
|
@ -4,10 +4,8 @@
|
||||||
programs.neovim = {
|
programs.neovim = {
|
||||||
enable = true;
|
enable = true;
|
||||||
vimAlias = true;
|
vimAlias = true;
|
||||||
withNodeJs = true;
|
|
||||||
extraConfig = builtins.readFile ./init.vim;
|
extraConfig = builtins.readFile ./init.vim;
|
||||||
plugins = with pkgs.vimPlugins; [
|
plugins = with pkgs.vimPlugins; [
|
||||||
coc-nvim
|
|
||||||
editorconfig-vim
|
editorconfig-vim
|
||||||
fzf-vim
|
fzf-vim
|
||||||
vim-airline
|
vim-airline
|
||||||
|
@ -21,18 +19,18 @@
|
||||||
meson
|
meson
|
||||||
gruvbox
|
gruvbox
|
||||||
|
|
||||||
coc-clangd
|
nvim-lspconfig
|
||||||
vim-lsp-cxx-highlight
|
nvim-compe
|
||||||
|
|
||||||
coc-json
|
|
||||||
coc-rust-analyzer
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
home.sessionVariables.EDITOR = "nvim";
|
home.sessionVariables.EDITOR = "nvim";
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
nixpkgs-fmt
|
nixpkgs-fmt
|
||||||
|
python3
|
||||||
|
python3Packages.ipython
|
||||||
python3Packages.pylint
|
python3Packages.pylint
|
||||||
|
nodePackages.pyright
|
||||||
];
|
];
|
||||||
|
|
||||||
xdg.configFile."nvim/coc-settings.json".text = builtins.toJSON {
|
xdg.configFile."nvim/coc-settings.json".text = builtins.toJSON {
|
||||||
|
|
|
@ -15,43 +15,78 @@ set cmdheight=2
|
||||||
set updatetime=300
|
set updatetime=300
|
||||||
set shortmess+=c
|
set shortmess+=c
|
||||||
set signcolumn=yes
|
set signcolumn=yes
|
||||||
" Use tab for trigger completion with characters ahead and navigate.
|
|
||||||
inoremap <silent><expr> <TAB>
|
|
||||||
\ pumvisible() ? "\<C-n>" :
|
|
||||||
\ <SID>check_back_space() ? "\<TAB>" :
|
|
||||||
\ coc#refresh()
|
|
||||||
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
|
|
||||||
|
|
||||||
function! s:check_back_space() abort
|
lua << EOF
|
||||||
let col = col('.') - 1
|
-- Mostly stolen from https://github.com/breuerfelix/nixos/blob/e0c83e66e821d407efae3e998b8eb70b50f9f5e3/shell/vim/lsp.lua
|
||||||
return !col || getline('.')[col - 1] =~# '\s'
|
local nvim_lsp = require('lspconfig')
|
||||||
endfunction
|
local on_attach = function(client, bufnr)
|
||||||
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
||||||
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
||||||
|
|
||||||
" Use <c-space> to trigger completion.
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||||
inoremap <silent><expr> <c-space> coc#refresh()
|
|
||||||
|
|
||||||
" Use `[g` and `]g` to navigate diagnostics
|
-- Mappings.
|
||||||
nmap <silent> [g <Plug>(coc-diagnostic-prev)
|
local opts = { noremap = true, silent = true }
|
||||||
nmap <silent> ]g <Plug>(coc-diagnostic-next)
|
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||||
|
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||||
|
buf_set_keymap('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||||
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||||
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||||
|
|
||||||
" GoTo code navigation.
|
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||||
nmap <silent> gd <Plug>(coc-definition)
|
buf_set_keymap('n', '<leader>rd', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
||||||
nmap <silent> gy <Plug>(coc-type-definition)
|
buf_set_keymap('n', '<leader>rh', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||||
nmap <silent> gi <Plug>(coc-implementation)
|
buf_set_keymap('n', '<leader>rs', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||||
nmap <silent> gr <Plug>(coc-references)
|
buf_set_keymap('n', '<leader>rk', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||||
|
buf_set_keymap('n', '<leader>rj', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||||
|
buf_set_keymap('n', '<leader>rl', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||||
|
|
||||||
|
-- Set some keybinds conditional on server capabilities
|
||||||
|
if client.resolved_capabilities.document_formatting then
|
||||||
|
buf_set_keymap("n", "<leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
||||||
|
elseif client.resolved_capabilities.document_range_formatting then
|
||||||
|
buf_set_keymap("n", "<leader>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
||||||
|
end
|
||||||
|
|
||||||
" Highlight the symbol and its references when holding the cursor.
|
-- Set autocommands conditional on server_capabilities
|
||||||
autocmd CursorHold * silent call CocActionAsync('highlight')
|
if client.resolved_capabilities.document_highlight then
|
||||||
|
vim.api.nvim_exec([[
|
||||||
|
hi LspReferenceRead cterm=bold ctermbg=red guibg=LightGrey
|
||||||
|
hi LspReferenceText cterm=bold ctermbg=red guibg=LightGrey
|
||||||
|
hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightGrey
|
||||||
|
augroup lsp_document_highlight
|
||||||
|
autocmd! * <buffer>
|
||||||
|
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||||
|
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||||
|
augroup END
|
||||||
|
]], false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
" Symbol renaming.
|
nvim_lsp['pyright'].setup { on_attach = on_attach }
|
||||||
nmap <leader>rn <Plug>(coc-rename)
|
nvim_lsp['clangd'].setup { on_attach = on_attach }
|
||||||
|
|
||||||
" Formatting selected code.
|
require'compe'.setup {
|
||||||
xmap <leader>f <Plug>(coc-format-selected)
|
enabled = true;
|
||||||
nmap <leader>f <Plug>(coc-format-selected)
|
autocomplete = true;
|
||||||
|
debug = false;
|
||||||
|
min_length = 1;
|
||||||
|
preselect = 'enable';
|
||||||
|
throttle_time = 80;
|
||||||
|
source_timeout = 200;
|
||||||
|
incomplete_delay = 400;
|
||||||
|
max_abbr_width = 100;
|
||||||
|
max_kind_width = 100;
|
||||||
|
max_menu_width = 100;
|
||||||
|
documentation = true;
|
||||||
|
|
||||||
nmap <leader>a <Plug>(coc-action)
|
source = {
|
||||||
|
path = true;
|
||||||
command! -nargs=0 Format :call CocAction('format')
|
buffer = true;
|
||||||
command! -nargs=? Fold :call CocAction('fold', <f-args>)
|
calc = true;
|
||||||
|
nvim_lsp = true;
|
||||||
|
nvim_lua = true;
|
||||||
|
vsnip = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
Loading…
Reference in a new issue