This commit is contained in:
2026-10-31 15:58:33 +03:00
parent 838627fb33
commit cf1505eca5
7 changed files with 846 additions and 189 deletions
+24 -32
View File
@@ -97,15 +97,24 @@ print("[lua] init.lua выполнен")
-- -- false — нет вкладки или иконки
-- api.editor:clear_tab_icon(i) -- вернуть иконку по умолчанию (file)
-- api.editor:tab_icon(i) -- имя иконки вкладки или nil
-- api.editor:set_gutter_icon(line, name[, color])
-- api.editor:set_gutter_icon(line, name, kind[, options])
-- -- иконка на поле слева от редактора
-- -- (активная вкладка, строка с нуля);
-- -- color — #RGB/#RGBA/#RRGGBB/#RRGGBBAA;
-- -- kind — тип иконки, на строке может быть
-- -- по одной иконке каждого типа;
-- -- options = { color = "#RRGGBB",
-- -- hover_color = "#RRGGBB" };
-- -- false — неизвестная иконка или цвет
-- api.editor:gutter_icon(line) -- имя иконки gutter или nil
-- api.editor:gutter_color(line) -- цвет иконки gutter или nil
-- api.editor:clear_gutter_icon(line) -- убрать иконку со строки
-- api.editor:gutter_icon(line, kind) -- имя иконки gutter или nil
-- api.editor:gutter_color(line, kind) -- цвет иконки gutter или nil
-- api.editor:gutter_hover_color(line, kind) -- цвет при наведении или nil
-- api.editor:clear_gutter_icon(line, kind) -- убрать иконку этого типа
-- api.editor:clear_gutter_line(line) -- убрать все иконки строки
-- api.editor:clear_gutter_kind(kind) -- убрать иконки типа во всей вкладке
-- api.editor:clear_gutter() -- убрать все иконки активной вкладки
-- api.editor:on_gutter_click(kind, callback)
-- -- клик по иконке типа; callback(line, icon, kind),
-- -- nil снимает обработчик
-- api.editor:active_text() -- текст активной вкладки
-- api.editor:set_active_text(text) -- заменить текст активной вкладки
-- api.editor:set_language(i, "rust") -- включить подсветку
@@ -498,10 +507,9 @@ local function diagnostic_rank(diagnostic)
or 1
end
-- Строки активной вкладки, занятые иконками диагностики. Gutter действует
-- только на активную вкладку, поэтому запоминаем поставленные строки, чтобы
-- при следующем обновлении снять устаревшие иконки и не трогать остальные.
local diagnostic_gutter = {}
-- Строки активной вкладки, занятые иконками диагностики, больше не нужно
-- запоминать: иконки имеют тип "diagnostics", и перед перерисовкой сценарий
-- снимает только их, не трогая иконки других типов.
local function active_tab_title()
local active = api.editor:active_tab()
@@ -531,14 +539,11 @@ end
api.editor:on_lsp_diagnostics(100, function(servers)
diagnostics_tree:clear()
-- Иконки прошлого обновления активной вкладки могли устареть.
-- Иконки прошлого обновления активной вкладки могли устареть. Снимаем
-- только иконки диагностики: иконки других типов (например, точки
-- останова) остаются на месте.
local title = active_tab_title()
if title and diagnostic_gutter[title] then
for line in pairs(diagnostic_gutter[title]) do
api.editor:clear_gutter_icon(line)
end
diagnostic_gutter[title] = nil
end
api.editor:clear_gutter_kind("diagnostics")
-- Сначала собираем диагностику по файлам: одинаковые проблемы от разных
-- серверов попадают в одну запись.
@@ -600,15 +605,13 @@ api.editor:on_lsp_diagnostics(100, function(servers)
-- Подсветка и gutter в редакторе относятся к активной вкладке, поэтому
-- иконки ставим только для её файла.
local active = title ~= nil and path_matches_title(path, title)
local gutter_lines = active and {} or nil
local errors = {}
for index, key in ipairs(group_order) do
local group = groups[key]
local icon = severity_icons[group.severity] or "circle-alert"
if active then
api.editor:set_gutter_icon(group.line, icon)
gutter_lines[group.line] = true
api.editor:set_gutter_icon(group.line, icon, "diagnostics")
end
errors[#errors + 1] = {
-- Префикс отделяет позицию от id файла, даже если в пути есть ':'.
@@ -629,17 +632,6 @@ api.editor:on_lsp_diagnostics(100, function(servers)
}
end
if active and next(gutter_lines) then
local stored = diagnostic_gutter[title]
if not stored then
stored = {}
diagnostic_gutter[title] = stored
end
for line in pairs(gutter_lines) do
stored[line] = true
end
end
diagnostics_tree:append({
{
id = path,
@@ -672,5 +664,5 @@ api.panels.toolbar:add_button("Запустить", "play", nil, "run", "right",
print("[toolbar] кнопка «Запустить» нажата")
end)
api.editor:set_gutter_icon(2, "play", "#efefe6")
api.editor:set_gutter_icon(90, "play")
api.editor:set_gutter_icon(2, "play", "demo", { color = "#efefe6" })
api.editor:set_gutter_icon(90, "play", "demo")