-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.lua
371 lines (343 loc) · 10.4 KB
/
plugins.lua
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
-- FILE: Plugins and their configs.
-- Plugin Loader
-- =============
local Plug = vim.fn['plug#']
vim.call('plug#begin', '~/.config/nvim/plugged')
-- Important
-- ---------
-- Plug 'editorconfig/editorconfig-vim' -- does not work.
-- Plug 'gpanders/editorconfig.nvim' -- is now built-in in nvim v0.9.0.
Plug 'lewis6991/gitsigns.nvim'
Plug 'nvim-lua/plenary.nvim' -- Many utils and dep of plugin:telescope.nvim.
Plug('nvim-telescope/telescope.nvim', { branch = '0.1.x' })
-- NOTE: Run `checkhealth telescope` regularly.
-- LSP
-- ---
Plug 'williamboman/mason.nvim' -- instead of nvim-lsp-installer.
Plug 'williamboman/mason-lspconfig.nvim' -- as bridge of mason.nvim and nvim-lspconfig.
Plug 'neovim/nvim-lspconfig' -- Wrapper of vim.lsp.* functions.
-- Auto-Completion
-- ---------------
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/nvim-cmp' -- for auto-completion. TODO: Need setup in details.
Plug 'hrsh7th/cmp-nvim-lsp-signature-help'
-- UI/UX
-- -----
local disable_devicons = os.getenv('DISABLE_DEVICONS')
if not (disable_devicons == 'true' or disable_devicons == '1') then
Plug 'nvim-tree/nvim-web-devicons'
end
Plug 'numToStr/Comment.nvim'
Plug 'windwp/nvim-autopairs'
Plug 'itchyny/lightline.vim' -- for status line.
Plug 'folke/which-key.nvim'
-- NOTE: Run `checkhealth which_key` regularly.
Plug('nvim-treesitter/nvim-treesitter') -- , { ['do'] = vim.cmd [[TSUpdate]] })
-- NOTE: Run `checkhealth nvim-treesitter` regularly.
Plug 'folke/todo-comments.nvim'
Plug 'nvim-telescope/telescope-file-browser.nvim'
-- Color Scheme
-- ------------
Plug 'navarasu/onedark.nvim' -- instead of 'joshdick/onedark.vim'
Plug 'lifepillar/vim-wwdc16-theme'
Plug 'morhetz/gruvbox'
vim.call('plug#end')
-- Plugin Configs
-- ==============
local function setup_gitsigns()
local ok, gitsigns = pcall(require, 'gitsigns')
if not ok then
print('<Plug>gitsigns not loaded.')
return -- early.
end
gitsigns.setup()
end
setup_gitsigns()
-- NOTE: Keymaps are set in setup_telescope_keymap()
local function setup_telescope()
local ok, telescope = pcall(require, 'telescope')
if not ok then
print('<Plug>telescope not loaded.')
return -- early.
end
telescope.setup({
defaults = {
mappings = {
i = {
['<C-i>'] = require('telescope.actions.layout').toggle_preview,
},
n = {
['<C-i>'] = require('telescope.actions.layout').toggle_preview,
},
},
sorting_strategy = 'ascending',
layout_strategy = 'flex',
layout_config = {
prompt_position = 'top',
horizontal = { preview_cutoff = 60, preview_width = 0.6 },
vertical = { preview_cutoff = 25, preview_height = 0.5 },
width = 0.9,
},
file_ignore_patterns = {
'.git/',
'node_modules/',
'vendor/bundle/',
'.bundle/bin/',
'plugged/',
},
},
pickers = {
find_files = {
find_command = vim.fn.executable('fd') == 1
and { "fd", "--type", "file" }
or nil,
hidden = true, -- to show hidden files.
},
current_buffer_fuzzy_find = {
sorting_strategy = 'ascending',
},
},
extensions = {
file_browser = {
display_stat = false, -- originally a table.
grouped = true,
hidden= { file_browser = true, folder_browser = true },
hijack_netrw = true,
respect_gitignore = false,
select_buffer = true,
},
},
})
end
setup_telescope()
local function setup_telescope_file_browser()
local tsOk, telescope = pcall(require, 'telescope')
if not tsOk then
print('<Plug>telescope-file-browser: Telescope not loaded.')
return
end
local ok, _ = pcall(require, 'telescope._extensions.file_browser')
if not ok then
print('<Plug>telescope-file-browser not loaded.')
return
end
telescope.load_extension('file_browser')
end
setup_telescope_file_browser()
local function setup_cmp()
local ok, cmp = pcall(require, 'cmp')
if not ok then
print('<Plug>cmp not loaded.')
return -- early.
end
-- vim.opt.completeopt={ 'menu', 'menuone', 'noselect' }
cmp.setup({
experimental = { ghost_text = true },
snippet = {
expand = function(args)
vim.fn['vsnip#anonymous'](args.body)
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.complete(), -- to invoke cmp menu.
['<CR>'] = cmp.mapping.confirm({ select = false }), --Recommended by nvim-cmp: <CR>.
['<C-e>'] = cmp.mapping.abort(), -- As default.
['<C-n>'] = cmp.mapping.select_next_item(), -- As default.
['<C-p>'] = cmp.mapping.select_prev_item(), -- As default.
-- TODO: <C-f> and <C-b> not working:
['<C-f>'] = cmp.mapping.scroll_docs(4), -- Recommended by nvim-cmp: <C-f>.
['<C-b>'] = cmp.mapping.scroll_docs(-4), -- Recommended by nvim-cmp: <C-b>.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp_signature_help' },
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
-- { name = 'path' },
}, {
{ name = 'buffer' },
}) -- depends on other <Plug>.
})
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
},
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' },
}, {
{ name = 'cmdline' },
}),
matching = { disallow_symbol_nonprefix_matching = false },
})
end
setup_cmp()
local function on_attach_lsp(client, bufnr)
vim.keymap.set('i', '<C-k>', vim.lsp.buf.signature_help, { buffer = bufnr, desc = '<LSP>SignHelp'})
vim.keymap.set('n', '<Leader>K', vim.lsp.buf.hover, { buffer = bufnr, desc = '<LSP>Hover doc' })
vim.keymap.set('n', '<Leader>lD', vim.lsp.buf.definition, { buffer = bufnr, desc = '<LSP>Go definition' })
vim.keymap.set('n', '<Leader>lI', vim.lsp.buf.implementation, { buffer = bufnr, desc = '<LSP>Go implementation' })
vim.keymap.set('n', '<Leader>lT', vim.lsp.buf.type_definition, { buffer = bufnr, desc = '<LSP>Go type-definition' })
vim.keymap.set('n', '<Leader>ls', vim.lsp.buf.rename, { buffer = bufnr, desc = '<LSP>Rename symbol' })
vim.keymap.set('n', '<Leader>la', vim.lsp.buf.code_action, { buffer = bufnr, desc = '<LSP>Code action' })
vim.keymap.set('n', '<Leader>lr', '<cmd>Telescope lsp_references<CR>', { desc = '<Tel>References...' })
end
local function setup_lsp(on_attach_fn)
local ok, mason, lspconfig, mason_lspconfig, cmp_nvim_lsp
ok, mason = pcall(require, 'mason')
if not ok then
print('<Plug>mason not loaded.')
return -- early.
end
ok, lspconfig = pcall(require, 'lspconfig')
if not ok then
print('<Plug>lspconfig not loaded.')
return -- early.
end
ok, mason_lspconfig = pcall(require, 'mason-lspconfig')
if not ok then
print('<Plug>mason-lspconfig not loaded.')
return -- early.
end
ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp')
if not ok then
print('<Plug>cmp_nvim_lsp not loaded.')
return -- early.
end
local capabilities = cmp_nvim_lsp.default_capabilities()
-- TODO: Not sure this capabilities do:
local capabilities_vscode = vim.lsp.protocol.make_client_capabilities()
capabilities_vscode.textDocument.completion.completionItem.snippetSupport = true
-- NOTE: Have to setup in order of: mason, mason_lspconfig, lspconfig. Requires cmp-nvim-lsp to run properly.
mason.setup()
mason_lspconfig.setup({
ensure_installed = {
'gopls', 'lua_ls', 'bashls',
-- Coop with vscode-langservers-extracted via npm:
'html', 'cssls', 'jsonls', 'eslint',
-- For more web dev env:
'ts_ls', 'denols', 'svelte',
},
})
lspconfig.gopls.setup({
capabilities = capabilities,
on_attach = on_attach_fn,
})
lspconfig.lua_ls.setup({
capabilities = capabilities,
on_attach = on_attach_fn,
settings = {
Lua = { diagnostics = { globals = { 'vim' } } },
},
})
lspconfig.bashls.setup({
capabilities = capabilities,
on_attach = on_attach_fn,
})
-- Ref for html, cssls, jsonls and eslint: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
lspconfig.html.setup({
capabilities = capabilities_vscode,
on_attach = on_attach_fn,
})
lspconfig.cssls.setup({
capabilities = capabilities_vscode,
on_attach = on_attach_fn,
})
lspconfig.jsonls.setup({
capabilities = capabilities_vscode,
on_attach = on_attach_fn,
})
lspconfig.eslint.setup({
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
command = "EslintFixAll",
})
end,
})
lspconfig.ts_ls.setup({
capabilities = capabilities,
on_attach = on_attach_fn,
root_dir = lspconfig.util.root_pattern({ 'package.json', 'tsconfig.json', 'jsconfig.json' }),
})
lspconfig.denols.setup({
capabilities = capabilities,
on_attach = on_attach_fn,
root_dir = lspconfig.util.root_pattern({ 'deno.json', 'deno.jsonc' }),
})
lspconfig.svelte.setup({
capabilities = capabilities,
on_attach = on_attach_fn,
})
end
setup_lsp(on_attach_lsp)
local function setup_comment_plug()
local ok, comment_plug = pcall(require, 'Comment')
if not ok then
print('<Plug>Comment not loaded.')
end
comment_plug.setup({
ignore = '^$', -- to ignore empty lines.
})
end
setup_comment_plug()
local function setup_autopairs()
local ok, autopairs = pcall(require, 'nvim-autopairs')
if not ok then
print('<Plug>autopairs not loaded.')
end
autopairs.setup()
end
setup_autopairs()
local function setup_treesitter()
local ok, treesitter = pcall(require, 'nvim-treesitter.configs')
if not ok then
print('<Plug>treesitter not loaded.')
return -- early.
end
local configs = {
ensure_installed = {
'go', 'lua', 'vim', 'bash',
'html', 'css', 'javascript', 'jsdoc',
'typescript', 'tsx',
'svelte',
},
sync_install = true,
highlight = {
enable = true, -- as default.
-- disable = {}, -- List of lang(s) in case of any problem.
},
indent = {
enable = true,
disable = { 'yaml' }, -- List of lang(s) in case of any problem.
},
}
treesitter.setup(configs)
-- vim.cmd [[TSUpdate]] -- TODO: Vim:E492: Not an editor command: TSUpdate.
end
setup_treesitter()
local function setup_todo_comments()
local ok, todo_comments = pcall(require, 'todo-comments')
if not ok then
print('<Plug>todo-comments not loaded.')
return
end
todo_comments.setup({ highlight = { after = '' } }) -- '' or 'bg'.
end
setup_todo_comments()
-- Setup in other files:
-- <Plug>lightline : colorscheme.lua
-- <Plug>which-key : keymap.lua
-- <Plug>telescope keymap : keymap.lua
-- Color schemes : colorscheme.lua