-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.nvimrc.lua
4946 lines (4593 loc) · 160 KB
/
.nvimrc.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
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- | \ | | ___ __\ \ / /_ _| \/ | | | | | | | / \
-- | \| |/ _ \/ _ \ \ / / | || |\/| | | | | | | |/ _ \
-- | |\ | __/ (_) \ V / | || | | | _ | |__| |_| / ___ \
-- |_| \_|\___|\___/ \_/ |___|_| |_| (_) |_____\___/_/ \_\
--------------------------------------------------------------------------------------
local use_nix = true
local lazypath
if vim.fn.isdirectory(vim.fn.stdpath("data") .. "/nix") and use_nix then
lazypath = vim.fn.stdpath("data") .. "/nix/lazy.nvim"
else
lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
end
local loop_or_uv = vim.loop or vim.uv
if not loop_or_uv.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--branch=stable", -- remove this if you want to bootstrap to HEAD
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local kind_icons_list = {
Array = ' ',
Boolean = ' ',
BreakStatement = ' ',
Call = ' ',
CaseStatement = ' ',
Class = ' ',
Color = ' ',
Constant = ' ',
Constructor = ' ',
ContinueStatement = '→ ',
Copilot = ' ',
Declaration = ' ',
Delete = ' ',
DoStatement = ' ',
Enum = ' ',
EnumMember = ' ',
Event = ' ',
Field = ' ',
File = ' ',
Folder = ' ',
ForStatement = ' ',
Function = ' ',
Identifier = ' ',
IfStatement = ' ',
Interface = ' ',
Keyword = ' ',
List = ' ',
Log = ' ',
Lsp = ' ',
Macro = ' ',
MarkdownH1 = ' ',
MarkdownH2 = ' ',
MarkdownH3 = ' ',
MarkdownH4 = ' ',
MarkdownH5 = ' ',
MarkdownH6 = ' ',
Method = ' ',
Module = ' ',
Namespace = ' ',
Null = ' ',
Number = ' ',
Object = ' ',
Operator = ' ',
Package = ' ',
Property = ' ',
Reference = ' ',
Regex = ' ',
Repeat = ' ',
Scope = ' ',
Snippet = ' ',
Specifier = ' ',
Statement = ' ',
String = ' ',
Struct = ' ',
SwitchStatement = ' ',
Text = ' ',
Type = ' ',
TypeParameter = ' ',
Unit = ' ',
Value = ' ',
Variable = ' ',
WhileStatement = ' ',
Key = " ",
}
local kind_icons = {
Text = ' ',
Method = ' ',
Function = ' ',
Constructor = ' ',
Field = ' ',
Variable = ' ',
Class = 'ﴯ ',
Interface = ' ',
Module = " ",
Property = 'ﰠ ',
Unit = ' ',
Value = ' ',
Enum = ' ',
Keyword = ' ',
Snippet = ' ',
Color = ' ',
File = ' ',
Reference = ' ',
Folder = ' ',
EnumMember = ' ',
Constant = ' ',
Struct = ' ',
Event = ' ',
Operator = ' ',
TypeParameter = " ",
TabNine = ' ',
String = " ",
Namespace = " ",
Number = " ",
Package = " ",
Boolean = "◩ ",
Array = " ",
Object = " ",
Key = " ",
Null = "ﳠ ",
}
-- git navigations by vscode-neovim
local function vscode_next_hunk()
require("vscode-neovim").action("workbench.action.editor.nextChange")
end
local function vscode_prev_hunk()
require("vscode-neovim").action("workbench.action.editor.previousChange")
end
local function lsp_merge_project_config(config)
if vim.g.project_config then
return vim.tbl_deep_extend('keep', config, vim.g.project_config)
end
return config
end
local plugins = {
{'folke/lazy.nvim', lazy = false},
{
'nvim-lua/plenary.nvim',
cmd = {
"PlenaryProfile",
"PlenaryProfileStop",
},
config = function()
vim.api.nvim_create_user_command("PlenaryProfile", function() require'plenary.profile'.start("profile.log", {flame = true}) end, { nargs = 0 })
vim.api.nvim_create_user_command("PlenaryProfileStop", function() require'plenary.profile'.stop() end, { nargs = 0 })
end
},
{
'nvim-telescope/telescope.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-telescope/telescope-fzf-native.nvim',
'jonarrien/telescope-cmdline.nvim',
'tom-anders/telescope-vim-bookmarks.nvim',
},
keys = {
"<leader>f",
"<leader>b",
"<leader>gs",
"<leader>gg",
"<leader>t",
},
cond = vim.g.vscode == nil,
config = function()
local action_set = require "telescope.actions.set"
local function move_selection_next_5(prompt_bufnr)
action_set.shift_selection(prompt_bufnr, 5)
end
local function move_selection_previous_5(prompt_bufnr)
action_set.shift_selection(prompt_bufnr, -5)
end
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local function move_left_7()
return vim.api.nvim_feedkeys(t "7h", "n", true)
end
local function move_right_7()
return vim.api.nvim_feedkeys(t "7l", "n", true)
end
local status_ok, trouble_telscope = pcall(require, "trouble.sources.telescope")
local opts = {
defaults = {
mappings = {
i = {
["<C-j>"] = "move_selection_next",
["<C-k>"] = "move_selection_previous",
},
n = {
["K"] = move_selection_previous_5,
["J"] = move_selection_next_5,
["H"] = move_left_7,
["L"] = move_right_7,
["q"] = require("telescope.actions").close,
},
}
}
}
if status_ok then
opts.defaults.mappings.i["<C-t>"] = trouble_telscope.open
opts.defaults.mappings.n["<C-t>"] = trouble_telscope.open
end
require('telescope').setup(opts)
local function telescope_grep_string_visual()
local saved_reg = vim.fn.getreg "v"
vim.cmd [[noautocmd sil norm "vy]]
local sele = vim.fn.getreg "v"
vim.fn.setreg("v", saved_reg)
require('telescope.builtin').grep_string({ search = sele })
end
-- lazy load telescope
local telescope_buildin = require('telescope.builtin')
vim.keymap.set('n', '<leader>f', telescope_buildin.find_files, { silent = true })
vim.keymap.set('n', '<leader>F', function() telescope_buildin.find_files{no_ignore=true} end, { silent = true })
vim.keymap.set('n', '<leader>b', '<cmd>Telescope buffers<cr>', { silent = true })
vim.keymap.set('n', '<leader>gs', '<cmd>Telescope grep_string <cr>', { silent = true })
vim.keymap.set('v', '<leader>gs', telescope_grep_string_visual, { silent = true })
vim.keymap.set('n', '<leader>gg', telescope_buildin.live_grep, { silent = true })
vim.keymap.set('n', '<leader>t', '<cmd>Telescope builtin include_extensions=true <cr>', { silent = true })
vim.keymap.set('n', '<leader>rc', '<cmd>Telescope command_history <cr>', { silent = true })
vim.keymap.set('n', '<leader>rf', '<cmd>Telescope lsp_document_symbols<cr>', { silent = true })
vim.keymap.set('n', '<leader>rw', '<cmd>Telescope lsp_dynamic_workspace_symbols<cr>', { silent = true })
vim.keymap.set('n', '<leader>rl', '<cmd>Telescope current_buffer_fuzzy_find fuzzy=false <cr>', { silent = true })
end
},
{'seandewar/sigsegvim', cmd = "Sigsegv"},
{"Eandrju/cellular-automaton.nvim", cmd = "CellularAutomaton"},
{
'nvim-telescope/telescope-live-grep-args.nvim',
lazy = true,
keys = "<leader>gG",
config = function()
vim.keymap.set('n', '<leader>gG', require('telescope').extensions.live_grep_args.live_grep_args, { silent = true })
end
},
{
'kevinhwang91/nvim-bqf',
config = function()
vim.cmd [[
hi BqfPreviewBorder guifg=#50a14f ctermfg=71
hi link BqfPreviewRange Search
]]
require('bqf').setup({
auto_enable = true,
auto_resize_height = false,
preview = {
win_height = 999, -- full screen
win_vheight = 12,
delay_syntax = 80,
border_chars = {'┃', '┃', '━', '━', '┏', '┓', '┗', '┛', '█'},
should_preview_cb = function(bufnr, qwinid)
local ret = true
local bufname = vim.api.nvim_buf_get_name(bufnr)
local fsize = vim.fn.getfsize(bufname)
if fsize > 100 * 1024 then
-- skip file size greater than 100k
ret = false
elseif bufname:match('^fugitive://') then
-- skip fugitive buffer
ret = false
end
return ret
end
},
-- make `drop` and `tab drop` to become preferred
func_map = {
drop = 'o',
openc = 'O',
split = '<C-s>',
tabdrop = '<C-t>',
tabc = '',
ptogglemode = 'z,',
},
filter = {
fzf = {
action_for = {['ctrl-s'] = 'split', ['ctrl-t'] = 'tab drop'},
extra_opts = {'--bind', 'ctrl-o:toggle-all', '--prompt', '> '}
}
}
})
end
}, -- better quick fix
{
'kevinhwang91/nvim-hlslens',
lazy = true,
config = function()
local kopts = {silent = true}
vim.keymap.set('n', 'n',
[[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]],
kopts)
vim.keymap.set('n', 'N',
[[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]],
kopts)
vim.keymap.set('n', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('n', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('n', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('n', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('x', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('x', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('x', 'g*', [[g*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.keymap.set('x', 'g#', [[g#<Cmd>lua require('hlslens').start()<CR>]], kopts)
require'hlslens'.setup {
calm_down = false,
nearest_only = true,
nearest_float_when = 'auto',
build_position_cb = function(plist, _, _, _)
require("scrollbar.handlers.search").handler.show(plist.start_pos)
end,
}
end
},
{
"williamboman/mason.nvim",
lazy = true,
cmd = "Mason",
init = function()
vim.fn.setenv("PATH", vim.fn.getenv("PATH") .. ":" .. vim.fn.stdpath("data") .. "/mason/bin")
end,
config = function()
require("mason").setup()
end
},
{
'mfussenegger/nvim-jdtls',
dependencies = 'nvim-lspconfig',
config = function()
-- java
local jdt_config = get_lsp_common_config()
local java_exec
if vim.fn.filereadable('/run/current-system/sw/bin/java') then
java_exec = '/run/current-system/sw/bin/java'
else
java_exec = 'java'
end
jdt_config.cmd = {
vim.fn.stdpath('data') .. "/mason/bin/jdtls",
"--java-executable=" .. java_exec,
}
-- 💀
-- This is the default if not provided, you can remove it. Or adjust as needed.
-- One dedicated LSP server & client will be started per unique root_dir
jdt_config.root_dir = vim.fs.root(0, {".git", "mvnw", "gradlew", ".classpath", ".exrc"})
-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- for a list of options
jdt_config.settings = {
java = {
completion = {
overwrite = true,
guessMethodArguments = true,
},
selectionRange = {
enabled = true,
},
inlayHints = {
parameterNames = {
enabled = "all"
}
},
implementationsCodeLens = true,
referencesCodeLens = true,
}
}
jdt_config.name = "jdtls"
-- progress_report
jdt_config.handlers = {
-- disable default progress report
['language/status'] = function() end,
}
-- Language server `initializationOptions`
-- You need to extend the `bundles` with paths to jar files
-- if you want to use additional eclipse.jdt.ls plugins.
--
-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
--
-- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
local bundles = {
vim.fn.glob(vim.fn.stdpath('data') .. "/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin-*.jar")
}
vim.list_extend(bundles, vim.split(vim.fn.glob(
vim.fn.stdpath('data') .. "/mason/packages/java-test/extension/server/*.jar"), "\n"))
jdt_config.init_options = {
bundles = bundles,
}
vim.api.nvim_create_user_command("JdtDebugTestClass", "lua require('jdtls').test_class()", { nargs = 0 })
vim.api.nvim_create_user_command("JdtDebugTestMethod", "lua require('jdtls').test_nearest_method()", { nargs = 0 })
jdt_config.on_attach = function(client, bufnr)
-- With `hotcodereplace = 'auto' the debug adapter will try to apply code changes
-- you make during a debug session immediately.
-- Remove the option if you do not want that.
require('jdtls').setup_dap({ hotcodereplace = 'auto' })
common_on_attach(client, bufnr)
require('jdtls.dap').setup_dap_main_class_configs()
end
local jdt_config = lsp_merge_project_config(jdt_config)
-- jdtls needs to be started by FileType, and executed every time for each java file
vim.api.nvim_create_autocmd("FileType", {
pattern = "java",
callback = function()
require('jdtls').start_or_attach(jdt_config)
end,
})
end
},
{
"mrcjkb/rustaceanvim",
dependencies = 'nvim-lspconfig',
config = function()
vim.g.rustaceanvim = function()
local extension_path = vim.fn.stdpath('data') .. '/mason/'
local codelldb_path = extension_path .. 'bin/codelldb'
local liblldb_path = extension_path .. 'packages/codelldb/extension/lldb/lib/liblldb.so'
local lsp_config = get_lsp_common_config()
lsp_config.capabilities.offsetEncoding = nil
local cfg = require('rustaceanvim.config')
return {
server = lsp_merge_project_config(lsp_config),
dap = {
adapter = cfg.get_codelldb_adapter(codelldb_path, liblldb_path),
},
}
end
vim.api.nvim_buf_create_user_command(0, "RustLspExpandMacro", function() vim.cmd.RustLsp('expandMacro') end, {})
end
},
{
'p00f/clangd_extensions.nvim',
dependencies = 'nvim-lspconfig',
},
{
'neovim/nvim-lspconfig',
config = function()
-- vim.lsp.set_log_level('DEBUG')
vim.lsp.set_log_level('OFF')
local lspconfig = require('lspconfig')
function common_on_attach(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- codelens
vim.api.nvim_create_autocmd({"InsertLeave", "TextChanged", "BufEnter"}, {
pattern = "*",
callback = function()
vim.lsp.codelens.refresh()
end
})
-- refresh on start
vim.lsp.codelens.refresh()
-- rust_analyzer needs to be defered refresh
if client.name == "rust_analyzer" then
vim.defer_fn(function()
vim.lsp.codelens.refresh()
end, 500)
end
-- inlay hints
vim.lsp.inlay_hint.enable()
end
local function showDocument()
local clients = vim.lsp.get_clients()
if next(clients) ~= nil then
vim.lsp.buf.hover()
elseif vim.o.filetype == "help" or vim.o.filetype == "vim" or vim.o.filetype == "lua" then
vim.cmd("execute 'h '.expand('<cword>')")
else
vim.cmd("execute '!' . &keywordprg . ' ' . expand('<cword>')")
end
end
local opts = { noremap=true, silent=true }
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
-- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'gd', '<cmd>Trouble lsp_definitions<CR>', opts)
-- vim.keymap.set('n', '<leader>d', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.keymap.set('n', 'gr', '<cmd>Trouble lsp_references<CR>', opts)
vim.keymap.set('n', 'gi', '<cmd>Trouble lsp_implementations<cr>', opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>aa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>ar', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>al', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.keymap.set('n', '<space>D', '<cmd>Trouble lsp_type_definitions<CR>', opts)
-- vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, opts)
vim.api.nvim_create_autocmd("FileType", {
pattern = {"c", "cpp"},
callback = function(args)
vim.keymap.set('n', 'gh', '<cmd>ClangdSwitchSourceHeader <CR>', { buffer = true, silent = true, noremap = true })
end
})
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
vim.diagnostic.config({
virtual_text = false,
virtual_lines = false,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = signs.Error,
[vim.diagnostic.severity.WARN] = signs.Warn,
[vim.diagnostic.severity.INFO] = signs.Info,
[vim.diagnostic.severity.HINT] = signs.Hint,
},
numhl = {
[vim.diagnostic.severity.ERROR] = "DiagnosticError",
[vim.diagnostic.severity.WARN] = "DiagnosticWarn",
[vim.diagnostic.severity.INFO] = "DiagnosticInfo",
[vim.diagnostic.severity.HINT] = "DiagnosticHint",
},
}
})
virtualLineEnabled = false
local function changeDiagnostic()
require("lsp_lines") -- lazy load lsp_lines
if virtualLineEnabled == false then
vim.diagnostic.config({
virtual_text = false,
virtual_lines = true
})
virtualLineEnabled = true
else
vim.diagnostic.config({
-- virtual_text = true,
virtual_lines = false
})
virtualLineEnabled = false
end
end
function get_lsp_common_config()
local capabilities = require('cmp_nvim_lsp').default_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
local config = {
on_attach = common_on_attach,
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
},
handlers = {
["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
signs = true,
underline = true,
update_in_insert = false,
}
),
}
}
return config
end
-- 'rust_analyzer' are handled by rustaceanvim.
local servers = {
'texlab', 'lua_ls', 'vimls', 'hls', 'ts_ls',
"cmake", "gopls", "bashls", "buf_ls", "ltex", "nil_ls",
'clangd',
}
-- add my magic python lsp
local ok, pycfg = pcall(require, 'dotfiles.private.magic_py_lsp')
if not ok or pycfg.config == nil then
servers[#servers+1] = 'pyright'
else
require('lspconfig.configs')[pycfg.name] = pycfg.config
servers[#servers+1] = pycfg.name
end
for _, lsp in ipairs(servers) do
local lsp_common_config = get_lsp_common_config()
if lsp == 'ts_ls' then
-- lsp_common_config.root_dir = require('lspconfig.util').root_pattern("*")
elseif lsp == "pyright" or lsp == pycfg.name then
lsp_common_config.settings = {
python = {
analysis = {
diagnosticSeverityOverrides = {
-- reportGeneralTypeIssues = "warning"
},
}
}
}
elseif lsp == "clangd" then
lsp_common_config.cmd = { "clangd", "--header-insertion-decorators=0", "-header-insertion=never",
"--background-index" }
lsp_common_config.filetypes = { "c", "cpp", "objc", "objcpp", "cuda" }
-- set offset encoding
lsp_common_config.capabilities.offsetEncoding = 'utf-8'
elseif lsp == "texlab" then
lsp_common_config.on_attach = function(client, bufnr)
common_on_attach(client,bufnr)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<localleader>v', '<cmd>TexlabForward<cr>', { noremap=true, silent=true })
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<localleader>b', '<cmd>TexlabBuild<cr>', { noremap=true, silent=true })
end
lsp_common_config.settings = {
texlab = {
-- rootDirectory = vim.fn.getcwd(),
auxDirectory = "latex.out",
build = {
onSave = true, -- Automatically build latex on save
args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f", "-outdir=latex.out" },
-- args = { "-pdfxe", "-interaction=nonstopmode", "-synctex=1", "%f", "-outdir=latex.out" },
-- args = { "-pdflua", "-interaction=nonstopmode", "-synctex=1", "%f", "-outdir=latex.out" },
},
forwardSearch = {
executable = "zathura",
args = {
'--synctex-forward',
'%l:1:%f',
'%p',
},
},
},
chktex = {
onEdit = false,
onOpenAndSave = true
}
}
elseif lsp == "lua_ls" then
if string.find(vim.fn.expand('%'), '.nvimrc.lua', 1, true) then
-- lsp_common_config.autostart = false
end
lsp_common_config.settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = true,
},
codeLens = {
enable = true,
},
hint = {
enable = true,
},
},
}
elseif lsp == "gopls" then
lsp_common_config.settings = {
gopls = {
semanticTokens = true,
usePlaceholders = true,
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
}
}
}
lsp_common_config.on_attach = function(client, bufnr)
common_on_attach(client,bufnr)
local semantic = client.config.capabilities.textDocument.semanticTokens
client.server_capabilities.semanticTokensProvider = {
full = true,
legend = {tokenModifiers = semantic.tokenModifiers, tokenTypes = semantic.tokenTypes},
range = true,
}
end
elseif lsp == "grammarly" then
lsp_common_config.filetypes = { "markdown", "tex" }
lsp_common_config.cmd = (function()
if vim.fn.isdirectory(os.getenv("HOME") .. "/grammarly") == 1 then
return {os.getenv("HOME") .. "/grammarly/packages/grammarly-languageserver/bin/server.js", "--stdio"}
else
return {"grammarly-languageserver", "--stdio"}
end
end)()
lsp_common_config.init_options = {
clientId = "client_BaDkMgx4X19X9UxxYRCXZo"
}
lsp_common_config.settings = {
grammarly = {
config = {
suggestions = {
MissingSpaces = false
}
}
}
}
elseif lsp == "ltex" then
lsp_common_config.settings = {
ltex = {
language = "en-US",
}
}
elseif lsp == "nil_ls" then
lsp_common_config.settings = {
['nil'] = {
formatting = {
command = { "nixpkgs-fmt" }
},
nix = {
maxMemoryMB = math.floor((vim.uv.get_free_memory() * 0.9) / math.pow(2, 20)),
flake = {
autoArchive = false,
autoEvalInputs = true,
nixpkgsInputName = "nixpkgs",
}
}
}
}
end
lspconfig[lsp].setup(lsp_merge_project_config(lsp_common_config))
end
vim.keymap.set('n', '<space>e', changeDiagnostic, opts)
-- vim.keymap.set('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.keymap.set('n', '[d', function() vim.diagnostic.jump({ count = -1, float = true }) end, opts)
vim.keymap.set('n', ']d', function() vim.diagnostic.jump({ count = 1, float = true }) end, opts)
vim.keymap.set('n', '<space>Q', '<cmd>Trouble diagnostics toggle filter.buf=0<CR>', opts)
vim.keymap.set('n', '<space>q', '<cmd>Trouble diagnostics toggle<CR>', opts)
vim.keymap.set('n', '<leader>d', showDocument, opts)
-- vim.cmd [[au CursorHold <buffer> lua vim.diagnostic.open_float()]]
-- UI Customization
-- To instead override globally
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
opts.border = "rounded"
return orig_util_open_floating_preview(contents, syntax, opts, ...)
end
-- code len
vim.keymap.set('n', '<leader>cl', '<cmd>lua vim.lsp.codelens.run()<CR>', opts)
vim.cmd [[hi! link LspCodeLens specialkey]]
-- format code
local function formatBuf()
local modes = {"i", "s"}
local mode = vim.fn.mode()
for _,v in pairs(modes) do
if mode == v then
return
end
end
vim.lsp.buf.format{ async = true }
end
local function formatToggleHandler()
if vim.g.format_on_save == 1 then
vim.defer_fn(formatBuf, 1000)
end
end
local function formatToggle()
if not vim.g.format_on_save or vim.g.format_on_save == 0 then
vim.g.format_on_save = 1
vim.notify("Format On Save: ON")
elseif vim.g.format_on_save == 1 then
vim.g.format_on_save = 0
vim.notify("Format On Save: OFF")
end
end
-- defer 1000 ms for formatters
-- vim.cmd[[ au BufWritePost <buffer> silent lua vim.defer_fn(formatBuf, 1000) ]]
vim.api.nvim_create_autocmd({"BufWritePost"}, {
pattern = "*",
callback = formatToggleHandler,
})
vim.api.nvim_create_user_command("AFToggle", formatToggle, { nargs = 0 })
vim.keymap.set({"n", "v"}, "<leader>af", formatBuf, { silent = true })
end
},
{
"luukvbaal/statuscol.nvim",
branch = "0.10",
cond = vim.g.vscode == nil,
config = function()
local builtin = require("statuscol.builtin")
vim.o.numberwidth = vim.o.numberwidth + 2 -- fix numberwidth mismatch
require("statuscol").setup({
-- Builtin line number string options for ScLn() segment
thousands = false, -- or line number thousands separator string ("." / ",")
relculright = true, -- whether to right-align the cursor line number with 'relativenumber' set
bt_ignore = {"nofile"},
-- Builtin 'statuscolumn' options
setopt = true, -- whether to set the 'statuscolumn', providing builtin click actions
-- Default segments (fold -> sign -> line number + separator)
segments = {
{
sign = { name = { ".*" }, namespace = { ".*" }, maxwidth = 1, colwidth = 2},
click = "v:lua.ScSa"
},
{
text = { builtin.lnumfunc },
condition = { true, builtin.not_empty },
click = "v:lua.ScLa",
},
{
sign = { namespace = {"gitsigns"}, maxwidth = 1, colwidth = 1, auto = false },
click = "v:lua.ScSa",
},
{ text = { builtin.foldfunc }, click = "v:lua.ScFa" },
},
ft_ignore = {
"toggleterm",
"dapui_scopes",
"dapui_breakpoints",
"dapui_stacks",
"dapui_watches",
"dap-repl"
}, -- lua table with filetypes for which 'statuscolumn' will be unset
-- Click actions
clickhandlers = {
Lnum = builtin.lnum_click,
FoldClose = builtin.foldclose_click,
FoldOpen = builtin.foldopen_click,
FoldOther = builtin.foldother_click,
DapBreakpointRejected = builtin.toggle_breakpoint,
DapBreakpoint = builtin.toggle_breakpoint,
DapBreakpointCondition = builtin.toggle_breakpoint,
DiagnosticSignError = builtin.diagnostic_click,
DiagnosticSignHint = builtin.diagnostic_click,
DiagnosticSignInfo = builtin.diagnostic_click,
DiagnosticSignWarn = builtin.diagnostic_click,
GitSignsTopdelete = builtin.gitsigns_click,
GitSignsUntracked = builtin.gitsigns_click,
GitSignsAdd = builtin.gitsigns_click,
GitSignsChangedelete = builtin.gitsigns_click,
GitSignsDelete = builtin.gitsigns_click,
gitsigns_extmark_signs_ = builtin.gitsigns_click,
}
})
end
},
{
-- for code actions
'kosayoda/nvim-lightbulb',
config = function()
local lightbulb = require('nvim-lightbulb')
lightbulb.setup {
autocmd = {
enabled = true
},
sign = {
enabled = true,
-- Text to show in the sign column.
-- Must be between 1-2 characters.
text = "💡",
-- Highlight group to highlight the sign column text.
hl = "LightBulbSign",
},
ignore = {
clients = {"null-ls"}
},
}
end
},
{
'j-hui/fidget.nvim',
branch = "legacy",
config = function()
local opts = {
sources = {
["null-ls"] = {
ignore = true
},
["lua_ls"] = {
ignore = true
}
},
fmt = {
max_messages = 5,
}
}
require"fidget".setup(opts)
end
},
{'kyazdani42/nvim-web-devicons'},
{
'windwp/nvim-autopairs',
event = "InsertEnter",
cond = vim.g.vscode == nil,
opts = {}
},
{
"okuuva/auto-save.nvim",
event = {"InsertLeave", "TextChanged", "WinLeave", "BufLeave"},
cond = vim.g.vscode == nil,
opts = {
trigger_events = { -- See :h events
immediate_save = { "BufLeave", "FocusLost", "VimLeave" }, -- vim events that trigger an immediate save
defer_save = { "InsertLeave", "TextChanged" }, -- vim events that trigger a deferred save (saves after `debounce_delay`)
cancel_deferred_save = { "InsertEnter" }, -- vim events that cancel a pending deferred save
},
}
},
{
-- can be used as formatter
"nvimtools/none-ls.nvim",
depedencies = {
"nvimtools/none-ls-extras.nvim",
},
config = function()
local null_ls = require("null-ls")
local eslint = require('none-ls.diagnostics.eslint')
local autopep8 = require('none-ls.formatting.autopep8')
local isort_always_enabled = true
null_ls.setup({
sources = {
eslint,
-- null_ls.builtins.completion.spell,
null_ls.builtins.formatting.prettier,
null_ls.builtins.completion.tags,
null_ls.builtins.code_actions.gitsigns,
-- python
autopep8.with({
runtime_condition = function(params)
if params.options.isort == true then
return false
else
return true
end
end
}),
null_ls.builtins.formatting.isort.with({
runtime_condition = function(params)
if isort_always_enabled == true then