Repository navigation
Expand file tree
/
Copy pathexample-nvim.lua
More file actions
89 lines (77 loc) · 2.43 KB
/
Copy pathexample-nvim.lua
File metadata and controls
89 lines (77 loc) · 2.43 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local javalyzer = "javalyzer"
-- local javalyzer = "/path/to/javalyzer"
local filetypes = { "java", "jproperties", "yaml" }
local root_markers = {
"settings.gradle",
"settings.gradle.kts",
"build.gradle",
"build.gradle.kts",
"pom.xml",
".git",
}
local status_by_client = {}
local function on_status(_, result, ctx)
status_by_client[ctx.client_id] = result
vim.cmd("redrawstatus")
end
function JavalyzerStatus()
for _, client in ipairs(vim.lsp.get_clients({ bufnr = 0, name = "javalyzer" })) do
local status = status_by_client[client.id]
if status then
local text = "javalyzer: " .. status.activity
if status.activity == "indexing" then
text = text .. " " .. status.filesIndexed .. "/" .. status.filesTotal
end
if status.build == "untrusted" then
text = text .. " (untrusted)"
end
return text
end
end
return ""
end
vim.api.nvim_create_autocmd("FileType", {
pattern = filetypes,
callback = function(args)
local name = vim.api.nvim_buf_get_name(args.buf)
if name == "" then
return
end
vim.lsp.start({
name = "javalyzer",
cmd = { javalyzer },
root_dir = vim.fs.root(args.buf, root_markers) or vim.fs.dirname(name),
settings = {
javalyzer = {
-- Change to true to allow gradle/maven to be used
trustWorkspace = false,
formatOnSave = false,
organizeImportsOnSave = false,
formatStyle = "default",
-- A line of text above every declaration, so it is opt-in.
codeLens = false,
logLevel = "info",
},
},
handlers = {
["javalyzer/status"] = on_status,
},
on_attach = function(client, bufnr)
local function map(keys, fn, description)
vim.keymap.set("n", keys, fn, { buffer = bufnr, desc = description })
end
map("gd", vim.lsp.buf.definition, "go to definition")
map("gr", vim.lsp.buf.references, "list references")
map("K", vim.lsp.buf.hover, "hover")
map("<leader>rn", vim.lsp.buf.rename, "rename")
map("<leader>ca", vim.lsp.buf.code_action, "code action")
if client.server_capabilities.documentFormattingProvider then
map("<leader>f", function()
vim.lsp.buf.format({ bufnr = bufnr })
end, "format")
end
end,
}, { bufnr = args.buf })
end,
})
-- vim.o.statusline = "%f %{v:lua.JavalyzerStatus()}"