codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/_app_lsp.py
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
"""Mixin ``_AppLspMixin`` - integração do protocolo LSP (Language Server Protocol).
|
|
2
|
+
|
|
3
|
+
Gerencia o ciclo de vida dos language servers, roteamento de diagnósticos,
|
|
4
|
+
e a abertura do painel LSP na interface do Codis.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import contextlib
|
|
10
|
+
import logging
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import tkinter as tk
|
|
14
|
+
from collections.abc import Callable
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import TYPE_CHECKING
|
|
17
|
+
|
|
18
|
+
from src.constants import LANG_LABEL
|
|
19
|
+
from src.editor._pane_utils import _lsp_uri_to_path
|
|
20
|
+
from src.i18n import _t
|
|
21
|
+
from src.lint.manager import Diag
|
|
22
|
+
from src.lsp.edits import normalize_workspace_edit
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger("Codis")
|
|
28
|
+
|
|
29
|
+
_MAX_EDIT_OPEN_BYTES = 5_000_000
|
|
30
|
+
|
|
31
|
+
__all__ = ["_AppLspMixin"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class _AppLspMixin:
|
|
35
|
+
"""Mixin de Lsp do CodisApp."""
|
|
36
|
+
|
|
37
|
+
def _on_cursor_change(self, line: int, col: int) -> None:
|
|
38
|
+
"""Chamado quando a posição do cursor muda."""
|
|
39
|
+
self._status.set_cursor(line, col)
|
|
40
|
+
e = self._active_editor()
|
|
41
|
+
if e:
|
|
42
|
+
with contextlib.suppress(tk.TclError):
|
|
43
|
+
if e.text.tag_ranges(tk.SEL):
|
|
44
|
+
sel = e.text.get(tk.SEL_FIRST, tk.SEL_LAST)
|
|
45
|
+
self._status.set_selection(len(sel), sel.count("\n") + 1)
|
|
46
|
+
else:
|
|
47
|
+
self._status.set_selection(0, 0)
|
|
48
|
+
self._fire_hook("cursor_move", (line, col))
|
|
49
|
+
|
|
50
|
+
if hasattr(e, "_rhythm") and e._rhythm is not None:
|
|
51
|
+
try:
|
|
52
|
+
m = e._rhythm.metrics()
|
|
53
|
+
self._status.set_rhythm(m.flow_state, m.wpm)
|
|
54
|
+
except Exception:
|
|
55
|
+
logger.debug("_on_cursor_change: erro ignorado", exc_info=True)
|
|
56
|
+
if self._bus is not None:
|
|
57
|
+
self._bus.emit(
|
|
58
|
+
"editor.cursor_move",
|
|
59
|
+
{
|
|
60
|
+
"line": line,
|
|
61
|
+
"col": col,
|
|
62
|
+
"path": str(e.path) if e.path else "",
|
|
63
|
+
"lang": getattr(e, "lang", ""),
|
|
64
|
+
},
|
|
65
|
+
source="CodisApp",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def _on_editor_title(self, name: str, modified: bool) -> None:
|
|
69
|
+
"""Chamado quando o título do editor (nome do arquivo) muda."""
|
|
70
|
+
if 0 <= self._active_idx < len(self._editors):
|
|
71
|
+
self._tabbar.update_tab(self._active_idx, name, modified)
|
|
72
|
+
self._update_title()
|
|
73
|
+
|
|
74
|
+
def _on_lsp_diagnostics(self, lang: str, uri: str, lsp_diags: list) -> None:
|
|
75
|
+
"""Recebe diagnósticos do LSP e os encaminha ao editor e painéis."""
|
|
76
|
+
|
|
77
|
+
if uri.startswith("file://"):
|
|
78
|
+
file_path = uri[7:]
|
|
79
|
+
if sys.platform == "win32" and file_path.startswith("/"):
|
|
80
|
+
file_path = file_path[1:]
|
|
81
|
+
|
|
82
|
+
if len(file_path) >= 2 and file_path[1] == ":":
|
|
83
|
+
file_path = file_path[0].upper() + file_path[1:]
|
|
84
|
+
else:
|
|
85
|
+
file_path = uri
|
|
86
|
+
|
|
87
|
+
lint_diags: list[Diag] = []
|
|
88
|
+
for d in lsp_diags:
|
|
89
|
+
with contextlib.suppress(tk.TclError):
|
|
90
|
+
rng = getattr(d, "range", None)
|
|
91
|
+
if rng:
|
|
92
|
+
start_pos = getattr(rng, "start", rng)
|
|
93
|
+
line_0 = getattr(start_pos, "line", 0)
|
|
94
|
+
col_0 = getattr(start_pos, "character", 0)
|
|
95
|
+
end_pos = getattr(rng, "end", start_pos)
|
|
96
|
+
end_c = getattr(end_pos, "character", col_0)
|
|
97
|
+
else:
|
|
98
|
+
line_0 = 0
|
|
99
|
+
col_0 = 0
|
|
100
|
+
end_c = 0
|
|
101
|
+
lint_diags.append(
|
|
102
|
+
Diag(
|
|
103
|
+
line=line_0 + 1,
|
|
104
|
+
col=col_0,
|
|
105
|
+
end_col=end_c,
|
|
106
|
+
severity=getattr(d, "severity", 2),
|
|
107
|
+
message=getattr(d, "message", str(d)),
|
|
108
|
+
rule=str(getattr(d, "code", "") or ""),
|
|
109
|
+
source=getattr(d, "source", lang) or lang,
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
for e in self._editors:
|
|
114
|
+
if e.path and str(e.path) == file_path:
|
|
115
|
+
with contextlib.suppress(tk.TclError):
|
|
116
|
+
e.deliver_diags(lint_diags)
|
|
117
|
+
e.minimap.set_lint_lines(lint_diags)
|
|
118
|
+
break
|
|
119
|
+
|
|
120
|
+
ae = self._active_editor()
|
|
121
|
+
if ae and ae.path and str(ae.path) == file_path:
|
|
122
|
+
self._status.set_diags(lint_diags)
|
|
123
|
+
|
|
124
|
+
with contextlib.suppress(tk.TclError):
|
|
125
|
+
open_paths = [str(ed.path) for ed in self._editors if ed.path]
|
|
126
|
+
self._problems_panel.set_open_files(open_paths)
|
|
127
|
+
self._problems_panel.set_diags(lint_diags, file=file_path)
|
|
128
|
+
self._sidebar_problems.set_open_files(open_paths)
|
|
129
|
+
self._sidebar_problems.set_diags(lint_diags, file=file_path)
|
|
130
|
+
errors = sum(1 for d in lint_diags if d.severity == 1)
|
|
131
|
+
warns = sum(1 for d in lint_diags if d.severity == 2)
|
|
132
|
+
if errors + warns > 0:
|
|
133
|
+
self._actbar.set_badge("problems", errors + warns)
|
|
134
|
+
if self._kui:
|
|
135
|
+
with contextlib.suppress(tk.TclError):
|
|
136
|
+
self._kui.notify_diagnostics(errors, warns)
|
|
137
|
+
|
|
138
|
+
if lint_diags:
|
|
139
|
+
with contextlib.suppress(OSError):
|
|
140
|
+
fname = Path(file_path).name if file_path else uri
|
|
141
|
+
self._output_panel.write(
|
|
142
|
+
f"🔤 LSP [{lang}] {len(lint_diags)} diagnostic(s) in {fname}",
|
|
143
|
+
"LSP",
|
|
144
|
+
"info",
|
|
145
|
+
timestamp=False,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
def _on_lsp_log(self, lang: str, message: str) -> None:
|
|
149
|
+
"""Encaminha mensagens de log do servidor LSP para o painel de saída."""
|
|
150
|
+
with contextlib.suppress(tk.TclError):
|
|
151
|
+
self._output_panel.write(
|
|
152
|
+
f"[LSP:{lang}] {message}", "LSP", "info", timestamp=False
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
def _on_lsp_apply_edit(self, edit) -> None:
|
|
156
|
+
"""Aplica um WorkspaceEdit pedido pelo servidor (rename, refactor, quick fix).
|
|
157
|
+
|
|
158
|
+
Chega na thread do LSP; o trabalho com widgets é repassado para a thread da interface.
|
|
159
|
+
"""
|
|
160
|
+
try:
|
|
161
|
+
self._root.after(0, lambda: self._apply_workspace_edit(edit))
|
|
162
|
+
except (RuntimeError, tk.TclError) as exc:
|
|
163
|
+
logger.warning("_on_lsp_apply_edit falhou: %s", exc)
|
|
164
|
+
|
|
165
|
+
def _apply_workspace_edit(self, edit) -> int:
|
|
166
|
+
"""Aplica as edições em todos os arquivos citados e avisa quantos foram alterados."""
|
|
167
|
+
changed = 0
|
|
168
|
+
for uri, edits in normalize_workspace_edit(edit).items():
|
|
169
|
+
if self._apply_edits_to_path(_lsp_uri_to_path(uri), edits):
|
|
170
|
+
changed += 1
|
|
171
|
+
if changed:
|
|
172
|
+
self._status.notify(_t("lsp.edits_applied", n=changed), level="info")
|
|
173
|
+
return changed
|
|
174
|
+
|
|
175
|
+
def _apply_edits_to_path(self, path: Path, edits: list) -> bool:
|
|
176
|
+
"""Aplica ``edits`` ao arquivo em ``path``, abrindo-o em uma aba se ainda não estiver.
|
|
177
|
+
|
|
178
|
+
As alterações ficam pendentes (nada é gravado em disco), então dá para revisar e
|
|
179
|
+
desfazer com Ctrl+Z, e a recuperação de alterações já as protege.
|
|
180
|
+
"""
|
|
181
|
+
try:
|
|
182
|
+
idx = self._find_editor_for_path(path)
|
|
183
|
+
if idx is None:
|
|
184
|
+
if not path.is_file() or path.stat().st_size > _MAX_EDIT_OPEN_BYTES:
|
|
185
|
+
return False
|
|
186
|
+
self._open_file(path)
|
|
187
|
+
idx = self._find_editor_for_path(path)
|
|
188
|
+
if idx is None:
|
|
189
|
+
return False
|
|
190
|
+
self._editors[idx].apply_lsp_edits(edits)
|
|
191
|
+
return True
|
|
192
|
+
except (OSError, tk.TclError):
|
|
193
|
+
logger.debug("Falha ao aplicar edições LSP em %s", path, exc_info=True)
|
|
194
|
+
return False
|
|
195
|
+
|
|
196
|
+
def _open_lsp_panel(self) -> None:
|
|
197
|
+
"""Abre o painel de controle LSP - status, enable/disable por linguagem."""
|
|
198
|
+
if not self._lsp_mgr:
|
|
199
|
+
from tkinter import messagebox as _mb
|
|
200
|
+
|
|
201
|
+
_mb.showinfo(
|
|
202
|
+
"LSP", "LSP não está disponível nesta sessão.", parent=self._root
|
|
203
|
+
)
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
t = self._tmgr.theme
|
|
207
|
+
dlg = tk.Toplevel(self._root)
|
|
208
|
+
dlg.title("LSP - Servidores de Linguagem")
|
|
209
|
+
dlg.configure(bg=t.floating_bg)
|
|
210
|
+
dlg.geometry("620x500")
|
|
211
|
+
dlg.minsize(500, 380)
|
|
212
|
+
dlg.transient(self._root)
|
|
213
|
+
|
|
214
|
+
tk.Frame(dlg, bg=t.accent, height=2).pack(fill="x")
|
|
215
|
+
hdr = tk.Frame(dlg, bg=t.floating_bg)
|
|
216
|
+
hdr.pack(fill="x", padx=14, pady=(10, 4))
|
|
217
|
+
tk.Label(
|
|
218
|
+
hdr,
|
|
219
|
+
text=_t("lsp.panel_title"),
|
|
220
|
+
bg=t.floating_bg,
|
|
221
|
+
fg=t.t_func,
|
|
222
|
+
font=("Segoe UI", 12, "bold"),
|
|
223
|
+
).pack(side="left")
|
|
224
|
+
|
|
225
|
+
btn_kw = {
|
|
226
|
+
"relief": "flat",
|
|
227
|
+
"cursor": "hand2",
|
|
228
|
+
"font": ("Segoe UI", 8),
|
|
229
|
+
"padx": 8,
|
|
230
|
+
"pady": 3,
|
|
231
|
+
}
|
|
232
|
+
tk.Button(
|
|
233
|
+
hdr,
|
|
234
|
+
text=_t("lsp.btn_enable_all"),
|
|
235
|
+
bg=t.btn_primary,
|
|
236
|
+
fg=t.btn_primary_fg,
|
|
237
|
+
command=lambda: _enable_all(),
|
|
238
|
+
**btn_kw,
|
|
239
|
+
).pack(
|
|
240
|
+
side="right", padx=2
|
|
241
|
+
) # pylint: disable=unnecessary-lambda
|
|
242
|
+
tk.Button(
|
|
243
|
+
hdr,
|
|
244
|
+
text=_t("lsp.btn_disable_all"),
|
|
245
|
+
bg=t.btn_bg,
|
|
246
|
+
fg=t.fg,
|
|
247
|
+
command=lambda: _disable_all(),
|
|
248
|
+
**btn_kw,
|
|
249
|
+
).pack(
|
|
250
|
+
side="right", padx=2
|
|
251
|
+
) # pylint: disable=unnecessary-lambda
|
|
252
|
+
|
|
253
|
+
lgd = tk.Frame(dlg, bg=t.floating_bg)
|
|
254
|
+
lgd.pack(fill="x", padx=14, pady=(0, 6))
|
|
255
|
+
for sym, color, label in [
|
|
256
|
+
("●", "#69ff47", _t("lsp.status_active")),
|
|
257
|
+
("●", "#ff9100", _t("lsp.status_starting")),
|
|
258
|
+
("●", "#546e7a", _t("lsp.status_available")),
|
|
259
|
+
("●", "#ff5252", _t("lsp.status_disabled")),
|
|
260
|
+
("○", "#2d3040", _t("lsp.status_none")),
|
|
261
|
+
]:
|
|
262
|
+
tk.Label(
|
|
263
|
+
lgd,
|
|
264
|
+
text=f"{sym} {label}",
|
|
265
|
+
bg=t.floating_bg,
|
|
266
|
+
fg=color,
|
|
267
|
+
font=("Segoe UI", 8),
|
|
268
|
+
).pack(side="left", padx=6)
|
|
269
|
+
|
|
270
|
+
container = tk.Frame(dlg, bg=t.floating_bg)
|
|
271
|
+
container.pack(fill="both", expand=True, padx=14, pady=4)
|
|
272
|
+
|
|
273
|
+
canvas = tk.Canvas(container, bg=t.floating_bg, highlightthickness=0)
|
|
274
|
+
scrollbar = tk.Scrollbar(
|
|
275
|
+
container, orient="vertical", command=canvas.yview)
|
|
276
|
+
inner = tk.Frame(canvas, bg=t.floating_bg)
|
|
277
|
+
|
|
278
|
+
inner.bind(
|
|
279
|
+
"<Configure>", lambda _: canvas.configure(
|
|
280
|
+
scrollregion=canvas.bbox("all"))
|
|
281
|
+
)
|
|
282
|
+
canvas.create_window((0, 0), window=inner, anchor="nw")
|
|
283
|
+
canvas.configure(yscrollcommand=scrollbar.set)
|
|
284
|
+
|
|
285
|
+
scrollbar.pack(side="right", fill="y")
|
|
286
|
+
canvas.pack(side="left", fill="both", expand=True)
|
|
287
|
+
|
|
288
|
+
row_vars: dict[str, tk.BooleanVar] = {}
|
|
289
|
+
|
|
290
|
+
def _refresh_rows() -> None:
|
|
291
|
+
for w in inner.winfo_children():
|
|
292
|
+
w.destroy()
|
|
293
|
+
row_vars.clear()
|
|
294
|
+
|
|
295
|
+
status = self._lsp_mgr.status()
|
|
296
|
+
all_langs = sorted(
|
|
297
|
+
set(
|
|
298
|
+
list(status.keys())
|
|
299
|
+
+ (
|
|
300
|
+
[self._active_editor().lang]
|
|
301
|
+
if self._active_editor()
|
|
302
|
+
and self._active_editor().lang != "text"
|
|
303
|
+
else []
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
for i, lang in enumerate(all_langs):
|
|
309
|
+
st = status.get(lang, "unavailable")
|
|
310
|
+
color = {
|
|
311
|
+
"running": "#69ff47",
|
|
312
|
+
"starting": "#ff9100",
|
|
313
|
+
"available": "#546e7a",
|
|
314
|
+
"disabled": "#ff5252",
|
|
315
|
+
"stopped": "#ff9100",
|
|
316
|
+
"unavailable": "#2d3040",
|
|
317
|
+
}.get(st, "#2d3040")
|
|
318
|
+
|
|
319
|
+
row_bg = t.editor_bg if i % 2 == 0 else t.floating_bg
|
|
320
|
+
row = tk.Frame(inner, bg=row_bg)
|
|
321
|
+
row.pack(fill="x", pady=1)
|
|
322
|
+
|
|
323
|
+
tk.Label(
|
|
324
|
+
row, text="●", bg=row_bg, fg=color, font=("Segoe UI", 10), width=2
|
|
325
|
+
).pack(side="left", padx=(4, 0))
|
|
326
|
+
|
|
327
|
+
label_text = LANG_LABEL.get(lang, lang.capitalize())
|
|
328
|
+
tk.Label(
|
|
329
|
+
row,
|
|
330
|
+
text=label_text,
|
|
331
|
+
bg=row_bg,
|
|
332
|
+
fg=t.fg,
|
|
333
|
+
font=("Segoe UI", 9),
|
|
334
|
+
width=18,
|
|
335
|
+
anchor="w",
|
|
336
|
+
).pack(side="left", padx=4)
|
|
337
|
+
|
|
338
|
+
status_text = {
|
|
339
|
+
"running": "Ativo",
|
|
340
|
+
"starting": "Iniciando...",
|
|
341
|
+
"available": "Disponível",
|
|
342
|
+
"disabled": "Desabilitado",
|
|
343
|
+
"stopped": "Parado",
|
|
344
|
+
"unavailable": "Sem servidor",
|
|
345
|
+
}.get(st, st)
|
|
346
|
+
tk.Label(
|
|
347
|
+
row,
|
|
348
|
+
text=status_text,
|
|
349
|
+
bg=row_bg,
|
|
350
|
+
fg=color,
|
|
351
|
+
font=("Segoe UI", 8),
|
|
352
|
+
width=14,
|
|
353
|
+
).pack(side="left")
|
|
354
|
+
|
|
355
|
+
hint = self._lsp_mgr.install_hint(lang)
|
|
356
|
+
if hint and st == "unavailable":
|
|
357
|
+
tk.Label(
|
|
358
|
+
row,
|
|
359
|
+
text=f" instalar: {hint[:40]}",
|
|
360
|
+
bg=row_bg,
|
|
361
|
+
fg=t.fg_muted,
|
|
362
|
+
font=("Courier New", 7),
|
|
363
|
+
anchor="w",
|
|
364
|
+
).pack(side="left")
|
|
365
|
+
|
|
366
|
+
enabled = st not in ("disabled", "unavailable")
|
|
367
|
+
var = tk.BooleanVar(value=enabled)
|
|
368
|
+
row_vars[lang] = var
|
|
369
|
+
|
|
370
|
+
def _make_toggle(lg: str) -> Callable:
|
|
371
|
+
def _toggle() -> None:
|
|
372
|
+
if self._lsp_mgr.is_lang_enabled(lg):
|
|
373
|
+
self._lsp_mgr.disable_lang(lg)
|
|
374
|
+
self._status.notify(f"LSP {lg}: desabilitado")
|
|
375
|
+
else:
|
|
376
|
+
self._lsp_mgr.enable_lang(lg)
|
|
377
|
+
self._status.notify(f"LSP {lg}: habilitado")
|
|
378
|
+
dlg.after(600, _refresh_rows)
|
|
379
|
+
|
|
380
|
+
return _toggle
|
|
381
|
+
|
|
382
|
+
def _make_restart(lg: str) -> Callable:
|
|
383
|
+
def _restart() -> None:
|
|
384
|
+
self._lsp_mgr.restart_lang(lg)
|
|
385
|
+
self._status.notify(f"LSP {lg}: reiniciando...")
|
|
386
|
+
|
|
387
|
+
def _rewire() -> None:
|
|
388
|
+
for ed in self._editors:
|
|
389
|
+
if ed.path and ed.lang == lg:
|
|
390
|
+
with contextlib.suppress(Exception):
|
|
391
|
+
content = ed.text.get("1.0", "end-1c")
|
|
392
|
+
self._lsp_mgr.did_open(
|
|
393
|
+
ed.path, lg, content)
|
|
394
|
+
ed.autocomplete.set_lsp_manager(
|
|
395
|
+
self._lsp_mgr, ed.path
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
dlg.after(1500, _rewire)
|
|
399
|
+
dlg.after(1600, _refresh_rows)
|
|
400
|
+
|
|
401
|
+
return _restart
|
|
402
|
+
|
|
403
|
+
if st != "unavailable":
|
|
404
|
+
btn_label = "⏹" if enabled else "▶"
|
|
405
|
+
tk.Button(
|
|
406
|
+
row,
|
|
407
|
+
text=btn_label,
|
|
408
|
+
bg=t.btn_bg,
|
|
409
|
+
fg=t.fg,
|
|
410
|
+
relief="flat",
|
|
411
|
+
cursor="hand2",
|
|
412
|
+
font=("Segoe UI", 9),
|
|
413
|
+
command=_make_toggle(lang),
|
|
414
|
+
).pack(side="right", padx=2)
|
|
415
|
+
|
|
416
|
+
if st in ("running", "starting", "stopped"):
|
|
417
|
+
tk.Button(
|
|
418
|
+
row,
|
|
419
|
+
text="↺",
|
|
420
|
+
bg=t.btn_bg,
|
|
421
|
+
fg=t.fg,
|
|
422
|
+
relief="flat",
|
|
423
|
+
cursor="hand2",
|
|
424
|
+
font=("Segoe UI", 9),
|
|
425
|
+
command=_make_restart(lang),
|
|
426
|
+
).pack(side="right", padx=2)
|
|
427
|
+
|
|
428
|
+
def _enable_all() -> None:
|
|
429
|
+
for lang in list(self._lsp_mgr._disabled_langs):
|
|
430
|
+
self._lsp_mgr.enable_lang(lang)
|
|
431
|
+
_refresh_rows()
|
|
432
|
+
|
|
433
|
+
def _disable_all() -> None:
|
|
434
|
+
status = self._lsp_mgr.status()
|
|
435
|
+
for lang, st in status.items():
|
|
436
|
+
if st in ("running", "starting", "available", "stopped"):
|
|
437
|
+
self._lsp_mgr.disable_lang(lang)
|
|
438
|
+
_refresh_rows()
|
|
439
|
+
|
|
440
|
+
_refresh_rows()
|
|
441
|
+
|
|
442
|
+
foot = tk.Frame(dlg, bg=t.floating_bg)
|
|
443
|
+
foot.pack(fill="x", padx=14, pady=(4, 10))
|
|
444
|
+
tk.Button(
|
|
445
|
+
foot,
|
|
446
|
+
text=_t("lsp.btn_refresh"),
|
|
447
|
+
bg=t.btn_bg,
|
|
448
|
+
fg=t.fg,
|
|
449
|
+
relief="flat",
|
|
450
|
+
cursor="hand2",
|
|
451
|
+
font=("Segoe UI", 9),
|
|
452
|
+
padx=12,
|
|
453
|
+
pady=4,
|
|
454
|
+
command=_refresh_rows,
|
|
455
|
+
).pack(side="left")
|
|
456
|
+
tk.Button(
|
|
457
|
+
foot,
|
|
458
|
+
text=_t("ui.close"),
|
|
459
|
+
bg=t.btn_primary,
|
|
460
|
+
fg=t.btn_primary_fg,
|
|
461
|
+
relief="flat",
|
|
462
|
+
cursor="hand2",
|
|
463
|
+
font=("Segoe UI", 9),
|
|
464
|
+
padx=12,
|
|
465
|
+
pady=4,
|
|
466
|
+
command=dlg.destroy,
|
|
467
|
+
).pack(side="right")
|
|
468
|
+
|
|
469
|
+
def _on_lint_result(self, diags: list[Diag]) -> None:
|
|
470
|
+
"""Recebe resultados do lint e os distribui ao editor, painéis e output."""
|
|
471
|
+
e = self._active_editor()
|
|
472
|
+
if e:
|
|
473
|
+
e.deliver_diags(diags)
|
|
474
|
+
e.minimap.set_lint_lines(diags)
|
|
475
|
+
self._status.set_diags(diags)
|
|
476
|
+
|
|
477
|
+
open_paths = [str(ed.path) for ed in self._editors if ed.path]
|
|
478
|
+
file_str = str(e.path) if e and e.path else ""
|
|
479
|
+
self._problems_panel.set_open_files(open_paths)
|
|
480
|
+
self._problems_panel.set_diags(diags, file=file_str)
|
|
481
|
+
with contextlib.suppress(tk.TclError):
|
|
482
|
+
self._sidebar_problems.set_open_files(open_paths)
|
|
483
|
+
self._sidebar_problems.set_diags(diags, file=file_str)
|
|
484
|
+
|
|
485
|
+
errors = warns = 0
|
|
486
|
+
for d in diags:
|
|
487
|
+
if d.severity == 1:
|
|
488
|
+
errors += 1
|
|
489
|
+
elif d.severity == 2:
|
|
490
|
+
warns += 1
|
|
491
|
+
|
|
492
|
+
self._actbar.set_badge("problems", errors + warns)
|
|
493
|
+
if self._kui:
|
|
494
|
+
with contextlib.suppress(tk.TclError):
|
|
495
|
+
self._kui.notify_diagnostics(errors, warns)
|
|
496
|
+
self._fire_hook("lint_complete", diags)
|
|
497
|
+
|
|
498
|
+
if not (diags and e and e.path):
|
|
499
|
+
return
|
|
500
|
+
|
|
501
|
+
fname = e.path.name
|
|
502
|
+
by_source: dict[str, list[Diag]] = {}
|
|
503
|
+
for d in diags:
|
|
504
|
+
by_source.setdefault(d.source or "", []).append(d)
|
|
505
|
+
|
|
506
|
+
_source_channel = {
|
|
507
|
+
"eslint": "ESLint",
|
|
508
|
+
"pyflakes": "Python",
|
|
509
|
+
"flake8": "Python",
|
|
510
|
+
"mypy": "Python",
|
|
511
|
+
"py_compile": "Python",
|
|
512
|
+
}
|
|
513
|
+
for src, src_diags in by_source.items():
|
|
514
|
+
channel = _source_channel.get(src, "Codis")
|
|
515
|
+
self._output_panel.write(
|
|
516
|
+
f"-- {fname} --", channel, "info", timestamp=True)
|
|
517
|
+
for d in src_diags:
|
|
518
|
+
lvl = "error" if d.is_error else "warn"
|
|
519
|
+
rule = f" [{d.rule}]" if d.rule else ""
|
|
520
|
+
self._output_panel.write(
|
|
521
|
+
f" {d.icon} L{d.line}:{d.col} {d.message}{rule}", channel, lvl
|
|
522
|
+
)
|
|
523
|
+
e_cnt = sum(1 for d in src_diags if d.is_error)
|
|
524
|
+
w_cnt = len(src_diags) - e_cnt
|
|
525
|
+
self._output_panel.write(
|
|
526
|
+
f" {len(src_diags)} problema(s) - {e_cnt} erro(s), {w_cnt} aviso(s)",
|
|
527
|
+
channel,
|
|
528
|
+
"info" if e_cnt == 0 else "error",
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
def _apply_problem_fix(self, file_path: str, diag: Diag) -> None:
|
|
532
|
+
"""Aplica o fix de um único diagnóstico no editor correspondente ao arquivo.
|
|
533
|
+
|
|
534
|
+
Percorre os editores abertos e aplica o fix no editor cujo caminho
|
|
535
|
+
corresponde a ``file_path``. Se o arquivo não estiver aberto, ignora.
|
|
536
|
+
|
|
537
|
+
Args:
|
|
538
|
+
file_path: Caminho absoluto do arquivo com o diagnóstico.
|
|
539
|
+
diag: Diagnóstico com campo ``fix`` (dict ESLint).
|
|
540
|
+
"""
|
|
541
|
+
if not diag.fix:
|
|
542
|
+
return
|
|
543
|
+
for ed in self._editors:
|
|
544
|
+
if ed.path and str(ed.path) == file_path:
|
|
545
|
+
ed._apply_single_fix(diag)
|
|
546
|
+
return
|
|
547
|
+
e = self._active_editor()
|
|
548
|
+
if e and e.path and str(e.path) == file_path:
|
|
549
|
+
e._apply_single_fix(diag)
|
|
550
|
+
|
|
551
|
+
def _apply_problem_fix_all(self, file_path: str, diags: list[Diag]) -> None:
|
|
552
|
+
"""Aplica todos os fixes de um arquivo no editor correspondente.
|
|
553
|
+
|
|
554
|
+
Usa o algoritmo atômico do ESLint (merge de fixes não-sobrepostos
|
|
555
|
+
numa única varredura) para garantir que os offsets originais
|
|
556
|
+
permaneçam válidos durante toda a operação.
|
|
557
|
+
|
|
558
|
+
Args:
|
|
559
|
+
file_path: Caminho absoluto do arquivo.
|
|
560
|
+
diags: Lista de diagnósticos com fix disponível.
|
|
561
|
+
"""
|
|
562
|
+
for ed in self._editors:
|
|
563
|
+
if ed.path and str(ed.path) == file_path:
|
|
564
|
+
ed._apply_fix_list(diags)
|
|
565
|
+
return
|
|
566
|
+
e = self._active_editor()
|
|
567
|
+
if e and e.path and str(e.path) == file_path:
|
|
568
|
+
e._apply_fix_list(diags)
|
|
569
|
+
|
|
570
|
+
def _on_git_refresh(self) -> None:
|
|
571
|
+
"""Chamado quando o repositório Git é atualizado."""
|
|
572
|
+
self._file_tree.refresh()
|
|
573
|
+
|
|
574
|
+
if self._workspace:
|
|
575
|
+
try:
|
|
576
|
+
r = subprocess.run(
|
|
577
|
+
["git", "status", "--porcelain"],
|
|
578
|
+
capture_output=True,
|
|
579
|
+
text=True,
|
|
580
|
+
encoding="utf-8",
|
|
581
|
+
errors="replace",
|
|
582
|
+
cwd=str(self._workspace),
|
|
583
|
+
timeout=5,
|
|
584
|
+
check=False,
|
|
585
|
+
)
|
|
586
|
+
n = len(r.stdout.splitlines()) if r.returncode == 0 else 0
|
|
587
|
+
except (OSError, FileNotFoundError):
|
|
588
|
+
n = 0
|
|
589
|
+
self._actbar.set_badge("git", n)
|
|
590
|
+
|
|
591
|
+
def _show_panel(self, key: str) -> None:
|
|
592
|
+
"""Exibe o painel inferior correspondente à chave.
|
|
593
|
+
|
|
594
|
+
Args:
|
|
595
|
+
key: Chave do painel (``"problems"``, ``"terminal"``, etc.).
|
|
596
|
+
"""
|
|
597
|
+
t = self._tmgr.theme
|
|
598
|
+
if not self._panel_visible:
|
|
599
|
+
self._show_bottom_panel()
|
|
600
|
+
|
|
601
|
+
panel_map: dict[str, tk.Widget] = {
|
|
602
|
+
"problems": self._problems_panel,
|
|
603
|
+
"terminal": self._terminal,
|
|
604
|
+
"output": self._output_panel,
|
|
605
|
+
"git": self._git_bottom,
|
|
606
|
+
"diff": self._diff_pane,
|
|
607
|
+
"debug": self._debug_panel,
|
|
608
|
+
"regex": self._regex_panel,
|
|
609
|
+
}
|
|
610
|
+
if getattr(self, "_sql_bottom", None) is not None:
|
|
611
|
+
panel_map["sql"] = self._sql_bottom # type: ignore[assignment]
|
|
612
|
+
for w in self._panel_content.winfo_children():
|
|
613
|
+
w.pack_forget()
|
|
614
|
+
panel = panel_map.get(key)
|
|
615
|
+
if panel:
|
|
616
|
+
panel.pack(fill="both", expand=True)
|
|
617
|
+
|
|
618
|
+
for k, lbl in self._panel_tabs.items():
|
|
619
|
+
active = k == key
|
|
620
|
+
lbl.config(
|
|
621
|
+
bg=t.tab_act_bg if active else t.tabbar_bg,
|
|
622
|
+
fg=t.tab_act_fg if active else t.tab_in_fg,
|
|
623
|
+
)
|
|
624
|
+
|
|
625
|
+
self._current_panel = key
|