forked from oxalica/nil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-coc.nix
129 lines (109 loc) · 4.03 KB
/
vim-coc.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ pkgs ? import <nixpkgs> { } }:
let
# vim
customRC = ''
source ${./vimrc.vim}
let $COC_NO_PLUGINS = 1
autocmd BufRead,BufNewFile *.nix setf nix
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'
let leader = '\\'
set updatetime=300
" Color encoding.
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
syntax on
" Semantic highlighting.
autocmd CursorHold * silent call CocActionAsync('highlight')
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)
nmap <silent> gl <Plug>(coc-openlink)
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)
nmap <silent> <Leader>a <Plug>(coc-codeaction-cursor)
xmap <silent> <Leader>a <Plug>(coc-codeaction-selected)
nmap <silent> <Leader>qf <Plug>(coc-fix-current)
command -nargs=0 CocShowOutput CocCommand workspace.showOutput languageserver.nix
command -nargs=0 CocSemanticHighlightInfo call CocActionAsync('showSemanticHighlightInfo')
" Workaround: https://github.com/EdenEast/nightfox.nvim/issues/236
lua vim.treesitter = { highlighter = { hl_map = {} } }
packadd! nightfox.nvim
" https://github.com/EdenEast/nightfox.nvim/issues/218
lua <<EOF
require("nightfox").setup({
options = {
modules = {
treesitter = true,
},
},
})
EOF
colorscheme nightfox
highlight link Identifier TSVariable
highlight link CocSemPath Include
highlight link CocSemVariable TSVariable
highlight link CocSemParameter Identifier
highlight link CocSemPunctuation TSOperator
highlight link CocSemEscape TSStringEscape
highlight link CocSemUnresolved Error
highlight link CocSemWithAttribute Underlined
highlight link CocSemDelimiterPunctuation TSPunctDelimiter
highlight link CocSemConditionalKeyword Conditional
highlight link CocSemBuiltinVariable TSConstBuiltin
highlight link CocSemBuiltinFunction TSFuncBuiltin
highlight link CocSemBuiltin TSVariableBuiltin
'';
cocSetting = {
"coc.preferences.formatOnSaveFiletypes" = [ "nix" ];
"links.tooltip" = true;
semanticTokens.filetypes = [ "nix" ];
languageserver.nix = {
command = pkgs.writeShellScript "nil" ''
exec "$NIL_PATH" "$@"
'';
filetypes = [ "nix" ];
rootPatterns = [ "flake.nix" ];
settings.nil = {
testSetting = 42;
formatting.command = [ "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" ];
diagnostics.excludedFiles = [ "generated.nix" ];
};
};
};
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; [
vim-nix # File type and syntax highlighting.
coc-nvim
# FIXME
(nightfox-nvim.overrideAttrs (old: {
src = pkgs.fetchFromGitHub {
owner = "EdenEast";
repo = "nightfox.nvim";
rev = "15f3b5837a8d07f45cbe16753fbf13630bc167a3";
hash = "sha256-Uq+Rp4uoI+AUEUoSWXInB49bCldPz5f9KtinFMKF8iM=";
};
}))
];
};
}