Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bin/nextls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env -S elixir --sname undefined

System.no_halt(true)

Logger.configure(level: :none)

Mix.start()
Mix.shell(Mix.Shell.Process)

Mix.install([{:next_ls, System.get_env("NEXTLS_VERSION")}])

Logger.configure(level: :info)

Application.ensure_all_started(:next_ls)
21 changes: 21 additions & 0 deletions lua/elixir/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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")
Expand All @@ -17,6 +18,13 @@ M.credo.default_bin = (
vim.fn.fnamemodify(debug.getinfo(1).source, ":h") .. "/../../bin/credo-language-server"
):gsub("^@", "")

M.nextls = {}

M.nextls.default_bin = (vim.fn.fnamemodify(debug.getinfo(1).source, ":h") .. "/../../bin/nextls"):gsub(
"^@",
""
)

local enabled = function(value)
return value == nil or value == true
end
Expand All @@ -26,6 +34,7 @@ function M.setup(opts)

opts.elixirls = opts.elixirls or {}
opts.credo = opts.credo or {}
opts.nextls = opts.nextls or {}

if not opts.credo.cmd then
opts.credo.cmd = M.credo.default_bin
Expand All @@ -35,6 +44,14 @@ function M.setup(opts)
opts.credo.version = utils.latest_release("elixir-tools", "credo-language-server")
end

if not opts.nextls.cmd then
opts.nextls.cmd = M.nextls.default_bin
end

if not opts.nextls.version then
opts.nextls.version = utils.latest_release("elixir-tools", "next-ls")
end

mix.setup()
projectionist.setup()
if enabled(opts.elixirls.enable) then
Expand All @@ -43,6 +60,10 @@ function M.setup(opts)
if enabled(opts.credo.enable) then
credo.setup(opts.credo)
end

if enabled(opts.nextls.enable) then
nextls.setup(opts.nextls)
end
end

return M
45 changes: 45 additions & 0 deletions lua/elixir/nextls/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local M = {}

if not vim.uv then
vim.uv = vim.loop
end

function M.setup(opts)
local nextls_group = vim.api.nvim_create_augroup("elixir-tools.nextls", { clear = true })

vim.api.nvim_create_autocmd({ "FileType" }, {
group = nextls_group,
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 = matches[1]

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 = "NextLS",
cmd = cmd,
cmd_env = {
NEXTLS_VERSION = opts.version,
},
settings = {},
root_dir = vim.fs.dirname(file),
on_attach = opts.on_attach or function() end,
}
end
end,
})
end

return M
2 changes: 1 addition & 1 deletion lua/elixir/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function M.latest_release(owner, repo)
)
local resp = vim.json.decode(vim.fn.system(curl))

return resp and resp.tag_name:gsub("^v", "") or nil
return resp and resp.tag_name and resp.tag_name:gsub("^v", "") or nil
end

return M