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
|
---- cmp
local cmp = require("cmp")
local luasnip = require("luasnip")
local mapping = cmp.mapping
require("cmp").setup({
completion = {
completeopt = "menu,menuone,noinsert",
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = mapping.preset.insert({
["<C-n>"] = mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-p>"] = mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-b>"] = mapping.scroll_docs(-4),
["<C-f>"] = mapping.scroll_docs(4),
["<C-Space>"] = mapping.complete(),
["<C-e>"] = mapping.abort(),
["<CR>"] = mapping.confirm({ select = true }),
["<S-CR>"] = mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "async_path" },
{ name = "buffer" },
}),
})
---- gitsigns
require("gitsigns").setup()
---- fidget
require("fidget").setup()
---- lsp sources
local null_ls = require("null-ls")
local diagnostics = null_ls.builtins.diagnostics
local formatting = null_ls.builtins.formatting
local sources = {
lsp_servers = {
["bashls"] = "bash-language-server",
["clangd"] = "clangd",
["eslint"] = "eslint",
["nil_ls"] = "nil",
["pyright"] = "pyright-langserver",
["rust_analyzer"] = "rust-analyzer",
["tsserver"] = "typescript-language-server",
},
null_ls = {
diagnostics.actionlint,
diagnostics.alex,
diagnostics.codespell,
diagnostics.deadnix,
diagnostics.pylint,
diagnostics.shellcheck,
diagnostics.statix,
formatting.alejandra,
formatting.beautysh,
formatting.codespell,
formatting.just,
formatting.nimpretty,
formatting.prettier,
formatting.rustfmt,
formatting.shellharden,
formatting.stylua,
formatting.yapf,
},
}
--- lsp config
local capabilities = vim.tbl_deep_extend(
"force",
require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
{ workspace = { didChangeWatchedFiles = { dynamicRegistration = true } } }
)
local all_config = {
capabilities = capabilities,
}
local servers = {}
for server, binary in pairs(sources.lsp_servers) do
if vim.fn.executable(binary) == 1 then
servers[server] = all_config
end
end
servers["lua_ls"] = {
capabilities = capabilities,
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
},
},
}
for server, settings in pairs(servers) do
require("lspconfig")[server].setup(settings)
end
---- null-ls
-- auto-format
local lsp_formatting = function(bufnr)
vim.lsp.buf.format({
filter = function(client)
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local formatting_on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
lsp_formatting(bufnr)
end,
})
end
end
require("mini.comment").setup({
options = {
custom_commentstring = function()
return require("ts_context_commentstring.internal").calculate_commentstring()
or vim.bo.context_commentstring
end,
},
})
require("null-ls").setup({
on_attach = formatting_on_attach,
sources = sources.null_ls,
})
require("nvim-treesitter.configs").setup({
auto_install = false,
highlight = { enable = true },
indent = { enable = true },
context_commentstring = {
enable = true,
enable_autocmd = false,
},
})
---- trouble
require("trouble").setup()
|