Skip to content

Commit

Permalink
feat: add a restart command with langoustine
Browse files Browse the repository at this point in the history
  • Loading branch information
ckipp01 committed Dec 23, 2022
1 parent 92f7451 commit c36ead3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
10 changes: 10 additions & 0 deletions doc/metals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ The following commands are provided by `nvim-metals`:
* |MetalsResetChoice|
* |MetalsRestartBuild|
* |MetalsRestartServer|
* |MetalsRestartServerWithLangoustineTracing|
* |MetalsRunDoctor|
* |MetalsRunScalafix|
* |MetalsScanSources|
Expand Down Expand Up @@ -634,6 +635,12 @@ MetalsRestartBuild Manually restart the build server.
*MetalsRestartServer*
MetalsRestartServer Restart the Metals server.

*MetalsRestartServerWithLangoustineTracing*
MetalsRestartServerWithLangoustineTracing Restart the Metals server with
tracing enabled via Langoustine. To read more
about Langoustine check out
https://neandertech.github.io/langoustine/tracer.html.

*MetalsRunDoctor*
MetalsRunDoctor Run Metals Doctor, which will open a floating
window to show you the status of Metals.
Expand Down Expand Up @@ -932,6 +939,9 @@ restart_build() Use to execute a |metals.build-restart| command.
*restart_server()*
restart_server() Restart the Metals server.

*restart_server_with_langoustine_tracing()*
restart_server() Restart the Metals server with Langoustine tracing.

*run_doctor()*
run_doctor() Use to execute a |metals.doctor-run| command.

Expand Down
20 changes: 17 additions & 3 deletions lua/metals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ M.organize_imports = function()
end
end

-- Used to fully restart Metals. This will send a shutdown request to Metals,
-- delay for 3 seconds, and then reconnect.
M.restart_server = function()
local function get_metals_and_stop()
for _, buf in pairs(fn.getbufinfo({ bufloaded = true })) do
if vim.tbl_contains(conf.scala_file_types, api.nvim_buf_get_option(buf.bufnr, "filetype")) then
local clients = lsp.buf_get_clients(buf.bufnr)
Expand All @@ -322,12 +320,28 @@ M.restart_server = function()
end
end
end
end

M.restart_server = function()
get_metals_and_stop()

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

M.restart_server_with_langoustine_tracing = function()
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)

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

local function show_decoded(decoder_type, format)
local _format = ""
if format then
Expand Down
5 changes: 5 additions & 0 deletions lua/metals/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ local commands_table = {
label = "Restart Server",
hint = "Restart Metals",
},
{
id = "restart_server_with_langoustine_tracing",
label = "Restart Server with Langoustine tracing",
hint = "Restart Server with Tracing",
},
{
id = "run_doctor",
label = "Run Doctor",
Expand Down
1 change: 1 addition & 0 deletions lua/metals/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ local valid_metals_settings = {
local valid_nvim_metals_settings = {
"decorationColor",
"disabledMode",
"langoustineTracing",
"metalsBinaryPath",
"serverOrg",
"serverVersion",
Expand Down

0 comments on commit c36ead3

Please sign in to comment.