Skip to content

Commit

Permalink
chore: various improvements and merge w/ nvim branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Manca committed Jan 7, 2025
1 parent 90242d1 commit 486085b
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 127 deletions.
74 changes: 4 additions & 70 deletions after/ftplugin/java.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ local extendedClientCapabilities = require("jdtls").extendedClientCapabilities
extendedClientCapabilities.resolveAdditionalTextEditsSupport = true
extendedClientCapabilities.document_formatting = false

local root_dir = vim.fs.root(0, { ".git", "mvnw", "gradlew", "pom.xml" }) or vim.fs.dirname(vim.api.nvim_buf_get_name(0))
local root_dir = vim.fs.root(0, { ".git", "mvnw", "gradlew", "pom.xml" })
or vim.fs.dirname(vim.api.nvim_buf_get_name(0))
local cache_dir = vim.fn.stdpath "cache"
local project_name = vim.fs.basename(root_dir)
local project_name = vim.fs.basename(root_dir or vim.uv.cwd())
local workspace_dir = string.format("%s/java/wksp/%s", cache_dir, project_name)

local launcher_path = vim.fn.glob(data_path .. "/mason/packages/jdtls/plugins/org.eclipse.equinox.launcher_*.jar", true)
Expand Down Expand Up @@ -296,71 +297,4 @@ vim.api.nvim_create_autocmd({ "BufWritePost" }, {
end,
})

if vim.fn.filereadable(root_dir .. "/gradlew") then
local gradlew = root_dir .. "/gradlew"

local function get_gradle_tasks()
if vim.g["gradle_" .. root_dir] ~= nil then
return vim.g["gradle_" .. root_dir]
end

local taskList = {}
local out = vim.system({ gradlew, "tasks", "--all" }, { text = true }):wait()
if out.code == 0 then
for line in out.stdout:gmatch "[^\r\n]+" do
if line:find " - " then
local taskName = line:match "^(.-)%s+-" --line:match("^(.-) -")
if taskName then
table.insert(taskList, taskName)
end
end
end
vim.g["gradle_" .. root_dir] = taskList
else
vim.notify("Error executing command: " .. out.stderr, vim.log.levels.ERROR, { text = "Gradle (tasks)" })
end
return taskList
end

local function select_gradle_task(tasks, callback)
vim.ui.select(tasks, {
prompt = "⟩ Gradle task: ",
}, function(choice)
if not choice then
return
end
callback(choice)
end)
end

local function run_gradle_task(task)
local msg = string.format(" running: < gradlew %s >", task)
vim.notify(msg, vim.log.levels.INFO, { title = "Gradle" })
vim.system({ gradlew, task }, { text = true }, function(obj)
if obj.code ~= 0 then
vim.notify(obj.stderr, vim.log.levels.WARN)
else
vim.print(obj.stdout)
vim.schedule(function()
vim.fn.setqflist({}, "r", { title = "Gradle Output", lines = vim.split(obj.stdout, "\n") })
vim.cmd.copen()
end)
end
end)
end

vim.api.nvim_create_user_command("Gradle", function(input)
local task = nil
if input.args ~= "" then
run_gradle_task(task)
else
local tasks = get_gradle_tasks()
select_gradle_task(tasks, function(selected_task)
run_gradle_task(selected_task)
end)
end
end, {
nargs = "?",
complete = get_gradle_tasks,
})
end
require("lib.gradle").setup { root_dir = root_dir }
116 changes: 116 additions & 0 deletions lua/lib/gradle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-------------------------------------
-- File : gradle.lua
-- Description : gradle utils functions
-- Author : Kevin
-- Last Modified: 06/01/2025 - 12:19
-------------------------------------

local M = {}

---Get Gradle tasks for the project
---@param gradlew string the path for the gradle
---@param root_dir string the root directory of the project
local function get_gradle_tasks(gradlew, root_dir)
if vim.g["gradle_" .. root_dir] ~= nil then
return vim.g["gradle_" .. root_dir]
end

local taskList = {}
local out = vim.system({ gradlew, "tasks", "--all" }, { text = true }):wait()
if out.code == 0 then
for line in out.stdout:gmatch "[^\r\n]+" do
if line:find " - " then
local taskName = line:match "^(.-)%s+-" --line:match("^(.-) -")
if taskName then
table.insert(taskList, taskName)
end
end
end
vim.g["gradle_" .. root_dir] = taskList
else
vim.notify("Error executing command: " .. out.stderr, vim.log.levels.ERROR, { text = "Gradle (tasks)" })
end
return taskList
end

local function run_gradle_task(gradlew, task)
local msg = string.format(" running: < gradlew %s >", task)
-- vim.notify(msg, 2, { title = "Gradle" })
print("Gradle⟩ " .. msg)
vim.system({ gradlew, task }, { text = true }, function(obj)
local out = (obj.code ~= 0) and obj.stderr or obj.stdout

vim.schedule(function()
local text = string.format(" OUTPUT⟩ gradle %s\n\n%s", task, out)
local lines = vim.split(text, "\n")

local buf = vim.api.nvim_create_buf(false, true)

vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
local height = math.floor(vim.o.lines * 0.25)
local win = vim.api.nvim_open_win(buf, true, {
height = height,
win = -1,
split = "below",
})
vim.api.nvim_set_option_value("buftype", "nofile", { buf = buf })
vim.api.nvim_set_option_value("swapfile", false, { buf = buf })
vim.api.nvim_set_option_value("bufhidden", "wipe", { buf = buf })
vim.api.nvim_set_option_value("filetype", "sh", { buf = buf })
vim.api.nvim_set_option_value("number", false, { win = win })
vim.api.nvim_set_option_value("relativenumber", false, { win = win })

vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = buf })
vim.keymap.set("n", "<esc>", "<cmd>close<cr>", { buffer = buf })
end)
end)
end

