Skip to content

Commit

Permalink
Add user commands to set and show active maven profiles (#688)
Browse files Browse the repository at this point in the history
Co-authored-by: Mathias Fussenegger <[email protected]>
  • Loading branch information
JavaHello and mfussenegger authored Sep 26, 2024
1 parent 99e4b20 commit efe8138
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lua/jdtls/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ end
---@param client vim.lsp.Client
---@param opts jdtls.start.opts
local function add_commands(client, bufnr, opts)

---@param name string
local function create_cmd(name, command, cmdopts)
api.nvim_buf_create_user_command(bufnr, name, command, cmdopts or {})
end
Expand Down Expand Up @@ -252,6 +254,45 @@ local function add_commands(client, bufnr, opts)
desc = "Trigger reload of changed classes for current debug session",
})
end
local selected_profiles = "org.eclipse.m2e.core.selectedProfiles"
local util = require("jdtls.util")
create_cmd("JdtUpdateMavenActiveProfiles", function (o)
local active_profiles = o.args
local settings = {
[selected_profiles] = active_profiles
}
local params = {
command = "java.project.updateSettings",
arguments = { vim.uri_from_bufnr(bufnr), settings },
}
util.execute_command(params)
end, {
nargs = "?",
})
create_cmd("JdtShowMavenActiveProfiles", function (_)
local params = {
command = "java.project.getSettings",
arguments = {
vim.uri_from_bufnr(bufnr),
{ selected_profiles },
},
}
local function on_response(err, resp)
if err then
vim.notify("Could not resolve active maven profiles: " .. vim.inspect(err), vim.log.levels.WARN)
else
local profiles = resp[selected_profiles]
if profiles and profiles ~= "" then
vim.notify("Active profiles: " .. profiles, vim.log.levels.INFO)
else
vim.notify("No active profiles", vim.log.levels.INFO)
end
end
end
util.execute_command(params, on_response, bufnr)
end, {
nargs = 0,
})
end


Expand Down

0 comments on commit efe8138

Please sign in to comment.