-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathinit.lua
More file actions
63 lines (53 loc) · 1.36 KB
/
init.lua
File metadata and controls
63 lines (53 loc) · 1.36 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
local M = {}
if not vim.uv then
vim.uv = vim.loop
end
function M.setup(opts)
local credo = vim.api.nvim_create_augroup("elixir-tools.credo", { clear = true })
vim.api.nvim_create_autocmd({ "FileType" }, {
group = credo,
pattern = { "elixir" },
callback = function()
local matches = vim.fs.find({ "mix.lock" }, {
stop = vim.uv.os_homedir(),
upward = true,
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
})
local file = nil
local function read_file(path)
local f = io.open(path, "rb")
if not f then
return nil
end
local content = f:read("*a")
f:close()
return content
end
for _, f in ipairs(matches) do
if f and read_file(f):find([["credo": {]]) then
file = f
break
end
end
if file then
local cmd
if type(opts.port) == "number" then
cmd = vim.lsp.rpc.connect("127.0.0.1", opts.port)
else
cmd = { opts.cmd, "--stdio" }
end
vim.lsp.start {
name = "Credo",
cmd = cmd,
cmd_env = {
CREDO_LSP_VERSION = opts.version
},
settings = {},
root_dir = vim.fs.dirname(file),
on_attach = opts.on_attach or function() end,
}
end
end,
})
end
return M