-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
181 lines (165 loc) · 5.09 KB
/
init.lua
File metadata and controls
181 lines (165 loc) · 5.09 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
--- LSP configuration
---
--- Author: @lararosekelley
--- Last Modified: September 1st, 2025
local icons = require("config.icons").icons
local lsp_format = require("utils.lsp").lsp_format
local lsp_augroup = require("utils.lsp").lsp_augroup
local lsp_servers = require("utils.lsp").lsp_servers
return {
-- lsp and diagnostics
{
"nvimtools/none-ls.nvim",
event = "VeryLazy",
dependencies = {
"nvim-lua/plenary.nvim",
"nvimtools/none-ls-extras.nvim",
"neovim/nvim-lspconfig",
"RRethy/vim-illuminate", -- highlight other uses of word under cursor
},
config = function()
local nls = require("null-ls")
local handlers = require("plugins.lsp.handlers")
local eslint_code_actions = require("none-ls.code_actions.eslint")
local flake8_diagnostics = require("none-ls.diagnostics.flake8")
local has_extra_vale, vale_diagnostics = pcall(require, "none-ls.diagnostics.vale")
local formatting = nls.builtins.formatting
local diagnostics = nls.builtins.diagnostics
local vale = nil
if has_extra_vale then
vale = vale_diagnostics
elseif diagnostics.vale then
vale = diagnostics.vale
end
local sources = {
-- code actions
eslint_code_actions.with({
prefer_local = "node_modules/.bin",
}),
-- diagnostics
flake8_diagnostics.with({
prefer_local = ".venv/bin",
}),
diagnostics.markdownlint_cli2.with({
extra_filetypes = { "vimwiki" },
}),
diagnostics.sqlfluff.with({
extra_args = { "--dialect", "postgres" }, -- prefer postgresql
}),
-- formatting
formatting.black.with({
extra_args = { "--fast" },
prefer_local = ".venv/bin",
}),
formatting.google_java_format,
formatting.prettierd.with({
extra_filetypes = { "toml", "vimwiki" },
}),
formatting.stylua,
}
if vale then
table.insert(sources, vale.with({
filetypes = { "markdown", "text", "gitcommit", "rst", "asciidoc" },
extra_args = function(params)
local root = params.root or ((vim.uv or vim.loop).cwd()) or vim.fn.getcwd()
local local_config = nil
if vim.fn.filereadable(root .. "/.vale.ini") == 1 then
local_config = root .. "/.vale.ini"
elseif vim.fn.filereadable(root .. "/_vale.ini") == 1 then
local_config = root .. "/_vale.ini"
end
return { "--config", local_config or (vim.fn.stdpath("config") .. "/.vale.ini") }
end,
}))
end
handlers.setup()
nls.setup({
-- flip to true to debug
debug = false,
sources = sources,
on_attach = function(client, bufnr)
-- https://github.com/nvimtools/none-ls.nvim/wiki/Avoiding-LSP-formatting-conflicts
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = lsp_augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = lsp_augroup,
buffer = bufnr,
callback = lsp_format,
})
end
end,
})
end,
},
-- non-LSP tool installer
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
event = "VeryLazy",
dependencies = { "mason-org/mason.nvim" },
opts = {
ensure_installed = {
"black",
"flake8",
"google-java-format",
"markdownlint-cli2",
"vale",
"prettierd",
"rust-analyzer",
"sqlfluff",
"stylua",
},
},
},
-- language server installer
{
"mason-org/mason-lspconfig.nvim",
event = "VeryLazy",
dependencies = {
"mason-org/mason.nvim",
"neovim/nvim-lspconfig",
},
keys = {
{ "<leader>M", "<cmd>Mason<cr>", desc = "Mason" },
},
config = function()
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")
local handlers = require("plugins.lsp.handlers")
mason.setup({
ui = {
check_outdated_packages_on_open = true,
icons = icons.mason,
},
})
mason_lspconfig.setup({
automatic_installation = true,
ensure_installed = lsp_servers,
})
for _, server in pairs(lsp_servers) do
-- settings for all language servers
local opts = {
on_attach = handlers.on_attach,
capabilities = handlers.capabilities,
}
local server_exists, server_opts = pcall(require, "plugins.lsp.settings." .. server)
if not server_exists then
server_opts = {}
end
opts = vim.tbl_deep_extend("force", server_opts, opts)
vim.lsp.config(server, opts)
vim.lsp.enable(server)
end
end,
},
-- better lua lsp performance
{
"folke/lazydev.nvim",
ft = "lua",
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = "${3rd}/luv/library", words = { "vim%.uv" } },
},
},
},
}