Repository navigation
Expand file tree
/
Copy pathcommands.lua
More file actions
73 lines (68 loc) · 2.33 KB
/
Copy pathcommands.lua
File metadata and controls
73 lines (68 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local M = {}
--- The symbol queries the language server understands, in the order they are
--- offered. `@` is every Spring annotation, `@+` bean definitions, `@/`
--- request mappings and `@>` prototypes.
--- see https://github.com/spring-projects/sts4/wiki/Boot-Java-Editor-Support#symbol-search
local SYMBOL_QUERIES = {
{ name = "Annotations", query = "@", description = "shows all Spring annotations in the code" },
{ name = "Beans", query = "@+", description = "shows all defined beans" },
{ name = "RequestMappings", query = "@/", description = "shows all defined request mappings" },
{ name = "Prototype", query = "@>", description = "shows all functions (prototype implementation)" },
}
---@param name string
---@return { name: string, query: string, description: string }?
local function symbol_query(name)
for _, entry in ipairs(SYMBOL_QUERIES) do
if entry.name == name then
return entry
end
end
end
---@param choice string
local function find_symbols(choice)
local entry = symbol_query(choice)
if not entry then
local names = vim.tbl_map(function(e)
return e.name
end, SYMBOL_QUERIES)
vim.notify(
("spring_boot: unknown symbol query '%s', expected one of %s"):format(choice, table.concat(names, ", ")),
vim.log.levels.WARN
)
return
end
local buf = vim.api.nvim_get_current_buf()
if #vim.lsp.get_clients({ name = "spring-boot", bufnr = buf }) == 0 then
vim.notify("spring_boot: no Spring Boot language server on this buffer", vim.log.levels.WARN)
return
end
vim.lsp.buf.workspace_symbol(entry.query)
end
--- Registers the user commands of the plugin. Safe to call more than once.
M.register = function()
vim.api.nvim_create_user_command("SpringBoot", function(args)
if args.args ~= "" then
find_symbols(args.args)
return
end
vim.ui.select(SYMBOL_QUERIES, {
prompt = "Spring Symbol:",
format_item = function(entry)
return ("%s - %s"):format(entry.name, entry.description)
end,
}, function(entry)
if entry then
find_symbols(entry.name)
end
end)
end, {
desc = "Find Spring Boot symbols: annotations, beans, request mappings, prototypes",
nargs = "?",
complete = function()
return vim.tbl_map(function(entry)
return entry.name
end, SYMBOL_QUERIES)
end,
})
end
return M