Skip to content

Commit 4483ac6

Browse files
committed
updating with .md viewer
1 parent 4bb0089 commit 4483ac6

File tree

5 files changed

+713
-4
lines changed

5 files changed

+713
-4
lines changed

init.lua

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,16 @@ require('lazy').setup({
562562
-- or a suggestion from your LSP for this to activate.
563563
map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
564564

565+
-- Organize imports (Python via Pyright code actions)
566+
map('<leader>co', function()
567+
vim.lsp.buf.code_action({
568+
context = {
569+
only = { 'source.organizeImports' },
570+
},
571+
apply = true,
572+
})
573+
end, '[C]ode [O]rganize Imports')
574+
565575
-- WARN: This is not Goto Definition, this is Goto Declaration.
566576
-- For example, in C this would take you to the header.
567577
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
@@ -673,8 +683,21 @@ require('lazy').setup({
673683
local servers = {
674684
-- clangd = {},
675685
-- gopls = {},
676-
pyright = {},
677-
jdtls = {},
686+
pyright = {
687+
settings = {
688+
python = {
689+
analysis = {
690+
autoSearchPaths = true,
691+
useLibraryCodeForTypes = true,
692+
diagnosticMode = 'workspace',
693+
typeCheckingMode = 'basic',
694+
autoImportCompletions = true,
695+
},
696+
},
697+
},
698+
},
699+
-- NOTE: jdtls is configured separately via nvim-jdtls plugin (see custom/plugins/jdtls.lua)
700+
-- Do not configure it here as it requires special handling
678701
-- rust_analyzer = {},
679702
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
680703
--
@@ -717,6 +740,11 @@ require('lazy').setup({
717740
local ensure_installed = vim.tbl_keys(servers or {})
718741
vim.list_extend(ensure_installed, {
719742
'stylua', -- Used to format Lua code
743+
'jdtls', -- Java language server
744+
'java-debug-adapter', -- Java debugger
745+
'java-test', -- Java test runner
746+
'isort', -- Python import organizer
747+
'black', -- Python formatter
720748
})
721749
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
722750

@@ -725,6 +753,10 @@ require('lazy').setup({
725753
automatic_installation = false,
726754
handlers = {
727755
function(server_name)
756+
-- Skip jdtls as it's configured separately via nvim-jdtls plugin
757+
if server_name == 'jdtls' then
758+
return
759+
end
728760
local server = servers[server_name] or {}
729761
-- This handles overriding only values explicitly passed
730762
-- by the server configuration above. Useful when disabling
@@ -772,7 +804,7 @@ require('lazy').setup({
772804
formatters_by_ft = {
773805
lua = { 'stylua' },
774806
-- Conform can also run multiple formatters sequentially
775-
-- python = { "isort", "black" },
807+
python = { "isort", "black" },
776808
--
777809
-- You can use 'stop_after_first' to run the first available formatter from the list
778810
-- javascript = { "prettierd", "prettier", stop_after_first = true },
@@ -1006,7 +1038,7 @@ require('lazy').setup({
10061038
-- This is the easiest way to modularize your config.
10071039
--
10081040
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
1009-
-- { import = 'custom.plugins' },
1041+
{ import = 'custom.plugins' },
10101042
--
10111043
-- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
10121044
-- Or use telescope!

lua/custom/maven.lua

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
-- Maven command runner with UI
2+
local M = {}
3+
4+
-- Store last command for quick re-run
5+
M.last_command = nil
6+
7+
-- Common Maven phases and goals
8+
M.maven_commands = {
9+
-- Lifecycle Phases
10+
{ name = "clean", desc = "Clean the project (remove target/)" },
11+
{ name = "validate", desc = "Validate project structure" },
12+
{ name = "compile", desc = "Compile source code" },
13+
{ name = "test", desc = "Run unit tests" },
14+
{ name = "test-compile", desc = "Compile test sources" },
15+
{ name = "package", desc = "Package compiled code (JAR/WAR)" },
16+
{ name = "verify", desc = "Run integration tests" },
17+
{ name = "install", desc = "Install package to local repository" },
18+
{ name = "deploy", desc = "Deploy to remote repository" },
19+
20+
-- Common Combined Commands
21+
{ name = "clean compile", desc = "Clean and compile" },
22+
{ name = "clean test", desc = "Clean and test" },
23+
{ name = "clean package", desc = "Clean and package" },
24+
{ name = "clean install", desc = "Clean and install" },
25+
26+
-- Plugin Goals
27+
{ name = "dependency:tree", desc = "Display dependency tree" },
28+
{ name = "dependency:analyze", desc = "Analyze dependencies" },
29+
{ name = "versions:display-dependency-updates", desc = "Check for dependency updates" },
30+
{ name = "help:effective-pom", desc = "Show effective POM" },
31+
32+
-- Spring Boot specific (if applicable)
33+
{ name = "spring-boot:run", desc = "Run Spring Boot application" },
34+
35+
-- Testing specific
36+
{ name = "test -Dtest=", desc = "Run specific test class (specify after =)", custom_input = true },
37+
{ name = "test -Dtest=*Test", desc = "Run all test classes" },
38+
{ name = "surefire-report:report", desc = "Generate test report" },
39+
}
40+
41+
-- Execute Maven command
42+
function M.execute_maven(cmd, opts)
43+
opts = opts or {}
44+
45+
-- Check if mvn exists
46+
local mvn_cmd = vim.fn.executable("mvn") == 1 and "mvn" or nil
47+
if not mvn_cmd then
48+
vim.notify("Maven (mvn) not found in PATH. Install with: brew install maven", vim.log.levels.ERROR)
49+
return
50+
end
51+
52+
-- Store last command
53+
M.last_command = cmd
54+
55+
-- Determine if we're in a Maven project
56+
local pom_exists = vim.fn.filereadable(vim.fn.getcwd() .. "/pom.xml") == 1
57+
if not pom_exists then
58+
vim.notify("No pom.xml found in current directory: " .. vim.fn.getcwd(), vim.log.levels.WARN)
59+
local proceed = vim.fn.confirm("Run Maven anyway?", "&Yes\n&No", 2)
60+
if proceed ~= 1 then
61+
return
62+
end
63+
end
64+
65+
local full_cmd = "mvn " .. cmd
66+
67+
-- Choose display method based on preference
68+
if opts.background then
69+
-- Run in background, show in quickfix
70+
vim.notify("Running: " .. full_cmd, vim.log.levels.INFO)
71+
vim.fn.setqflist({}, 'r', { title = full_cmd, lines = {} })
72+
vim.cmd("copen")
73+
74+
vim.fn.jobstart(full_cmd, {
75+
on_stdout = function(_, data)
76+
if data then
77+
vim.fn.setqflist({}, 'a', { lines = data })
78+
end
79+
end,
80+
on_stderr = function(_, data)
81+
if data then
82+
vim.fn.setqflist({}, 'a', { lines = data })
83+
end
84+
end,
85+
on_exit = function(_, exit_code)
86+
if exit_code == 0 then
87+
vim.notify("Maven command completed successfully", vim.log.levels.INFO)
88+
else
89+
vim.notify("Maven command failed with exit code: " .. exit_code, vim.log.levels.ERROR)
90+
end
91+
end,
92+
})
93+
else
94+
-- Run in terminal split
95+
vim.cmd("botright 15split | terminal " .. full_cmd)
96+
vim.cmd("startinsert")
97+
end
98+
end
99+
100+
-- Show Maven menu using vim.ui.select
101+
function M.show_menu()
102+
local choices = {}
103+
for i, cmd in ipairs(M.maven_commands) do
104+
choices[i] = string.format("%-40s | %s", cmd.name, cmd.desc)
105+
end
106+
107+
vim.ui.select(choices, {
108+
prompt = "Select Maven command:",
109+
format_item = function(item)
110+
return item
111+
end,
112+
}, function(choice, idx)
113+
if not choice then
114+
return
115+
end
116+
117+
local selected = M.maven_commands[idx]
118+
119+
-- Handle custom input commands
120+
if selected.custom_input then
121+
vim.ui.input({
122+
prompt = "Enter Maven command: ",
123+
default = selected.name,
124+
}, function(input)
125+
if input and input ~= "" then
126+
M.execute_maven(input)
127+
end
128+
end)
129+
else
130+
M.execute_maven(selected.name)
131+
end
132+
end)
133+
end
134+
135+
-- Run last Maven command
136+
function M.run_last()
137+
if M.last_command then
138+
vim.notify("Re-running: mvn " .. M.last_command, vim.log.levels.INFO)
139+
M.execute_maven(M.last_command)
140+
else
141+
vim.notify("No previous Maven command to run", vim.log.levels.WARN)
142+
M.show_menu()
143+
end
144+
end
145+
146+
-- Quick command to run specific test
147+
function M.run_test(test_name)
148+
if test_name then
149+
M.execute_maven("test -Dtest=" .. test_name)
150+
else
151+
-- Try to infer test name from current file
152+
local current_file = vim.fn.expand("%:t:r") -- filename without extension
153+
if current_file:match("Test$") or current_file:match("Tests$") then
154+
vim.ui.input({
155+
prompt = "Test class name:",
156+
default = current_file,
157+
}, function(input)
158+
if input and input ~= "" then
159+
M.execute_maven("test -Dtest=" .. input)
160+
end
161+
end)
162+
else
163+
M.execute_maven("test")
164+
end
165+
end
166+
end
167+
168+
-- User command to run Maven
169+
vim.api.nvim_create_user_command("Maven", function(opts)
170+
if opts.args and opts.args ~= "" then
171+
M.execute_maven(opts.args)
172+
else
173+
M.show_menu()
174+
end
175+
end, {
176+
nargs = "*",
177+
desc = "Run Maven command",
178+
complete = function()
179+
local completions = {}
180+
for _, cmd in ipairs(M.maven_commands) do
181+
table.insert(completions, cmd.name)
182+
end
183+
return completions
184+
end,
185+
})
186+
187+
-- User command to run tests
188+
vim.api.nvim_create_user_command("MavenTest", function(opts)
189+
M.run_test(opts.args ~= "" and opts.args or nil)
190+
end, {
191+
nargs = "?",
192+
desc = "Run Maven tests",
193+
})
194+
195+
return M

0 commit comments

Comments
 (0)