Skip to content

Commit 1b87e6b

Browse files
authored
Merge pull request #677 from ckipp01/refactorInfo
refactor: remove Metals version info from Info
2 parents 4fc2bf7 + d3e83e7 commit 1b87e6b

File tree

1 file changed

+48
-72
lines changed

1 file changed

+48
-72
lines changed

lua/metals.lua

Lines changed: 48 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -122,83 +122,59 @@ M.generate_bsp_config = function()
122122
execute_command({ command = "metals.generate-bsp-config" })
123123
end
124124

125-
-- Capture info about the currently installed Metals and display it in a
126-
-- floating window.
125+
-- Capture info about your Metals settings and display it in a floating window.
127126
M.info = function()
128127
local config = conf.get_config_cache()
129-
if not util.has_bins(conf.metals_bin()) and config and config.settings.metals.useGlobalExecutable then
130-
log.error_and_show(messages.use_global_set_but_cant_find)
131-
elseif not util.has_bins(conf.metals_bin()) and config and config.settings.metals.metalsBinaryPath then
132-
log.error_and_show(messages.binary_path_set_but_cant_find)
133-
elseif not util.has_bins(conf.metals_bin()) then
134-
log.warn_and_show(messages.metals_not_installed)
135-
else
136-
local output = {}
137-
138-
local metals_info = fn.system(conf.metals_bin() .. " --version")
139-
if metals_info then
140-
for s in metals_info:gmatch("[^\r\n]+") do
141-
-- A little hacky but the version output is weird and we want to coerce
142-
-- it to markdown, so we give the verstion line a # and then strip the
143-
-- other lines of their #
144-
if util.starts_with(s, "#") then
145-
table.insert(output, s:sub(2))
146-
else
147-
table.insert(output, "# " .. s)
148-
end
149-
end
150-
end
128+
local output = {}
151129

152-
if config and config.settings.metals then
153-
table.insert(output, "")
154-
table.insert(output, "## Current settings")
155-
table.insert(output, "```json")
156-
for s in vim.inspect(config.settings.metals):gmatch("[^\r\n]+") do
157-
table.insert(output, s)
158-
end
159-
table.insert(output, "```")
130+
if config and config.settings.metals then
131+
table.insert(output, "## Current settings")
132+
table.insert(output, "```json")
133+
for s in vim.inspect(config.settings.metals):gmatch("[^\r\n]+") do
134+
table.insert(output, s)
160135
end
161-
table.insert(output, "")
162-
table.insert(output, "## Useful locations")
163-
table.insert(output, string.format(" - nvim-metals log file: %s", log.nvim_metals_log))
164-
table.insert(output, string.format(" - nvim lsp log file: %s", lsp.get_log_path()))
165-
local loc_msg = " - metals install location:"
166-
if config and config.settings.metals.useGlobalExecutable then
167-
table.insert(output, string.format("%s %s", loc_msg, "Using metals executable on $PATH"))
168-
else
169-
table.insert(output, string.format("%s %s", loc_msg, conf.metals_bin()))
170-
end
171-
table.insert(output, "")
172-
table.insert(output, "## Helpful links")
173-
table.insert(output, " - https://discord.gg/FaVDrJegEh")
174-
table.insert(output, " - https://matrix.to/#/#scalameta:vim-users")
175-
table.insert(output, " - https://github.com/scalameta/nvim-metals")
176-
table.insert(output, " - https://github.com/scalameta/metals")
177-
178-
output = vim.split(table.concat(output, "\n"), "\n", { trimempty = true })
179-
180-
local float = Float.percentage_range_window(0.6, 0.4, { winblend = 0 }, {
181-
title = "Metals Info",
182-
titlehighlight = "MetalsTitle",
183-
topleft = "",
184-
topright = "",
185-
top = "",
186-
left = "",
187-
right = "",
188-
botleft = "",
189-
botright = "",
190-
bot = "",
191-
})
192-
-- It's seemingly impossibly to get the hl to work for me with Float, so we
193-
-- just manually set them here.
194-
api.nvim_set_option_value("winhl", "NormalFloat:Normal", { win = float.win_id })
195-
api.nvim_set_option_value("winhl", "NormalFloat:Normal", { win = float.border_win_id })
196-
197-
api.nvim_set_option_value("filetype", "markdown", { buf = float.bufnr })
198-
api.nvim_buf_set_lines(float.bufnr, 0, -1, false, output)
199-
api.nvim_buf_set_keymap(float.bufnr, "n", "q", "<cmd>close!<CR>", { nowait = true, noremap = true, silent = true })
200-
api.nvim_set_option_value("readonly", true, { buf = float.bufnr })
136+
table.insert(output, "```")
201137
end
138+
table.insert(output, "")
139+
table.insert(output, "## Useful locations")
140+
table.insert(output, string.format(" - nvim-metals log file: %s", log.nvim_metals_log))
141+
table.insert(output, string.format(" - nvim lsp log file: %s", lsp.get_log_path()))
142+
local loc_msg = " - metals install location:"
143+
if config and config.settings.metals.useGlobalExecutable then
144+
table.insert(output, string.format("%s %s", loc_msg, "Using metals executable on $PATH"))
145+
else
146+
table.insert(output, string.format("%s %s", loc_msg, conf.metals_bin()))
147+
end
148+
table.insert(output, "")
149+
table.insert(output, "## Helpful links")
150+
table.insert(output, " - https://discord.gg/FaVDrJegEh")
151+
table.insert(output, " - https://matrix.to/#/#scalameta:vim-users")
152+
table.insert(output, " - https://github.com/scalameta/nvim-metals")
153+
table.insert(output, " - https://github.com/scalameta/metals")
154+
155+
output = vim.split(table.concat(output, "\n"), "\n", { trimempty = true })
156+
157+
local float = Float.percentage_range_window(0.6, 0.4, { winblend = 0 }, {
158+
title = "Metals Info",
159+
titlehighlight = "MetalsTitle",
160+
topleft = "",
161+
topright = "",
162+
top = "",
163+
left = "",
164+
right = "",
165+
botleft = "",
166+
botright = "",
167+
bot = "",
168+
})
169+
-- It's seemingly impossibly to get the hl to work for me with Float, so we
170+
-- just manually set them here.
171+
api.nvim_set_option_value("winhl", "NormalFloat:Normal", { win = float.win_id })
172+
api.nvim_set_option_value("winhl", "NormalFloat:Normal", { win = float.border_win_id })
173+
174+
api.nvim_set_option_value("filetype", "markdown", { buf = float.bufnr })
175+
api.nvim_buf_set_lines(float.bufnr, 0, -1, false, output)
176+
api.nvim_buf_set_keymap(float.bufnr, "n", "q", "<cmd>close!<CR>", { nowait = true, noremap = true, silent = true })
177+
api.nvim_set_option_value("readonly", true, { buf = float.bufnr })
202178
end
203179

204180
M.toggle_logs = conf.toggle_logs

0 commit comments

Comments
 (0)