-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy path.nvim.lua
More file actions
66 lines (58 loc) · 1.52 KB
/
Copy path.nvim.lua
File metadata and controls
66 lines (58 loc) · 1.52 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
-- Get the current working directory (CWD)
local cwd = vim.fn.getcwd()
-- Load the local config file if it exists
local f, err = loadfile(".nvim.local.lua")
if not err then
local ok, err_f = pcall(f)
if not ok then
vim.print(err_f)
end
else
vim.lsp.config("zls", {
cmd = { cwd .. "/tools/zls.sh" },
})
vim.lsp.enable("zls")
function runFixAll()
local params = vim.lsp.util.make_range_params()
params.context = {
only = { "source.fixAll" },
diagnostics = {},
}
-- Send synchronous request (timeout 2 seconds)
local responses = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 1000)
if not responses then
return
end
for _, resp in pairs(responses) do
for _, action in ipairs(resp.result or {}) do
-- If action has edits, apply them
if action.edit then
vim.lsp.util.apply_workspace_edit(action.edit, "utf-16")
end
-- If the action has a command, execute it
if action.command then
vim.lsp.buf.execute_command(action.command)
end
end
end
end
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.zig", "*.zon" },
callback = runFixAll,
})
local ok, conform = pcall(require, "conform")
if ok then
conform.formatters_by_ft.bzl = { "buildifier" }
conform.formatters.buildifier = {
command = cwd .. "/tools/buildifier.sh",
}
vim.api.nvim_create_autocmd("FileType", {
pattern = "bzl",
callback = function()
vim.keymap.set("n", "<Leader>f", function()
mod.format()
end, { remap = false, silent = true })
end,
})
end
end