-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathinit.lua
More file actions
101 lines (82 loc) · 2.52 KB
/
init.lua
File metadata and controls
101 lines (82 loc) · 2.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
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
if not vim.iter then
vim.iter = require("elixir.iter")
end
local elixirls = require("elixir.elixirls")
local credo = require("elixir.credo")
local nextls = require("elixir.nextls")
local mix = require("elixir.mix")
local projectionist = require("elixir.projectionist")
local utils = require("elixir.utils")
local M = {}
M.elixirls = {}
M.elixirls.settings = elixirls.settings
M.elixirls.open_output_panel = elixirls.open_output_panel
M.credo = {}
M.credo.default_bin = (
vim.fn.fnamemodify(debug.getinfo(1).source, ":h") .. "/../../bin/credo-language-server"
):gsub("^@", "")
local enabled = function(value)
return value == nil or value == true
end
local define_user_command = function()
vim.api.nvim_create_user_command("Elixir", function(opts)
local args = vim.iter(opts.fargs)
local command = args:next()
local not_found = false
if "nextls" == command then
local subcommand = args:next()
if "uninstall" == subcommand then
vim.fn.delete(nextls.default_bin)
vim.notify(string.format("Uninstalled Next LS from %s", nextls.default_bin), vim.lsp.log_levels.INFO)
else
not_found = true
end
else
not_found = true
end
if not_found then
vim.notify("elixir-tools: unknown command: " .. opts.name .. " " .. opts.args, vim.lsp.log_levels.WARN)
end
end, {
desc = "elixir-tools main command",
nargs = "+",
complete = function(_, cmd_line)
local cmd = vim.trim(cmd_line)
if vim.startswith(cmd, "Elixir nextls") then
return { "uninstall" }
elseif vim.startswith(cmd, "Elixir") then
return { "nextls" }
end
end,
})
end
function M.setup(opts)
opts = opts or {}
opts.elixirls = opts.elixirls or {}
opts.credo = opts.credo or {}
opts.nextls = opts.nextls or {}
define_user_command()
if not opts.credo.cmd then
opts.credo.cmd = M.credo.default_bin
end
if enabled(opts.credo.enable) and not opts.credo.version then
opts.credo.version = utils.latest_release("elixir-tools", "credo-language-server")
end
local nextls_auto_update
if not opts.nextls.cmd then
opts.nextls.cmd = nextls.default_bin
nextls_auto_update = true
end
mix.setup()
projectionist.setup()
if enabled(opts.elixirls.enable) then
elixirls.setup(opts.elixirls)
end
if opts.credo.version and enabled(opts.credo.enable) then
credo.setup(opts.credo)
end
if opts.nextls.enable == true then
nextls.setup(vim.tbl_extend("force", opts.nextls, { auto_update = nextls_auto_update }))
end
end
return M