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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
local function run_sonar()
local exe = vim.fn.exepath("sonar-scanner")
if exe == "" then
vim.notify("sonar-scanner nicht im PATH gefunden", vim.log.levels.ERROR)
return
end
if vim.fn.executable(exe) == 0 then
vim.notify("sonar-scanner ist nicht ausführbar", vim.log.levels.ERROR)
return
end
-- Suche nach *.properties im aktuellen Verzeichnis
local files = vim.fn.glob("*.properties", false, true)
local cmd = exe
if #files > 0 then
-- Optional: gezielt sonar-project.properties bevorzugen
local selected = nil
for _, f in ipairs(files) do
if f == "sonar-project.properties" then
selected = f
break
end
end
-- Falls keine Standarddatei, nimm die erste
if not selected then selected = files[1] end
cmd = cmd .. " -Dproject.settings=" .. selected
vim.notify("Verwende Properties: " .. selected, vim.log.levels.INFO)
else
vim.notify("Keine .properties Datei gefunden, nutze Default-Verhalten", vim.log.levels.WARN)
end
vim.cmd("botright split | terminal " .. cmd)
vim.cmd("norm G")
end
local function load_sonar_issues()
local cmd = vim.fn.stdpath("config") .. "/scripts/sonarqube.sh"
vim.fn.setqflist({}, " ", {
title = "SonarQube Issues",
lines = vim.fn.systemlist(cmd),
})
vim.cmd("copen")
end
local function disable_lsp()
for _, client in ipairs(vim.lsp.get_clients()) do
client:stop()
end
end
local function disable_lsp_buffer()
for _, client in ipairs(vim.lsp.get_clients({ bufnr = 0 })) do
client:stop()
end
end
local function enable_lsp()
vim.cmd("edit") -- triggert Reattach bei vielen Setups
end
local function update_parsers()
local install = require("nvim-treesitter.install")
local ts_config = require("nvim-treesitter.config")
local langs = require("config.treesitter").languages
-- install() installiert fehlende Parser, ueberspringt aber bereits
-- installierte unabhaengig von deren Revision. update() aktualisiert
-- nur bereits installierte Parser, ignoriert aber fehlende. Beides ist
-- ausserdem async (gibt einen Task zurueck statt zu blockieren) -
-- deshalb :wait(), damit z.B. headless-Aufrufe (nvim-update) nicht
-- vorzeitig per "qa" abgebrochen werden, bevor Download/Kompilierung
-- fertig sind.
install.install(langs, { summary = true }):wait()
install.update(langs, { summary = true }):wait()
-- summary = true meldet sich ueber vim.notify/log.info, das laeuft ueber
-- Neovims Message-Area. Im headless-Modus (kein UI) landet das nirgends
-- sichtbar. io.write schreibt direkt auf den Prozess-stdout und liefert
-- damit auch bei "nvim-update" eine verlaessliche Bestaetigung.
local installed = ts_config.get_installed("parsers")
local missing = vim.tbl_filter(function(l)
return not vim.list_contains(installed, l)
end, langs)
-- Fuehrendes "\n", falls die vorherige Zeile (z.B. von lazy.nvim) ohne
-- Zeilenumbruch endet, und explizites flush(), damit die Meldung nicht
-- im stdout-Puffer haengen bleibt, wenn "qa" direkt danach beendet.
if #missing > 0 then
io.write("\n[UpdateParsers] FEHLEND: " .. table.concat(missing, ", ") .. "\n")
else
io.write("\n[UpdateParsers] alle " .. #langs .. " Parser installiert/aktuell.\n")
end
io.stdout:flush()
end
-- sonar-scanner/scripts/sonarqube.sh sind POSIX-only (kein Windows-Pendant),
-- deshalb Kommandos unter Windows gar nicht erst registrieren statt sie
-- dort fehlschlagen zu lassen.
local is_windows = vim.fn.has("win32") == 1
if not is_windows then
vim.api.nvim_create_user_command("SonarScan", run_sonar, {})
vim.api.nvim_create_user_command("SonarIssues", load_sonar_issues, {})
end
vim.api.nvim_create_user_command("LspOff", disable_lsp, {})
vim.api.nvim_create_user_command("LspOffBuffer", disable_lsp_buffer, {})
vim.api.nvim_create_user_command("LspOn", enable_lsp, {})
vim.api.nvim_create_user_command("UpdateParsers", update_parsers, {})
|