1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-29 06:32:10 +03:00
nil/dev/vim-coc.nix

134 lines
4.1 KiB
Nix
Raw Normal View History

2022-09-05 16:44:23 +03:00
{ pkgs ? import <nixpkgs> { } }:
let
# vim
customRC = ''
source ${./vimrc.vim}
2023-02-26 01:30:07 +03:00
if !empty($COC_NIL_PATH)
execute 'set rtp^=' . $COC_NIL_PATH
endif
2022-09-28 13:38:34 +03:00
autocmd BufRead,BufNewFile *.nix setf nix
2022-09-05 16:44:23 +03:00
let g:coc_node_path = '${pkgs.nodejs}/bin/node'
let g:coc_config_home = '${cocConfigHome}'
let g:coc_data_home = (empty($TMPDIR) ? '/tmp' : $TMPDIR) . '/coc-data'
2022-09-12 01:25:33 +03:00
let leader = '\\'
2022-09-05 16:44:23 +03:00
set updatetime=300
2022-11-24 16:52:00 +03:00
" Color encoding.
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
syntax on
2022-09-12 01:25:33 +03:00
function! LspStatus()
return coc#status()
endfunction
autocmd User CocStatusChange redrawstatus
" Semantic highlighting.
autocmd CursorHold * silent call CocActionAsync('highlight')
2022-09-05 16:44:23 +03:00
inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm() : "\<Tab>"
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <c-@> coc#refresh()
nmap <silent> [d <Plug>(coc-diagnostic-prev)
nmap <silent> ]d <Plug>(coc-diagnostic-next)
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
2022-11-24 16:52:00 +03:00
nmap <silent> gl <Plug>(coc-openlink)
2022-09-05 16:44:23 +03:00
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
nnoremap <silent> <Space><Space> <Cmd>call CocActionAsync('doHover')<CR>
nnoremap <silent> <Space>s <Cmd>call CocActionAsync('showSignatureHelp')<CR>
nmap <silent> <Leader>r <Plug>(coc-rename)
2022-11-24 16:52:00 +03:00
nmap <silent> <Leader>a <Plug>(coc-codeaction-cursor)
xmap <silent> <Leader>a <Plug>(coc-codeaction-selected)
nmap <silent> <Leader>qf <Plug>(coc-fix-current)
2022-09-12 01:25:33 +03:00
command -nargs=0 CocShowOutput CocCommand workspace.showOutput languageserver.nix
command -nargs=0 CocSemanticHighlightInfo call CocActionAsync('showSemanticHighlightInfo')
2022-11-09 19:44:23 +03:00
" Workaround: https://github.com/EdenEast/nightfox.nvim/issues/236
lua vim.treesitter = { highlighter = { hl_map = {} } }
2022-09-12 01:25:33 +03:00
packadd! nightfox.nvim
2022-10-24 04:01:04 +03:00
" https://github.com/EdenEast/nightfox.nvim/issues/218
lua <<EOF
require("nightfox").setup({
options = {
modules = {
2022-11-09 19:44:23 +03:00
treesitter = true,
2022-10-24 04:01:04 +03:00
},
},
})
EOF
2022-09-12 01:25:33 +03:00
colorscheme nightfox
highlight link Identifier TSVariable
highlight link CocSemPath Include
highlight link CocSemVariable TSVariable
2022-11-09 19:44:23 +03:00
highlight link CocSemParameter Identifier
2022-09-12 01:25:33 +03:00
highlight link CocSemPunctuation TSOperator
highlight link CocSemEscape TSStringEscape
highlight link CocSemUnresolved Error
highlight link CocSemWithAttribute Underlined
2022-09-12 01:25:33 +03:00
highlight link CocSemDelimiterPunctuation TSPunctDelimiter
highlight link CocSemConditionalKeyword Conditional
2023-02-04 03:38:09 +03:00
highlight link CocSemBuiltinVariable TSConstBuiltin
highlight link CocSemBuiltinFunction TSFuncBuiltin
highlight link CocSemBuiltin TSVariableBuiltin
2022-09-05 16:44:23 +03:00
'';
cocSetting = {
2023-02-26 01:30:07 +03:00
coc.preferences.formatOnSaveFiletypes = [ "nix" ];
links.tooltip = true;
2022-11-24 16:52:00 +03:00
semanticTokens.filetypes = [ "nix" ];
2023-02-26 01:30:07 +03:00
nil.server.path = pkgs.writeShellScript "nil" ''
exec "$NIL_PATH" "$@"
'';
nil.formatting.command = [ "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" ];
nil.diagnostics.excludedFiles = [ "generated.nix" ];
nil.nix.flake.autoEvalInputs = true;
2023-07-08 21:18:25 +03:00
nil.nix.maxMemoryMB = 2048;
2022-09-05 16:44:23 +03:00
};
cocConfigHome = pkgs.writeTextFile {
name = "coc-config";
destination = "/coc-settings.json";
text = builtins.toJSON cocSetting;
};
in
pkgs.vim_configurable.customize {
name = "vim-coc";
vimrcConfig = {
inherit customRC;
packages.myPlugins.start = with pkgs.vimPlugins; [
2022-11-24 16:52:00 +03:00
vim-nix # File type and syntax highlighting.
2022-09-05 16:44:23 +03:00
coc-nvim
2023-02-26 01:30:07 +03:00
coc-json
2022-12-01 03:07:07 +03:00
# FIXME
(nightfox-nvim.overrideAttrs (old: {
src = pkgs.fetchFromGitHub {
owner = "EdenEast";
repo = "nightfox.nvim";
rev = "15f3b5837a8d07f45cbe16753fbf13630bc167a3";
hash = "sha256-Uq+Rp4uoI+AUEUoSWXInB49bCldPz5f9KtinFMKF8iM=";
};
}))
2022-09-05 16:44:23 +03:00
];
};
}