Skip to content

Commit 60ccb0e

Browse files
committed
fix: clean up download directory after compiling the lsp
Closes #58
1 parent 2d610ee commit 60ccb0e

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

lua/elixir/language_server/compile.lua

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
local Version = require("elixir.language_server.version")
21
local Path = require("plenary.path")
32
local Job = require("plenary.job")
4-
local Utils = require("elixir.utils")
53

64
local __file = Path:new(debug.getinfo(1, "S").source:match("@(.*)$"))
75
assert(__file:exists())
@@ -17,7 +15,6 @@ end
1715

1816
function M.compile(source_path, install_path, opts)
1917
local do_sync = opts.sync or false
20-
local v = Version.get()
2118

2219
local printer = function(err, line)
2320
if opts.bufnr then
@@ -43,21 +40,7 @@ function M.compile(source_path, install_path, opts)
4340
end,
4441
on_stdout = do_sync and printer or vim.schedule_wrap(printer),
4542
on_stderr = do_sync and printer or vim.schedule_wrap(printer),
46-
on_exit = vim.schedule_wrap(function(_, code)
47-
if code == 0 then
48-
if opts.bufnr then
49-
vim.api.nvim_buf_call(opts.bufnr, function()
50-
vim.api.nvim_command("quit")
51-
end)
52-
end
53-
54-
vim.notify("Finished compiling ElixirLS!")
55-
vim.notify("Reloading buffer")
56-
vim.api.nvim_command("edit")
57-
vim.notify("Restarting LSP client")
58-
vim.api.nvim_command("LspRestart")
59-
end
60-
end),
43+
on_exit = vim.schedule_wrap(opts.on_exit),
6144
}
6245

6346
-- sync is just for testing

lua/elixir/language_server/download.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local curl = require("plenary.curl")
21
local Path = require("plenary.path")
32
local Job = require("plenary.job")
43

lua/elixir/language_server/init.lua

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function M.open_floating_window(buf)
3636
col = 0,
3737
minwidth = width,
3838
minheight = height,
39-
border = {},
39+
border = false,
4040
padding = { 2, 2, 2, 2 },
4141
zindex = 10,
4242
})
@@ -218,7 +218,33 @@ local function install_elixir_ls(opts)
218218
Compile.compile(
219219
download_dir:joinpath(source_path):absolute(),
220220
opts.install_path:absolute(),
221-
vim.tbl_extend("force", opts, { bufnr = bufnr })
221+
vim.tbl_extend("force", opts, {
222+
bufnr = bufnr,
223+
on_exit = function(_, compile_code)
224+
if compile_code == 0 then
225+
if bufnr then
226+
vim.api.nvim_buf_call(bufnr, function()
227+
vim.api.nvim_command("quit")
228+
end)
229+
end
230+
231+
vim.notify("Finished compiling ElixirLS!")
232+
vim.notify("Reloading buffer")
233+
vim.api.nvim_command("edit")
234+
vim.notify("Restarting LSP client")
235+
vim.api.nvim_command("LspRestart")
236+
vim.fn.jobstart({ "rm", "-rf", download_dir:absolute() }, {
237+
on_exit = vim.schedule_wrap(function(_, rm_code)
238+
if rm_code == 0 then
239+
vim.notify("Cleaned up elixir.nvim download directory")
240+
else
241+
vim.api.nvim_err_writeln("Failed to clean up elixir.nivm download directory")
242+
end
243+
end),
244+
})
245+
end
246+
end,
247+
})
222248
)
223249
end
224250

0 commit comments

Comments
 (0)