Skip to content

Commit

Permalink
refactor: ensure that a restart without tracing removes it
Browse files Browse the repository at this point in the history
  • Loading branch information
ckipp01 committed Dec 27, 2022
1 parent c36ead3 commit 79b3dec
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions lua/metals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,42 @@ local function get_metals_and_stop()
end
end

M.restart_server = function()
get_metals_and_stop()
local function configure_conf(with_tracing)
local our_config = conf.get_config_cache()

-- We want to make sure that we aren't double setting tracing here so we check
-- if tracing was enabled before and if so, do nothing. If we don't want tracing
-- we simply set the cmd to nil which will then force it to be re-computed in config.lua
-- ensure that if you had tracing before, you now don't on the restart.
if with_tracing then
if not util.starts_with(our_config.cmd[1], "cs") then
local langoustine = { "cs", "launch", "tech.neander:langoustine-tracer_3:latest.stable", "--" }
our_config.cmd = util.merge_lists(langoustine, our_config.cmd)
end
else
our_config.cmd = nil
end

vim.defer_fn(function()
setup.initialize_or_attach()
end, 3000)
return our_config
end

M.restart_server_with_langoustine_tracing = function()
local function restart_server(with_tracing)
get_metals_and_stop()

local old_conf = conf.get_config_cache()
local langoustine = { "cs", "launch", "tech.neander:langoustine-tracer_3:latest.stable", "--" }
old_conf.cmd = util.merge_lists(langoustine, old_conf.cmd)
local fresh_conf = configure_conf(with_tracing)

vim.defer_fn(function()
setup.initialize_or_attach(old_conf)
setup.initialize_or_attach(fresh_conf)
end, 3000)
end

M.restart_server = function()
restart_server(false)
end

M.restart_server_with_langoustine_tracing = function()
restart_server(true)
end

local function show_decoded(decoder_type, format)
local _format = ""
if format then
Expand Down

0 comments on commit 79b3dec

Please sign in to comment.