-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
2931 lines (2780 loc) · 92.4 KB
/
init.lua
File metadata and controls
2931 lines (2780 loc) · 92.4 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
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
-- 20241030 luocm 整合kickstart配置脚本,清理部分插件(lspsaga、trouble、none-ls、lualine等)
-- 20241101 luocm 清除nvim-surround,用mini.surround代替
-- 20241101 luocm telescope中增加delete_buffer按键映射
-- 20241111 luocm python lsp:pyright、pylyzer不支持stub,使用jedi但最终换回pyright+ruff
-- 前缀键
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- 是否有nerd字体()
vim.g.have_nerd_font = true
-- [[ Install `lazy.nvim` plugin manager ]]
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
error("Error cloning lazy.nvim:\n" .. out)
end
end
---@type vim.Option
local rtp = vim.opt.rtp
rtp:prepend(lazypath)
-- 插件配置
local plugins = {
{ -- Detect tabstop and shiftwidth automatically
"NMAC427/guess-indent.nvim",
config = function()
require("guess-indent").setup({})
end,
},
-- { "akinsho/bufferline.nvim", version = "*", dependencies = "nvim-tree/nvim-web-devicons" },
{ -- bufferline、lualine可mini相关套件替换
"nvim-lualine/lualine.nvim",
-- event = "VeryLazy",
event = { "BufReadPre", "BufNewFile" },
dependencies = { "nvim-tree/nvim-web-devicons", "SmiteshP/nvim-navic" },
config = function()
require("lualine").setup({
options = {
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
},
sections = {
lualine_a = {
{
"mode",
fmt = function(str)
return str:sub(1, 1)
end,
},
},
-- 状态栏c段显示navic代码导航信息,此处基于官方配置进行了改写
lualine_c = {
"filename",
{ -- navic代码导航
"navic",
-- Component specific options
color_correction = nil, -- Can be nil, "static" or "dynamic". This option is useful only when you have highlights enabled.
-- Many colorschemes don't define same backgroud for nvim-navic as their lualine statusline backgroud.
-- Setting it to "static" will perform a adjustment once when the component is being setup. This should
-- be enough when the lualine section isn't changing colors based on the mode.
-- Setting it to "dynamic" will keep updating the highlights according to the current modes colors for
-- the current section.
navic_opts = nil, -- lua table with same format as setup's option. All options except "lsp" options take effect when set here.
},
},
lualine_x = { -- 去掉'fileformat'(目前只有windows、linux图标)
{ -- 宏录制状态提示:recording @q
require("noice").api.status.mode.get,
cond = require("noice").api.status.mode.has,
color = { fg = "#ff9e64" },
},
-- {
-- function()
-- -- Check if MCPHub is loaded
-- if not vim.g.loaded_mcphub then
-- return " -"
-- end
--
-- local count = vim.g.mcphub_servers_count or 0
-- local status = vim.g.mcphub_status or "stopped"
-- local executing = vim.g.mcphub_executing
--
-- -- Show "-" when stopped
-- if status == "stopped" then
-- return " -"
-- end
--
-- -- Show spinner when executing, starting, or restarting
-- if executing or status == "starting" or status == "restarting" then
-- local frames =
-- { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
-- local frame = math.floor(vim.loop.now() / 100) % #frames + 1
-- return " " .. frames[frame]
-- end
--
-- return " " .. count
-- end,
-- color = function()
-- if not vim.g.loaded_mcphub then
-- return { fg = "#6c7086" } -- Gray for not loaded
-- end
--
-- local status = vim.g.mcphub_status or "stopped"
-- if status == "ready" or status == "restarted" then
-- return { fg = "#50fa7b" } -- Green for connected
-- elseif status == "starting" or status == "restarting" then
-- return { fg = "#ffb86c" } -- Orange for connecting
-- else
-- return { fg = "#ff5555" } -- Red for error/stopped
-- end
-- end,
-- },
"encoding",
"filetype",
},
},
})
end,
}, -- 状态栏
-- { -- 文档树
-- "nvim-tree/nvim-tree.lua",
-- config = function()
-- -- disable netrw
-- vim.g.loaded_netrw = 1
-- vim.g.loaded_netrwPlugin = 1
--
-- require("nvim-tree").setup({
-- view = {
-- width = 25,
-- },
-- filters = {
-- custom = {
-- "\\.git$",
-- "\\.svn$",
-- "\\.hg$",
-- "__pycache__",
-- },
-- },
-- -- update_focused_file = {
-- -- enable = true,
-- -- update_root = {
-- -- enable = true,
-- -- },
-- -- },
-- })
-- end,
-- },
{
"nvim-neo-tree/neo-tree.nvim",
version = "*",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
},
lazy = false,
keys = {
{ "<F1>", ":Neotree toggle reveal<CR>", desc = "NeoTree toggle", silent = true },
},
config = function()
require("neo-tree").setup({
filesystem = {
window = {
width = 25,
mappings = {
["<F1>"] = "close_window",
},
},
filtered_items = {
hide_by_name = {
"__pycache__",
"gmcache",
},
},
},
})
end,
},
"nvim-tree/nvim-web-devicons", -- 文档树图标
"christoomey/vim-tmux-navigator", -- 用ctl-hjkl来定位窗口
-- "nvim-treesitter/nvim-treesitter-context", -- 当前上下文,改用navic等面包屑插件
-- "nvim-treesitter/nvim-treesitter-textobjects", -- 有flash后作用不大!
{ -- Highlight, edit, and navigate code
"nvim-treesitter/nvim-treesitter",
-- version = "*",
build = ":TSUpdate",
event = { "BufReadPre", "BufNewFile" },
-- dependencies = {
-- "nvim-treesitter/nvim-treesitter-textobjects", -- 有flash后作用不大!
-- },
config = function()
local parsers = {
"bash",
"c",
"diff",
"html",
"lua",
"luadoc",
"markdown",
"markdown_inline",
"python",
"query",
"vim",
"vimdoc",
}
require("nvim-treesitter").install(parsers)
vim.api.nvim_create_autocmd("FileType", {
callback = function(args)
local buf, filetype = args.buf, args.match
local language = vim.treesitter.language.get_lang(filetype)
if not language then
return
end
-- check if parser exists and load it
if not vim.treesitter.language.add(language) then
return
end
-- enables syntax highlighting and other treesitter features
vim.treesitter.start(buf, language)
-- enables treesitter based folds
-- for more info on folds see `:help folds`
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.wo.foldmethod = "expr"
-- enables treesitter based indentation
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
end,
},
-- "p00f/nvim-ts-rainbow", -- 配合treesitter,不同括号颜色区分
{
"HiPhish/rainbow-delimiters.nvim",
submodules = false, -- 解决安装报错test/bin无法clone
config = function()
require("rainbow-delimiters.setup").setup({})
end,
},
-- {
-- "andymass/vim-matchup",
-- init = function()
-- -- 禁用系统自带matchit插件
-- vim.g.loaded_matchit = 1
-- -- may set any options here (default "status")
-- -- vim.g.matchup_matchparen_offscreen = { method = "popup" }
-- end,
-- },
-- { -- 交换列表、函数中元素(用mini.operators中gx功能替换)
-- "mizlan/iswap.nvim",
-- event = "VeryLazy",
-- },
{
"mason-org/mason.nvim",
lazy = true,
keys = {
{ "<leader>mm", "<cmd>Mason<cr>", desc = "[m]ason" },
},
},
{ -- Main LSP Configuration
"neovim/nvim-lspconfig",
-- event = "VeryLazy",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
-- Automatically install LSPs and related tools to stdpath for Neovim
{ "mason-org/mason.nvim", opts = {} }, -- NOTE: Must be loaded before dependants
"mason-org/mason-lspconfig.nvim",
"WhoIsSethDaniel/mason-tool-installer.nvim",
-- Useful status updates for LSP.
{ -- 进度提示
"j-hui/fidget.nvim",
opts = {
notification = {
-- 等价于vim.notify = require("fidget.notification").notify
-- override_vim_notify = true,
},
},
},
-- Allows extra capabilities provided by blink.cmp
-- "saghen/blink.cmp",
},
config = function()
-- Brief aside: **What is LSP?**
--
-- LSP is an initialism you've probably heard, but might not understand what it is.
--
-- LSP stands for Language Server Protocol. It's a protocol that helps editors
-- and language tooling communicate in a standardized fashion.
--
-- In general, you have a "server" which is some tool built to understand a particular
-- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers
-- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
-- processes that communicate with some "client" - in this case, Neovim!
--
-- LSP provides Neovim with features like:
-- - Go to definition
-- - Find references
-- - Autocompletion
-- - Symbol Search
-- - and more!
--
-- Thus, Language Servers are external tools that must be installed separately from
-- Neovim. This is where `mason` and related plugins come into play.
--
-- If you're wondering about lsp vs treesitter, you can check out the wonderfully
-- and elegantly composed help section, `:help lsp-vs-treesitter`
-- This function gets run when an LSP attaches to a particular buffer.
-- That is to say, every time a new file is opened that is associated with
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
-- function will be executed to configure the current buffer
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }),
callback = function(event)
-- NOTE: Remember that Lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself.
--
-- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time.
local map = function(keys, func, desc, mode)
mode = mode or "n" -- desc = "LSP: " .. desc
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = desc })
end
-- Jump to the definition of the word under your cursor.
-- This is where a variable was first declared, or where a function is defined, etc.
-- To jump back, press <C-t>.
map("gd", require("telescope.builtin").lsp_definitions, "goto [d]efinition")
-- grr/grn/gra/gri/gO等已在runtime\lua\vim\_defaults.lua中被默认定义
-- Find references for the word under your cursor.
map("grr", require("telescope.builtin").lsp_references, "goto [r]eferences")
-- Jump to the implementation of the word under your cursor.
-- Useful when your language has ways of declaring types without an actual implementation.
map("gri", require("telescope.builtin").lsp_implementations, "goto [i]mplementation")
-- Jump to the type of the word under your cursor.
-- Useful when you're not sure what type a variable is and you want to see
-- the definition of its *type*, not where it was *defined*.
map("grt", require("telescope.builtin").lsp_type_definitions, "goto [t]ype definition")
-- Fuzzy find all the symbols in your current document.
-- Symbols are things like variables, functions, types, etc.
map("<leader>sd", require("telescope.builtin").lsp_document_symbols, "symbol: [d]ocument")
-- Fuzzy find all the symbols in your current workspace.
-- Similar to document symbols, except searches over your entire project.
map("<leader>sw", require("telescope.builtin").lsp_dynamic_workspace_symbols, "symbol: [w]orkspace")
-- Rename the variable under your cursor.
-- Most Language Servers support renaming across files, etc.
-- map("<leader>cr", vim.lsp.buf.rename, "code: [r]ename")
-- Execute a code action, usually your cursor needs to be on top of an error
-- or a suggestion from your LSP for this to activate.
-- map("<leader>ca", vim.lsp.buf.code_action, "code: [a]ction", { "n", "x" })
-- WARN: This is not Goto Definition, this is Goto Declaration.
-- For example, in C this would take you to the header.
map("gD", vim.lsp.buf.declaration, "goto [D]eclaration")
-- 光标所在词浮窗提示
map("K", vim.lsp.buf.hover, "hover document")
-- 光标所在词浮窗提示(imap <c-s>已在_defaults.lua中定义)
map("<c-s>", vim.lsp.buf.signature_help, "signature help")
-- 工作目录维护
map("<leader>wa", vim.lsp.buf.add_workspace_folder, "workspace: [a]dd")
map("<leader>wr", vim.lsp.buf.remove_workspace_folder, "workspace: [r]emove")
map("<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, "workspace: [l]ist")
map("gi", vim.lsp.buf.incoming_calls, "goto [i]ncoming_calls")
map("go", vim.lsp.buf.outgoing_calls, "goto [o]utming_calls")
-- The following two autocommands are used to highlight references of the
-- word under your cursor when your cursor rests there for a little while.
-- See `:help CursorHold` for information about when this is executed
--
-- When you move your cursor, the highlights will be cleared (the second autocommand).
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client:supports_method("textDocument/documentHighlight", event.buf) then
local highlight_augroup =
vim.api.nvim_create_augroup("kickstart-lsp-highlight", { clear = false })
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
vim.api.nvim_create_autocmd("LspDetach", {
group = vim.api.nvim_create_augroup("kickstart-lsp-detach", { clear = true }),
callback = function(event)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({ group = "kickstart-lsp-highlight", buffer = event.buf })
end,
})
end
-- The following code creates a keymap to toggle inlay hints in your
-- code, if the language server you are using supports them
if client and client:supports_method("textDocument/inlayHint", event.buf) then
map("<leader>ch", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
end, "code: [h]int")
end
-- 尝试启用LSP自带的折叠功能
if
client
and client:supports_method(vim.lsp.protocol.Methods.textDocument_foldingRange, event.buf)
then
local win = vim.api.nvim_get_current_win()
vim.wo[win][0].foldexpr = "v:lua.vim.lsp.foldexpr()"
end
-- 增加navic代码导航栏(绑定后供winbar、statusline等控件使用)
if client and client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, event.buf)
end
-- sqls数据库插件绑定
-- if client and client.name == "sqls" then
-- require("sqls").on_attach(client, event.buf)
-- end
-- java jdtls额外命令
if client and client.name == "jdtls" then
map("<leader>ei", require("jdtls").organize_imports, "organize [i]mports", { "n" })
map("<leader>ev", require("jdtls").extract_variable, "extract [v]ariable", { "n", "v" })
map("<leader>ec", require("jdtls").extract_constant, "extract [c]onstant", { "n", "v" })
map("<leader>em", require("jdtls").extract_method, "extract [m]ethod", { "n", "v" })
end
local cwd = vim.fn.getcwd()
-- 规范化目录分隔符为/,windows上为\
cwd = string.gsub(cwd, "\\", "/")
-- python项目根目录cwd及src目录加入到LSP搜索目录中,避免代码无法跳转
if client and client.name == "pyright" then
local extraPaths = { cwd, cwd .. "/src" }
local workspace_folders = vim.lsp.buf.list_workspace_folders()
for _, folder in ipairs(extraPaths) do
if vim.fn.isdirectory(folder) == 1 and not vim.tbl_contains(workspace_folders, folder) then
vim.lsp.buf.add_workspace_folder(folder)
end
end
client.settings.python.analysis.extraPaths = extraPaths -- pyright
-- 排除扫描目录,降低pyright内存消耗
client.settings.python.analysis.exclude =
{ "**/node_modules", "**/__pycache__", "**/.venv", "**/site-packages" }
end
end,
})
-- LSP servers and clients are able to communicate to each other what features they support.
-- By default, Neovim doesn't support everything that is in the LSP specification.
-- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities.
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
local capabilities = require("blink.cmp").get_lsp_capabilities()
-- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
--
-- Add any additional override configuration in the following tables. Available keys are:
-- - cmd (table): Override the default command used to start the server
-- - filetypes (table): Override the default list of associated filetypes for the server
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
-- - settings (table): Override the default settings passed when initializing the server.
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
local servers = {
clangd = {},
-- gopls = {},
-- pyright侧重于类型检查,ruff负责lint、import、快速修复
-- https://microsoft.github.io/pyright/#/settings
pyright = {
-- settings = {
-- -- pyright = {
-- -- -- disableLanguageServices = false, -- 保持基础 LSP 功能
-- -- disableOrganizeImports = true, -- 关闭 Pyright 自带的 import 整理
-- -- },
-- python = {
-- analysis = {
-- extraPaths = { "." },
-- -- -- useLibraryCodeForTypes = true,
-- -- -- diagnosticSeverityOverrides = {
-- -- -- reportUnusedImport = "none", -- 禁用未使用导入的提示
-- -- -- },
-- -- -- autoImportCompletions = true,
-- -- -- typeCheckingMode = "strict",
-- -- -- diagnosticMode = "workspace", -- 降低实时诊断频率
-- -- linting = { enabled = false }, -- 彻底关闭 Pyright 的 lint 功能
-- --
-- -- -- Ignore all files for analysis to exclusively use Ruff for linting
-- -- -- ignore = { "*" },
-- },
-- },
-- },
},
-- https://docs.astral.sh/ruff/editors/settings/
ruff = {
-- settings = {
-- init_options = {
-- settings = {
-- args = { "--fix-only", "--select=ALL" }, -- 全量规则 + 自动修复
-- organizeImports = true, -- 接管 imports 整理
-- lint = { enable = true },
-- },
-- },
-- -- 增强 Ruff 的代码操作优先级
-- -- capabilities = require("cmp_nvim_lsp").default_capabilities().textDocument.codeAction,
-- },
},
-- rust_analyzer = {},
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
--
-- Some languages (like typescript) have entire language plugins that can be useful:
-- https://github.com/pmizio/typescript-tools.nvim
--
-- But for many setups, the LSP (`ts_ls`) will work just fine
-- ts_ls = {},
--
stylua = {}, -- Used to format Lua code
-- Special Lua Config, as recommended by neovim help docs
lua_ls = {
on_init = function(client)
if client.workspace_folders then
local path = client.workspace_folders[1].name
if
path ~= vim.fn.stdpath("config")
and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc"))
then
return
end
end
client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
runtime = {
version = "LuaJIT",
path = { "lua/?.lua", "lua/?/init.lua" },
},
workspace = {
checkThirdParty = false,
-- NOTE: this is a lot slower and will cause issues when working on your own configuration.
-- See https://github.com/neovim/nvim-lspconfig/issues/3189
library = vim.tbl_extend("force", vim.api.nvim_get_runtime_file("", true), {
"${3rd}/luv/library",
"${3rd}/busted/library",
}),
},
})
end,
settings = {
Lua = {},
},
},
-- sqls = {
-- settings = {
-- sqls = { -- https://github.com/sqls-server/sqls
-- connections = {
-- {
-- driver = "mysql",
-- dataSourceName = "root:root@tcp(127.0.0.1:3306)/world",
-- },
-- {
-- driver = "postgresql",
-- dataSourceName = "host=127.0.0.1 port=15432 user=postgres password=mysecretpassword1234 dbname=dvdrental sslmode=disable",
-- },
-- },
-- },
-- },
-- },
-- ltex配置不起作用,暂不知原因
ltex = {
filetypes = { "latex", "tex", "bibtex", "markdown" }, -- 仅保留必要类型
settings = {
ltex = {
enabled = { "latex", "markdown" }, -- 关闭 gitcommit 等无关功能
-- 禁用耗时检查
checkers = {
latex = { enable = false }, -- 关闭 LaTeX 语法检查
spelling = { enable = false }, -- 关闭拼写检查
},
},
},
},
}
-- You can add other tools here that you want Mason to install
-- for you, so that they are available from within Neovim.
local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, {
"stylua", -- Used to format Lua code
"lua_ls",
"pyright",
"ruff",
-- "jdtls", -- jdtls目前为独立的插件(nvim-jdtls),不在mason系统中管理
})
-- Ensure the servers and tools above are installed
-- To check the current status of installed tools and/or manually install
-- other tools, you can run
-- :Mason
--
-- You can press `g?` for help in this menu.
-- require("mason").setup({
-- ui = {
-- icons = {
-- package_installed = "✓",
-- package_pending = "➜",
-- package_uninstalled = "✗",
-- },
-- },
-- })
require("mason-tool-installer").setup({ ensure_installed = ensure_installed })
-- require("mason-lspconfig").setup({
-- ensure_installed = {},
-- automatic_installation = false,
-- handlers = {
-- function(server_name)
-- local server = servers[server_name] or {}
-- -- This handles overriding only values explicitly passed
-- -- by the server configuration above. Useful when disabling
-- -- certain features of an LSP (for example, turning off formatting for ts_ls)
-- server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {})
--
-- -- jdtls目前为独立的插件(nvim-jdtls),不在mason系统中管理
-- if server_name ~= "jdtls" then
-- require("lspconfig")[server_name].setup(server)
-- end
-- end,
-- },
-- })
-- 启用LSP
for name, server in pairs(servers) do
vim.lsp.config(name, server)
vim.lsp.enable(name)
end
end,
},
-- { -- hover信息美化
-- "Fildo7525/pretty_hover",
-- event = "LspAttach",
-- opts = {},
-- },
{ -- Autocompletion
"saghen/blink.cmp",
-- event = "VimEnter",
event = { "BufReadPre", "BufNewFile" },
version = "1.*",
dependencies = {
-- "Kaiser-Yang/blink-cmp-avante",
-- Snippet Engine & its associated nvim-cmp source
{
"L3MON4D3/LuaSnip",
version = "2.*",
build = (function()
-- Build Step is needed for regex support in snippets.
-- This step is not supported in many windows environments.
-- Remove the below condition to re-enable on windows.
if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then
return
end
return "make install_jsregexp"
end)(),
dependencies = {
-- `friendly-snippets` contains a variety of premade snippets.
-- See the README about individual language/framework/plugin snippets:
-- https://github.com/rafamadriz/friendly-snippets
{
"rafamadriz/friendly-snippets",
config = function()
-- 默认片段文件
require("luasnip.loaders.from_vscode").lazy_load()
-- 自定义片段文件(snipmate格式)
require("luasnip.loaders.from_snipmate").lazy_load({ paths = "./snippets" })
end,
},
},
opts = {},
},
"folke/lazydev.nvim",
{ -- AI辅助
"luozhiya/fittencode.nvim",
-- event = "VeryLazy",
event = { "BufReadPre", "BufNewFile" },
opts = {
-- Default keymaps
use_default_keymaps = true,
},
},
"xzbdmw/colorful-menu.nvim",
},
--- @module 'blink.cmp'
--- @type blink.cmp.Config
opts = {
cmdline = {
keymap = {
-- ["<cr>"] = { "select_and_accept", "fallback" },
},
completion = {
-- Whether to automatically show the window when new completion items are available
menu = { auto_show = true },
-- Displays a preview of the selected item on the current line
ghost_text = { enabled = false },
},
},
keymap = {
-- 'default' (recommended) for mappings similar to built-in completions
-- <c-y> to accept ([y]es) the completion.
-- This will auto-import if your LSP supports it.
-- This will expand snippets if the LSP sent a snippet.
-- 'super-tab' for tab to accept
-- 'enter' for enter to accept
-- 'none' for no mappings
--
-- For an understanding of why the 'default' preset is recommended,
-- you will need to read `:help ins-completion`
--
-- No, but seriously. Please read `:help ins-completion`, it is really good!
--
-- All presets have the following mappings:
-- <tab>/<s-tab>: move to right/left of your snippet expansion
-- <c-space>: Open menu or open docs if already open
-- <c-n>/<c-p> or <up>/<down>: Select next/previous item
-- <c-e>: Hide menu
-- <c-k>: Toggle signature help
--
-- See :h blink-cmp-config-keymap for defining your own keymap
preset = "default",
-- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see:
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
},
appearance = {
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- Adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono",
},
completion = {
menu = {
draw = {
-- We don't need label_description now because label and label_description are already
-- combined together in label by colorful-menu.nvim.
columns = { { "kind_icon" }, { "label", gap = 1 } },
components = {
label = {
text = function(ctx)
return require("colorful-menu").blink_components_text(ctx)
end,
highlight = function(ctx)
return require("colorful-menu").blink_components_highlight(ctx)
end,
},
},
},
},
-- By default, you may press `<c-space>` to show the documentation.
-- Optionally, set `auto_show = true` to show the documentation after a delay.
documentation = { auto_show = true, auto_show_delay_ms = 500 },
},
sources = {
-- "avante", "codecompanion"
default = { "lsp", "path", "snippets", "buffer", "lazydev" },
per_filetype = {
codecompanion = { "codecompanion" },
-- sql = { "snippets", "dadbod", "buffer" },
},
providers = {
-- avante = {
-- module = "blink-cmp-avante",
-- name = "Avante",
-- opts = {
-- -- options for blink-cmp-avante
-- },
-- },
-- dadbod = { name = "Dadbod", module = "vim_dadbod_completion.blink" },
lazydev = { name = "LazyDev", module = "lazydev.integrations.blink", score_offset = 5 },
fittencode = {
name = "fittencode",
module = "fittencode.sources.blink",
score_offset = 10,
},
buffer = {
opts = {
-- get all but "normal" buffers (recommended)
get_bufnrs = function()
return vim.tbl_filter(function(bufnr)
return vim.bo[bufnr].buftype == ""
end, vim.api.nvim_list_bufs())
end,
},
},
},
},
snippets = { preset = "luasnip" },
-- Blink.cmp includes an optional, recommended rust fuzzy matcher,
-- which automatically downloads a prebuilt binary when enabled.
--
-- By default, we use the Lua implementation instead, but you may enable
-- the rust implementation via `'prefer_rust_with_warning'`
--
-- See :h blink-cmp-config-fuzzy for more information
fuzzy = { implementation = "prefer_rust_with_warning" },
-- Shows a signature help window while you type arguments for a function
signature = { enabled = true },
},
opts_extend = { "sources.default" },
},
-- { -- 写代码AI辅助
-- "tzachar/cmp-tabnine",
-- event = "InsertEnter",
-- build = "powershell ./install.ps1",
-- dependencies = "hrsh7th/nvim-cmp",
-- },
-- { -- 类似CursorIDE的AI插件
-- "yetone/avante.nvim",
-- event = "VeryLazy",
-- lazy = false,
-- version = false, -- set this if you want to always pull the latest change
-- build = function()
-- -- conditionally use the correct build system for the current OS
-- if vim.fn.has("win32") == 1 then
-- return "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false"
-- else
-- return "make"
-- end
-- end,
-- --@module 'avante'
-- --@type avante.Config
-- opts = {
-- provider = "p1",
-- providers = {
-- openai = {
-- hide_in_model_selector = true,
-- },
-- vertex = {
-- hide_in_model_selector = true,
-- },
-- vertex_claude = {
-- hide_in_model_selector = true,
-- },
-- p1 = {
-- disable_tools = true,
-- __inherited_from = "openai",
-- hide_in_model_selector = false,
-- endpoint = "https://openrouter.ai/api/v1",
-- api_key_name = "OPENROUTER_API_KEY",
-- model = "deepseek/deepseek-r1-0528:free",
-- },
-- p2 = {
-- disable_tools = true,
-- __inherited_from = "openai",
-- hide_in_model_selector = false,
-- endpoint = "https://openrouter.ai/api/v1",
-- api_key_name = "OPENROUTER_API_KEY",
-- model = "qwen/qwen3-coder:free",
-- },
-- p3 = {
-- disable_tools = true,
-- __inherited_from = "openai",
-- hide_in_model_selector = false,
-- endpoint = "https://openrouter.ai/api/v1",
-- api_key_name = "OPENROUTER_API_KEY",
-- model = "z-ai/glm-4.5-air:free",
-- },
-- },
-- },
-- dependencies = {
-- "nvim-lua/plenary.nvim",
-- "MunifTanjim/nui.nvim",
-- --- The below dependencies are optional,
-- "nvim-tree/nvim-web-devicons", -- or nvim-mini/mini.icons
-- "nvim-telescope/telescope.nvim", -- for file_selector provider telescope
-- "zbirenbaum/copilot.lua", -- for providers='copilot'
-- -- "stevearc/dressing.nvim",
-- -- "folke/snacks.nvim",
-- {
-- -- support for image pasting
-- "HakonHarnes/img-clip.nvim",
-- event = "VeryLazy",
-- opts = {
-- -- recommended settings
-- default = {
-- embed_image_as_base64 = false,
-- prompt_for_file_name = false,
-- drag_and_drop = {
-- insert_mode = true,
-- },
-- -- required for Windows users
-- use_absolute_path = true,
-- },
-- },
-- },
-- {
-- -- Make sure to set this up properly if you have lazy=true
-- "MeanderingProgrammer/render-markdown.nvim",
-- opts = {
-- file_types = { "markdown", "Avante" },
-- },
-- ft = { "markdown", "Avante" },
-- },
-- },
-- },
{ -- AI辅助,目前高频使用,不要延迟加载
"olimorris/codecompanion.nvim",
event = { "BufReadPre", "BufNewFile" },
keys = {
{ "gp", "<cmd>CodeCompanionChat Toggle<cr>", mode = { "n" }, desc = "ai: [c]hat" },
},
config = function()
--https://github.com/olimorris/codecompanion.nvim/issues/2270
require("codecompanion").setup({
-- opts = { language = "Chinese", log_level = "INFO" },
-- tools = { enabled = false },
strategies = {
-- 默认用魔搭,硅基流动的模型相对贵,openrouter免费模型频繁下线
chat = {
adapter = "_modelscope",
roles = {
llm = function(adapter)
-- 模型名称类似于abc/def/ghi,只取最后一个ghi
return "Ai: " .. adapter.name .. "." .. adapter.model.name:match("([^/]+)$")
end,
user = "Me",
},
variables = {},
},
inline = { adapter = "_modelscope" },
},
adapters = {
http = {
_modelscope = function()
return require("codecompanion.adapters").extend("openai_compatible", {
env = {
url = "https://api-inference.modelscope.cn",
api_key = "MODELSCOPE_ACCESS_TOKEN",
chat_url = "/v1/chat/completions",
},
schema = {
model = {
default = "Qwen/Qwen3-Coder-30B-A3B-Instruct",
choices = {
"Qwen/Qwen3-Coder-30B-A3B-Instruct",
"Qwen/Qwen3-Next-80B-A3B-Instruct",
"ZhipuAI/GLM-5",
"MiniMax/MiniMax-M2.5",
"moonshotai/Kimi-K2.5",
"Qwen/Qwen3-Coder-480B-A35B-Instruct",
"deepseek-ai/DeepSeek-V3.2",
},
},
},
handlers = {
-- AI请求执行完成时,解析响应头获取配额信息
-- https://github.com/olimorris/codecompanion.nvim/discussions/2395
on_exit = function(self, data)