summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyren223 <contact@kyren.codes>2026-06-23 13:57:40 +0300
committerKyren223 <contact@kyren.codes>2026-06-23 13:57:40 +0300
commit9ad2a8e0486e6f8b522d303c54a0fb8294b79cd0 (patch)
tree53034b4cfe8be33e540184501684f35dab756c47
parent1e9ddece1574c79213588aef496026d875fa8168 (diff)
Sort jdtls code actions and completions based on packages I prefer, and
add static import to certain Kapi procs
-rw-r--r--.config/nvim/lua/plugins/blink-cmp.lua26
-rw-r--r--.config/nvim/lua/plugins/nvim-jdtls.lua64
2 files changed, 90 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/blink-cmp.lua b/.config/nvim/lua/plugins/blink-cmp.lua
index fdf6d87..0c3f6d5 100644
--- a/.config/nvim/lua/plugins/blink-cmp.lua
+++ b/.config/nvim/lua/plugins/blink-cmp.lua
@@ -108,6 +108,32 @@ return {
end, items)
end,
},
+
+ lsp = {
+ name = 'lsp',
+ module = 'blink.cmp.sources.lsp',
+ transform_items = function(ctx, items)
+ if vim.bo[ctx.bufnr].filetype == 'java' then
+ local java_package_weights = require('plugins.nvim-jdtls').java_package_weights
+
+ for _, item in ipairs(items) do
+ -- jdtls puts the fully qualified package path inside 'detail'
+ local detail = item.detail or ''
+ if detail ~= '' then
+ for pattern, weight in pairs(java_package_weights) do
+ pattern = '^' .. pattern
+ if detail:match(pattern) then
+ item.score_offset = weight
+ break -- Match found, move to the next item
+ end
+ end
+ end
+ end
+ end
+
+ return items
+ end,
+ },
},
},
diff --git a/.config/nvim/lua/plugins/nvim-jdtls.lua b/.config/nvim/lua/plugins/nvim-jdtls.lua
index 4929199..6f55aef 100644
--- a/.config/nvim/lua/plugins/nvim-jdtls.lua
+++ b/.config/nvim/lua/plugins/nvim-jdtls.lua
@@ -1,3 +1,11 @@
+local java_package_weights = {
+ ['codes%.kyren'] = 100,
+ ['org%.bukkit'] = 100,
+ ['io%.papermc'] = 100,
+ ['org%.jspecify'] = 80,
+ ['org%.jetbrains'] = 80,
+ ['net%.minecraft'] = 50,
+}
return {
'mfussenegger/nvim-jdtls',
ft = { 'java' },
@@ -22,6 +30,15 @@ return {
-- Safely mix standard blink capabilities with internal jdtls mappings
local lsp_capabilities = require('blink.cmp').get_lsp_capabilities()
+ local function get_action_weight(title)
+ for pattern, weight in pairs(java_package_weights) do
+ if title:match(pattern) then
+ return weight
+ end
+ end
+ return 0 -- Neutral weight for untracked packages
+ end
+
local opts = {
cmd = { 'jdtls', '-data', workspace_dir },
root_dir = root_dir,
@@ -57,6 +74,12 @@ return {
-- Stops jdtls from injecting variable placeholders when autocompleting
guessMethodArguments = 'off',
+ favoriteStaticMembers = {
+ 'codes.kyren.kapi.Kapi.expect',
+ 'codes.kyren.kapi.Kapi.panic',
+ 'codes.kyren.kapi.Kapi.unreachable',
+ },
+
filteredTypes = {
'edu.umd.cs.findbugs.*',
'javax.annotation.*',
@@ -79,6 +102,46 @@ return {
},
},
},
+
+ on_attach = function(client, bufnr)
+ if client._code_action_sorted then
+ return
+ end
+ client._code_action_sorted = true
+
+ -- Hook into the absolute lowest-level RPC pipe.
+ -- This catches 100% of traffic, bypassing any plugin API overrides.
+ local orig_rpc_request = client.rpc.request
+
+ client.rpc.request = function(method, params, handler, ...)
+ if method == 'textDocument/codeAction' then
+ local wrapped_handler = function(err, result, ctx, config)
+ if not err and result and type(result) == 'table' then
+ -- Sort the raw array (Respected by native vim.ui.select)
+ table.sort(result, function(a, b)
+ local title_a = a.title or ''
+ local title_b = b.title or ''
+ local weight_a = get_action_weight(title_a)
+ local weight_b = get_action_weight(title_b)
+
+ if weight_a ~= weight_b then
+ return weight_a > weight_b
+ end
+ return title_a < title_b
+ end)
+ end
+
+ if handler then
+ return handler(err, result, ctx, config)
+ end
+ end
+
+ return orig_rpc_request(method, params, wrapped_handler, ...)
+ end
+
+ return orig_rpc_request(method, params, handler, ...)
+ end
+ end,
}
require('jdtls').start_or_attach(opts)
@@ -91,4 +154,5 @@ return {
callback = setup_jdtls,
})
end,
+ java_package_weights = java_package_weights,
}