forked from NormalNvim/NormalNvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-dev-core.lua
More file actions
510 lines (485 loc) · 17.5 KB
/
3-dev-core.lua
File metadata and controls
510 lines (485 loc) · 17.5 KB
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
-- Dev core
-- Things that are just there.
-- Sections:
-- ## TREE SITTER
-- -> nvim-treesitter [syntax highlight]
-- -> nvim-ts-autotag [treesitter understand html tags]
-- -> ts-comments.nvim [treesitter comments]
-- -> nvim-colorizer [hex colors]
-- ## LSP
-- -> nvim-java [java support]
-- -> mason-lspconfig [auto start lsp]
-- -> nvim-lspconfig [lsp configs]
-- -> mason.nvim [lsp package manager]
-- -> SchemaStore.nvim [mason extra schemas]
-- -> none-ls-autoload.nvim [mason package loader]
-- -> none-ls [lsp code formatting]
-- -> neodev [lsp for nvim lua api]
-- -> garbage-day [lsp garbage collector]
-- ## AUTO COMPLETION
-- -> nvim-cmp [auto completion engine]
-- -> cmp-nvim-buffer [auto completion buffer]
-- -> cmp-nvim-path [auto completion path]
-- -> cmp-nvim-lsp [auto completion lsp]
-- -> cmp-luasnip [auto completion snippets]
local utils = require("base.utils")
local utils_lsp = require("base.utils.lsp")
return {
-- TREE SITTER ---------------------------------------------------------
-- [syntax highlight] + [treesitter understand html tags] + [comments]
-- https://github.com/nvim-treesitter/nvim-treesitter
-- https://github.com/windwp/nvim-ts-autotag
-- https://github.com/windwp/nvim-treesitter-textobjects
{
"nvim-treesitter/nvim-treesitter",
dependencies = {
"windwp/nvim-ts-autotag",
"nvim-treesitter/nvim-treesitter-textobjects",
},
event = "User BaseDefered",
cmd = {
"TSBufDisable",
"TSBufEnable",
"TSBufToggle",
"TSDisable",
"TSEnable",
"TSToggle",
"TSInstall",
"TSInstallInfo",
"TSInstallSync",
"TSModuleInfo",
"TSUninstall",
"TSUpdate",
"TSUpdateSync",
},
build = ":TSUpdate",
init = function(plugin)
-- perf: make treesitter queries available at startup.
require("lazy.core.loader").add_to_rtp(plugin)
require("nvim-treesitter.query_predicates")
end,
opts = {
auto_install = false, -- Currently bugged. Use [:TSInstall all] and [:TSUpdate all]
autotag = { enable = true },
highlight = {
enable = true,
disable = function(_, bufnr)
local excluded_filetypes = {} -- disabled for bugged parsers
local is_disabled = vim.tbl_contains(
excluded_filetypes, vim.bo.filetype) or utils.is_big_file(bufnr)
return is_disabled
end,
},
matchup = {
enable = true,
enable_quotes = true,
disable = function(_, bufnr)
local excluded_filetypes = { "c" } -- disabled for slow parsers
local is_disabled = vim.tbl_contains(
excluded_filetypes, vim.bo.filetype) or utils.is_big_file(bufnr)
return is_disabled
end,
},
incremental_selection = { enable = true },
indent = { enable = true },
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["ak"] = { query = "@block.outer", desc = "around block" },
["ik"] = { query = "@block.inner", desc = "inside block" },
["ac"] = { query = "@class.outer", desc = "around class" },
["ic"] = { query = "@class.inner", desc = "inside class" },
["a?"] = { query = "@conditional.outer", desc = "around conditional" },
["i?"] = { query = "@conditional.inner", desc = "inside conditional" },
["af"] = { query = "@function.outer", desc = "around function " },
["if"] = { query = "@function.inner", desc = "inside function " },
["al"] = { query = "@loop.outer", desc = "around loop" },
["il"] = { query = "@loop.inner", desc = "inside loop" },
["aa"] = { query = "@parameter.outer", desc = "around argument" },
["ia"] = { query = "@parameter.inner", desc = "inside argument" },
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]k"] = { query = "@block.outer", desc = "Next block start" },
["]f"] = { query = "@function.outer", desc = "Next function start" },
["]a"] = { query = "@parameter.inner", desc = "Next parameter start" },
},
goto_next_end = {
["]K"] = { query = "@block.outer", desc = "Next block end" },
["]F"] = { query = "@function.outer", desc = "Next function end" },
["]A"] = { query = "@parameter.inner", desc = "Next parameter end" },
},
goto_previous_start = {
["[k"] = { query = "@block.outer", desc = "Previous block start" },
["[f"] = { query = "@function.outer", desc = "Previous function start" },
["[a"] = { query = "@parameter.inner", desc = "Previous parameter start" },
},
goto_previous_end = {
["[K"] = { query = "@block.outer", desc = "Previous block end" },
["[F"] = { query = "@function.outer", desc = "Previous function end" },
["[A"] = { query = "@parameter.inner", desc = "Previous parameter end" },
},
},
swap = {
enable = true,
swap_next = {
[">K"] = { query = "@block.outer", desc = "Swap next block" },
[">F"] = { query = "@function.outer", desc = "Swap next function" },
[">A"] = { query = "@parameter.inner", desc = "Swap next parameter" },
},
swap_previous = {
["<K"] = { query = "@block.outer", desc = "Swap previous block" },
["<F"] = { query = "@function.outer", desc = "Swap previous function" },
["<A"] = { query = "@parameter.inner", desc = "Swap previous parameter" },
},
},
},
},
},
-- ts-comments.nvim [treesitter comments]
-- https://github.com/folke/ts-comments.nvim
-- This plugin can be safely removed after nvim 0.11 is released.
{
"folke/ts-comments.nvim",
event = "User BaseFile",
enabled = vim.fn.has("nvim-0.10.0") == 1,
opts = {},
},
-- [hex colors]
-- https://github.com/NvChad/nvim-colorizer.lua
{
"NvChad/nvim-colorizer.lua",
event = "User BaseFile",
cmd = {
"ColorizerToggle",
"ColorizerAttachToBuffer",
"ColorizerDetachFromBuffer",
"ColorizerReloadAllBuffers",
},
opts = { user_default_options = { names = false } },
},
-- LSP -------------------------------------------------------------------
-- nvim-java [java support]
-- https://github.com/nvim-java/nvim-java
-- Reliable jdtls support. Must go before mason-lspconfig and lsp-config.
{
"nvim-java/nvim-java",
ft = { "java" },
dependencies = {
"nvim-java/lua-async-await",
'nvim-java/nvim-java-refactor',
"nvim-java/nvim-java-core",
"nvim-java/nvim-java-test",
"nvim-java/nvim-java-dap",
"MunifTanjim/nui.nvim",
"neovim/nvim-lspconfig",
"mfussenegger/nvim-dap",
"williamboman/mason.nvim",
},
opts = {
notifications = {
dap = false,
},
-- NOTE: One of these files must be in your project root directory.
-- Otherwise the debugger will end in the wrong directory and fail.
root_markers = {
'settings.gradle',
'settings.gradle.kts',
'pom.xml',
'build.gradle',
'mvnw',
'gradlew',
'build.gradle',
'build.gradle.kts',
'.git',
},
},
},
-- nvim-lspconfig [lsp configs]
-- https://github.com/neovim/nvim-lspconfig
-- This plugin provide default configs for the lsp servers available on mason.
{
"neovim/nvim-lspconfig",
event = "User BaseFile",
dependencies = "nvim-java/nvim-java",
},
-- mason-lspconfig [auto start lsp]
-- https://github.com/williamboman/mason-lspconfig.nvim
-- This plugin auto starts the lsp servers installed by Mason
-- every time Neovim trigger the event FileType.
{
"williamboman/mason-lspconfig.nvim",
dependencies = { "neovim/nvim-lspconfig" },
event = "User BaseFile",
opts = function(_, opts)
if not opts.handlers then opts.handlers = {} end
opts.handlers[1] = function(server) utils_lsp.setup(server) end
end,
config = function(_, opts)
require("mason-lspconfig").setup(opts)
utils_lsp.apply_default_lsp_settings() -- Apply our default lsp settings.
utils.trigger_event("FileType") -- This line starts this plugin.
end,
},
-- mason [lsp package manager]
-- https://github.com/williamboman/mason.nvim
-- https://github.com/zeioth/mason-extra-cmds
{
"williamboman/mason.nvim",
dependencies = { "zeioth/mason-extra-cmds", opts = {} },
cmd = {
"Mason",
"MasonInstall",
"MasonUninstall",
"MasonUninstallAll",
"MasonLog",
"MasonUpdate",
"MasonUpdateAll", -- this cmd is provided by mason-extra-cmds
},
opts = {
registries = {
"github:nvim-java/mason-registry",
"github:mason-org/mason-registry",
},
ui = {
icons = {
package_installed = "✓",
package_uninstalled = "✗",
package_pending = "⟳",
},
},
}
},
-- Schema Store [mason extra schemas]
-- https://github.com/b0o/SchemaStore.nvim
"b0o/SchemaStore.nvim",
-- none-ls-autoload.nvim [mason package loader]
-- https://github.com/zeioth/mason-none-ls.nvim
-- This plugin auto starts the packages installed by Mason
-- every time Neovim trigger the event FileType ().
-- By default it will use none-ls builtin sources.
-- But you can add external sources if a mason package has no builtin support.
{
"zeioth/none-ls-autoload.nvim",
event = "User BaseFile",
dependencies = {
"williamboman/mason.nvim",
"zeioth/none-ls-external-sources.nvim"
},
opts = {
-- Here you can add support for sources not oficially suppored by none-ls.
external_sources = {
-- diagnostics
'none-ls-external-sources.diagnostics.cpplint',
'none-ls-external-sources.diagnostics.eslint',
'none-ls-external-sources.diagnostics.eslint_d',
'none-ls-external-sources.diagnostics.flake8',
'none-ls-external-sources.diagnostics.luacheck',
'none-ls-external-sources.diagnostics.psalm',
'none-ls-external-sources.diagnostics.shellcheck',
'none-ls-external-sources.diagnostics.yamllint',
-- formatting
'none-ls-external-sources.formatting.autopep8',
'none-ls-external-sources.formatting.beautysh',
'none-ls-external-sources.formatting.easy-coding-standard',
'none-ls-external-sources.formatting.eslint',
'none-ls-external-sources.formatting.eslint_d',
'none-ls-external-sources.formatting.jq',
'none-ls-external-sources.formatting.latexindent',
'none-ls-external-sources.formatting.reformat_gherkin',
'none-ls-external-sources.formatting.rustfmt',
'none-ls-external-sources.formatting.standardrb',
'none-ls-external-sources.formatting.yq',
},
},
},
-- none-ls [lsp code formatting]
-- https://github.com/nvimtools/none-ls.nvim
{
"nvimtools/none-ls.nvim",
event = "User BaseFile",
opts = function()
local builtin_sources = require("null-ls").builtins
-- You can customize your 'builtin sources' and 'external sources' here.
builtin_sources.formatting.shfmt.with({
command = "shfmt",
args = { "-i", "2", "-filename", "$FILENAME" },
})
-- Attach the user lsp mappings to every none-ls client.
return { on_attach = utils_lsp.apply_user_lsp_mappings }
end
},
-- neodev.nvim [lsp for nvim lua api]
-- https://github.com/folke/neodev.nvim
{
"folke/neodev.nvim",
ft = { "lua" },
opts = {}
},
-- garbage-day.nvim [lsp garbage collector]
-- https://github.com/zeioth/garbage-day.nvim
{
"zeioth/garbage-day.nvim",
event = "User BaseFile",
opts = {
aggressive_mode = false,
excluded_lsp_clients = {
"null-ls", "jdtls", "marksman"
},
grace_period = (60 * 15),
wakeup_delay = 3000,
notifications = false,
retries = 3,
timeout = 1000,
}
},
-- AUTO COMPLETION --------------------------------------------------------
-- Auto completion engine [autocompletion engine]
-- https://github.com/hrsh7th/nvim-cmp
{
"hrsh7th/nvim-cmp",
dependencies = {
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-nvim-lsp"
},
event = "InsertEnter",
opts = function()
-- ensure dependencies exist
local cmp = require("cmp")
local luasnip = require("luasnip")
local lspkind = require("lspkind")
-- border opts
local border_opts = {
border = "rounded",
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None",
}
-- helper
local function has_words_before()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
end
return {
enabled = function() -- disable in certain cases on dap.
local is_prompt = vim.bo.buftype == "prompt"
local is_dap_prompt = utils.is_available("cmp-dap")
and vim.tbl_contains(
{ "dap-repl", "dapui_watches", "dapui_hover" }, vim.bo.filetype)
if is_prompt and not is_dap_prompt then
return false
else
return vim.g.cmp_enabled
end
end,
preselect = cmp.PreselectMode.None,
formatting = {
fields = { "kind", "abbr", "menu" },
format = lspkind.cmp_format(utils.get_plugin_opts("lspkind.nvim")),
},
snippet = {
expand = function(args) luasnip.lsp_expand(args.body) end,
},
duplicates = {
nvim_lsp = 1,
luasnip = 1,
cmp_tabnine = 1,
buffer = 1,
path = 1,
},
confirm_opts = {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
completion = cmp.config.window.bordered(border_opts),
documentation = cmp.config.window.bordered(border_opts),
},
mapping = {
["<PageUp>"] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Select,
count = 8,
},
["<PageDown>"] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Select,
count = 8,
},
["<C-PageUp>"] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Select,
count = 16,
},
["<C-PageDown>"] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Select,
count = 16,
},
["<S-PageUp>"] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Select,
count = 16,
},
["<S-PageDown>"] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Select,
count = 16,
},
["<Up>"] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Select,
},
["<Down>"] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Select,
},
["<C-p>"] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Insert,
},
["<C-n>"] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Insert,
},
["<C-k>"] = cmp.mapping.select_prev_item {
behavior = cmp.SelectBehavior.Insert,
},
["<C-j>"] = cmp.mapping.select_next_item {
behavior = cmp.SelectBehavior.Insert,
},
["<C-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = cmp.config.disable,
["<C-e>"] = cmp.mapping {
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
},
["<CR>"] = cmp.mapping.confirm { select = false },
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources {
{ name = "nvim_lsp", priority = 1000 },
{ name = "luasnip", priority = 750 },
{ name = "buffer", priority = 500 },
{ name = "path", priority = 250 },
},
}
end,
},
}