local function select_and_run_gradle_task(gradlew, tasks)
vim.ui.select(tasks, {
prompt = "⟩ Gradle task: ",
}, function(choice)
if not choice then
return
end
run_gradle_task(gradlew, choice)
end)
end

---Setup Gradle module
---@param opts table
function M.setup(opts)
local root_dir = opts.root_dir or nil

if not root_dir then
vim.notify("root_dir not passed!", vim.log.levels.ERROR, { title = "Gradle" })
return
end

if not vim.fn.filereadable(root_dir .. "/gradlew") then
vim.notify("No gradlew bin found for the path\n" .. root_dir, vim.log.levels.WARN, { title = "Gradle" })
return
end

local gradlew = root_dir .. "/gradlew"

vim.api.nvim_create_user_command("Gradle", function(input)
local task = nil
if input.args ~= "" then
run_gradle_task(gradlew, task)
else
local tasks = get_gradle_tasks(gradlew, root_dir)
select_and_run_gradle_task(gradlew, tasks)
end
end, {
nargs = "?",
complete = get_gradle_tasks,
})

vim.keymap.set("n", "<leader>dg", function()
local tasks = get_gradle_tasks(gradlew, root_dir)
select_and_run_gradle_task(gradlew, tasks)
end, { desc = "Gradle", buffer = true })
end

return M
3 changes: 1 addition & 2 deletions lua/lib/notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
local note = {}

---Get available notes
---@private
---@return table
local function get_notes()
local notes = {}
Expand Down Expand Up @@ -75,4 +74,4 @@ function note.open_note()
end
end

return note
return note
3 changes: 2 additions & 1 deletion lua/lib/ui/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ local sl = {
dapui_hover = "󰃤",
dapui_watches = "󰃤",
default = "",
gradle = "",
}, {
__index = function(t, k)
local has_icons, icons = pcall(require, "mini.icons")
Expand Down Expand Up @@ -366,7 +367,7 @@ end
---Get lsp status and if active get names of server running
---@return string lsp_status
local function get_lsp_info()
return #vim.lsp.get_clients() ~= 0 and string.format("%s• ", sl.colors.name)
return #vim.lsp.get_clients { bufnr = 0 } ~= 0 and string.format("%s• ", sl.colors.name)
or string.format("%s• ", sl.colors.lspnoactive)
end

Expand Down
1 change: 1 addition & 0 deletions lua/plugins/editor/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ return {
["<C-Space>"] = { "show", "hide" },
["<C-e>"] = { "cancel" },
},
ghost_text = { enabled = true },
},
appearance = {
nerd_font_variant = "mono",
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ local M = {
---LaTeX
{
"lervag/vimtex",
ft = { "tex", "plaintex" },
ft = { "tex", "plaintex", "bib" },
config = function()
vim.g.vimtex_view_method = "sioyek"
vim.g.vimtex_quickfix_mode = 0 -- don't open qflist on compile errors
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/lsp/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ return {
},
})
end,
}
}
6 changes: 3 additions & 3 deletions lua/plugins/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local function set_buf_keymaps(client, bufnr)
local _, tele_builtin = pcall(require, "telescope.builtin")

local function nmap(tbl)
vim.keymap.set("n", tbl[1], tbl[2], { buffer = bufnr, desc = "LSP" .. tbl[3] })
vim.keymap.set("n", tbl[1], tbl[2], { buffer = bufnr, desc = "Lsp" .. tbl[3] })
end

nmap {
Expand Down Expand Up @@ -66,9 +66,9 @@ local function set_buf_keymaps(client, bufnr)
end

if client.supports_method "textDocument/signatureHelp" then
vim.keymap.set("s", "<C-space>", vim.lsp.buf.signature_help, {
vim.keymap.set("s", "<C-x><C-space>", vim.lsp.buf.signature_help, {
buffer = bufnr,
desc = "LSP❭ SignatureHelp",
desc = "Lsp❭ SignatureHelp",
})
end

Expand Down
4 changes: 2 additions & 2 deletions lua/plugins/utils/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ return {

vim.keymap.set("n", "<localleader>r", function()
require("render-markdown").toggle()
end, { desc = "Render Markdown" })
end, { desc = "Render Markdown", buffer = true })
end,
}
}
14 changes: 5 additions & 9 deletions snippets/general/java/javadoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
" *",
" * ${2:Description.}$0",
" *",
" * @param ${4:name} ${5:Type and description of the parameter.}",
" * @return ${6:Type and description of the returned object.}",
" * @param ${4:name} ${5:Description of the parameter.}",
" * @return ${6:Description of the returned object.}",
" *",
" * @example",
" * ```",
" * ${7:Write me later}",
" * ```",
" */"
],
"description": "A Java comment block including short summary, description, param, return, and examples."
Expand All @@ -25,12 +21,12 @@
},
"@param": {
"prefix": "@param",
"body": ["@param ${1:name} ${2:Type and description of the parameter.}$0"],
"body": ["@param ${1:name} ${2:Description of the parameter.}$0"],
"description": "Documents a parameter."
},
"@return": {
"prefix": "@return",
"body": ["@param ${1:name} ${2:Type and description of the parameter.}$0"],
"body": ["@param ${1:name} ${2:Description of the parameter.}$0"],
"description": "Documents a the returned object."
},
"@example": {
Expand Down Expand Up @@ -96,4 +92,4 @@
],
"description": "The @deprecated description in the first sentence should at least tell the user when the API was deprecated and what to use as a replacement. Only the first sentence will appear in the summary section and index. Subsequent sentences can also explain why it has been deprecated."
}
}
}
Loading

0 comments on commit 486085b

Please sign in to comment.