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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Peças compartilhadas pelos formatos que usam gramáticas e snippets no estilo TextMate.
|
|
2
|
+
|
|
3
|
+
Sublime Text, bundles do TextMate, plugins do JetBrains (com bundle TextMate) e do Eclipse
|
|
4
|
+
(TM4E) guardam a mesma coisa em arquivos de nomes diferentes. Aqui ficam a leitura de
|
|
5
|
+
``.sublime-syntax``, de ``.tmLanguage``, de ``.tmPreferences`` e de ``.tmSnippet``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import plistlib
|
|
11
|
+
import re
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from .. import textmate, yamlite
|
|
15
|
+
from ..common import lang_id, scope_lang
|
|
16
|
+
from ..jsonc import as_dict
|
|
17
|
+
from ..model import Extension, LanguageSpec, SnippetSpec
|
|
18
|
+
from ..themes import slug
|
|
19
|
+
|
|
20
|
+
MAX_RULES = 3000
|
|
21
|
+
_VARIABLE = re.compile(r"\{\{(\w+)\}\}")
|
|
22
|
+
_VERBOSE_FLAG = re.compile(r"^\(\?([imsx]*x[imsx]*)\)")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def strip_verbose(pattern: str) -> str:
|
|
26
|
+
"""Tira comentários e espaços de um regex em modo ``(?x)``, que o realce do Codis não usa."""
|
|
27
|
+
lead = _VERBOSE_FLAG.match(pattern)
|
|
28
|
+
if not lead:
|
|
29
|
+
return pattern
|
|
30
|
+
flags = lead.group(1).replace("x", "")
|
|
31
|
+
body = pattern[lead.end() :]
|
|
32
|
+
out: list[str] = []
|
|
33
|
+
i, in_class = 0, False
|
|
34
|
+
while i < len(body):
|
|
35
|
+
ch = body[i]
|
|
36
|
+
if ch == "\\" and i + 1 < len(body):
|
|
37
|
+
out.append(body[i : i + 2])
|
|
38
|
+
i += 2
|
|
39
|
+
continue
|
|
40
|
+
if in_class:
|
|
41
|
+
out.append(ch)
|
|
42
|
+
in_class = ch != "]"
|
|
43
|
+
elif ch == "[":
|
|
44
|
+
in_class = True
|
|
45
|
+
out.append(ch)
|
|
46
|
+
elif ch == "#":
|
|
47
|
+
while i < len(body) and body[i] != "\n":
|
|
48
|
+
i += 1
|
|
49
|
+
elif not ch.isspace():
|
|
50
|
+
out.append(ch)
|
|
51
|
+
i += 1
|
|
52
|
+
return (f"(?{flags})" if flags else "") + "".join(out)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def syntax_to_grammar(doc: dict[str, Any]) -> dict[str, Any]:
|
|
56
|
+
"""Converte um ``.sublime-syntax`` (já lido do YAML) em gramática no formato TextMate."""
|
|
57
|
+
variables = {str(k): str(v) for k, v in as_dict(doc.get("variables")).items()}
|
|
58
|
+
contexts = {k: v for k, v in as_dict(doc.get("contexts")).items() if isinstance(v, list)}
|
|
59
|
+
|
|
60
|
+
def expand(text: str) -> str:
|
|
61
|
+
for _ in range(4):
|
|
62
|
+
new = _VARIABLE.sub(lambda m: variables.get(m.group(1), m.group(0)), text)
|
|
63
|
+
if new == text:
|
|
64
|
+
break
|
|
65
|
+
text = new
|
|
66
|
+
return strip_verbose(text)
|
|
67
|
+
|
|
68
|
+
def capture_scope(rule: dict[str, Any]) -> str | None:
|
|
69
|
+
caps = as_dict(rule.get("captures"))
|
|
70
|
+
scopes = [str(v) for v in caps.values() if isinstance(v, str)]
|
|
71
|
+
return scopes[0] if len(scopes) == 1 else None
|
|
72
|
+
|
|
73
|
+
def meta_scope(rules: list[Any]) -> str | None:
|
|
74
|
+
for item in rules:
|
|
75
|
+
if isinstance(item, dict):
|
|
76
|
+
value = item.get("meta_scope") or item.get("meta_content_scope")
|
|
77
|
+
if isinstance(value, str):
|
|
78
|
+
return value
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
def pop_match(rules: list[Any]) -> str | None:
|
|
82
|
+
for item in rules:
|
|
83
|
+
if isinstance(item, dict) and item.get("pop") and isinstance(item.get("match"), str):
|
|
84
|
+
return expand(item["match"])
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
budget = [MAX_RULES]
|
|
88
|
+
|
|
89
|
+
def convert(rule: Any) -> dict[str, Any] | None:
|
|
90
|
+
if not isinstance(rule, dict) or budget[0] <= 0:
|
|
91
|
+
return None
|
|
92
|
+
budget[0] -= 1
|
|
93
|
+
include = rule.get("include")
|
|
94
|
+
if isinstance(include, str):
|
|
95
|
+
return {"include": f"#{include}"} if include in contexts else None
|
|
96
|
+
match = rule.get("match")
|
|
97
|
+
if not isinstance(match, str):
|
|
98
|
+
return None
|
|
99
|
+
scope = rule.get("scope") if isinstance(rule.get("scope"), str) else capture_scope(rule)
|
|
100
|
+
push = rule.get("push")
|
|
101
|
+
if isinstance(push, str) and push in contexts:
|
|
102
|
+
inner = contexts[push]
|
|
103
|
+
end, name = pop_match(inner), meta_scope(inner) or scope
|
|
104
|
+
if end and name:
|
|
105
|
+
return {"begin": expand(match), "end": end, "name": name, "patterns": [{"include": f"#{push}"}]}
|
|
106
|
+
if scope and not rule.get("pop"):
|
|
107
|
+
return {"match": expand(match), "name": scope}
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
repository: dict[str, Any] = {}
|
|
111
|
+
for name, rules in contexts.items():
|
|
112
|
+
converted = [c for c in (convert(r) for r in rules) if c]
|
|
113
|
+
repository[name] = {"patterns": converted}
|
|
114
|
+
return {"patterns": [{"include": "#main"}] if "main" in repository else [], "repository": repository}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def preferences_comments(plists: list[bytes]) -> dict[str, tuple[str | None, tuple[str, str] | None]]:
|
|
118
|
+
"""Comentário de linha e de bloco por escopo, a partir de arquivos ``.tmPreferences``."""
|
|
119
|
+
out: dict[str, tuple[str | None, tuple[str, str] | None]] = {}
|
|
120
|
+
for raw in plists:
|
|
121
|
+
try:
|
|
122
|
+
data = plistlib.loads(raw)
|
|
123
|
+
except Exception: # plist inválido de terceiros; só este arquivo é perdido
|
|
124
|
+
continue
|
|
125
|
+
scope = data.get("scope") if isinstance(data, dict) else None
|
|
126
|
+
variables = as_dict(data.get("settings")).get("shellVariables") if isinstance(data, dict) else None
|
|
127
|
+
if not isinstance(scope, str) or not isinstance(variables, list):
|
|
128
|
+
continue
|
|
129
|
+
values = {str(v.get("name")): str(v.get("value", "")) for v in variables if isinstance(v, dict)}
|
|
130
|
+
line = values.get("TM_COMMENT_START")
|
|
131
|
+
block = None
|
|
132
|
+
if values.get("TM_COMMENT_START_2") and values.get("TM_COMMENT_END_2"):
|
|
133
|
+
block = (values["TM_COMMENT_START_2"].strip(), values["TM_COMMENT_END_2"].strip())
|
|
134
|
+
if line is not None or block:
|
|
135
|
+
out[scope.split(",")[0].strip()] = ((line or "").strip() or None, block)
|
|
136
|
+
return out
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def language_from_grammar(
|
|
140
|
+
grammar: dict[str, Any],
|
|
141
|
+
ext: Extension,
|
|
142
|
+
known: set[str],
|
|
143
|
+
*,
|
|
144
|
+
fallback: str,
|
|
145
|
+
extensions: list[str] | None = None,
|
|
146
|
+
comments: dict[str, tuple[str | None, tuple[str, str] | None]] | None = None,
|
|
147
|
+
) -> None:
|
|
148
|
+
"""Acrescenta a linguagem da gramática a ``ext`` (ou registra por que foi deixada de fora)."""
|
|
149
|
+
scope = str(grammar.get("scopeName") or grammar.get("scope") or "")
|
|
150
|
+
name = str(grammar.get("name") or fallback)
|
|
151
|
+
lid = scope_lang(scope) or lang_id(slug(name).replace("_", "-"))
|
|
152
|
+
if lid in known:
|
|
153
|
+
note = f"linguagem '{lid}' já existe no Codis (realce nativo mantido)"
|
|
154
|
+
if note not in ext.ignored:
|
|
155
|
+
ext.ignored.append(note)
|
|
156
|
+
return
|
|
157
|
+
raw_types = extensions if extensions is not None else grammar.get("fileTypes") or []
|
|
158
|
+
suffixes = [e if str(e).startswith(".") else f".{e}" for e in raw_types if isinstance(e, str) and e]
|
|
159
|
+
if not suffixes:
|
|
160
|
+
return
|
|
161
|
+
spec = LanguageSpec(id=lid, label=name, extensions=[s.lower() for s in suffixes])
|
|
162
|
+
prefs = comments or {}
|
|
163
|
+
for key, (line, block) in prefs.items():
|
|
164
|
+
if scope and (scope == key or scope.startswith(key + ".") or key.startswith(scope + ".")):
|
|
165
|
+
spec.comment, spec.comment_block = line, block
|
|
166
|
+
break
|
|
167
|
+
try:
|
|
168
|
+
spec.patterns, spec.keywords = textmate.grammar_to_tokens(grammar)
|
|
169
|
+
except Exception as exc:
|
|
170
|
+
ext.warnings.append(f"gramática de '{lid}' não pôde ser lida: {type(exc).__name__}")
|
|
171
|
+
if not any(lg.id == lid for lg in ext.languages):
|
|
172
|
+
ext.languages.append(spec)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def load_sublime_syntax(text: str) -> dict[str, Any]:
|
|
176
|
+
doc = yamlite.loads(text)
|
|
177
|
+
if not isinstance(doc, dict):
|
|
178
|
+
raise ValueError("o arquivo de sintaxe não é um mapa YAML")
|
|
179
|
+
return doc
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def lang_snippets(scope_text: str, trigger: str, body: str, desc: str) -> list[SnippetSpec]:
|
|
183
|
+
"""Um snippet por linguagem citada em ``scope_text`` (``source.js, source.ts``)."""
|
|
184
|
+
langs: list[str] = []
|
|
185
|
+
for part in scope_text.split(","):
|
|
186
|
+
lang = scope_lang(part.strip())
|
|
187
|
+
if lang and lang not in langs:
|
|
188
|
+
langs.append(lang)
|
|
189
|
+
return [SnippetSpec(lang, trigger, body, desc) for lang in langs]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Utilidades dos leitores de editores menores: cores ANSI, tabelas de função e leitura de texto."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
_ANSI16 = [
|
|
6
|
+
"#000000", "#cd0000", "#00cd00", "#cdcd00", "#0000ee", "#cd00cd", "#00cdcd", "#e5e5e5",
|
|
7
|
+
"#7f7f7f", "#ff0000", "#00ff00", "#ffff00", "#5c5cff", "#ff00ff", "#00ffff", "#ffffff",
|
|
8
|
+
]
|
|
9
|
+
_ANSI_NAMES = {
|
|
10
|
+
"black": 0, "red": 1, "green": 2, "yellow": 3, "blue": 4, "magenta": 5, "cyan": 6, "white": 7,
|
|
11
|
+
"brightblack": 8, "brightred": 9, "brightgreen": 10, "brightyellow": 11, "brightblue": 12,
|
|
12
|
+
"brightmagenta": 13, "brightcyan": 14, "brightwhite": 15, "grey": 8, "gray": 8, "lightgrey": 7,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def ansi_color(token: str) -> str | None:
|
|
17
|
+
"""Nome ANSI (``brightblue``) ou índice 0-255 em ``#rrggbb``; ``None`` se não for nenhum."""
|
|
18
|
+
token = token.strip().lower()
|
|
19
|
+
if token in _ANSI_NAMES:
|
|
20
|
+
return _ANSI16[_ANSI_NAMES[token]]
|
|
21
|
+
if token.isdigit() and int(token) < 256:
|
|
22
|
+
n = int(token)
|
|
23
|
+
if n < 16:
|
|
24
|
+
return _ANSI16[n]
|
|
25
|
+
if n >= 232:
|
|
26
|
+
level = 8 + (n - 232) * 10
|
|
27
|
+
return f"#{level:02x}{level:02x}{level:02x}"
|
|
28
|
+
n -= 16
|
|
29
|
+
steps = (0, 95, 135, 175, 215, 255)
|
|
30
|
+
return f"#{steps[n // 36]:02x}{steps[(n // 6) % 6]:02x}{steps[n % 6]:02x}"
|
|
31
|
+
return None
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Base16/Base24 (tinted-theming): esquemas de 16 cores em YAML, JSON ou TOML, e os terminais que os usam."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from .. import registry
|
|
9
|
+
from ..common import decode, title_of
|
|
10
|
+
from ..model import Extension, ThemeSpec
|
|
11
|
+
from ..registry import Format
|
|
12
|
+
from ..sources import Bundle
|
|
13
|
+
from ..themes import assemble, slug
|
|
14
|
+
|
|
15
|
+
_PAIR = re.compile(r"""\bbase0([0-9A-Fa-f])["']?\s*[:=]\s*["']?(?:#|0x)?([0-9A-Fa-f]{6})\b""")
|
|
16
|
+
_NAME = re.compile(r"""^\s*["']?(?:scheme|name)["']?\s*[:=]\s*["']?([^"'\n#]+)""", re.MULTILINE)
|
|
17
|
+
_SUFFIXES = (".yaml", ".yml", ".json", ".toml", ".conf")
|
|
18
|
+
_MAX_FILES = 400
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def parse(text: str) -> dict[int, str]:
|
|
22
|
+
found = {int(m.group(1), 16): f"#{m.group(2)}" for m in _PAIR.finditer(text)}
|
|
23
|
+
return found if len(found) == 16 else {}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _files(bundle: Bundle) -> list[str]:
|
|
27
|
+
out = []
|
|
28
|
+
for rel in bundle.with_suffix(*_SUFFIXES)[:_MAX_FILES]:
|
|
29
|
+
raw = bundle.read(rel)
|
|
30
|
+
if raw and len(raw) < 60_000 and b"base0" in raw and parse(decode(raw)):
|
|
31
|
+
out.append(rel)
|
|
32
|
+
return out
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _is_base16(root: Path) -> bool:
|
|
36
|
+
return bool(_files(Bundle(root)))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def from_base16(palette: dict[int, str], *, theme_id: str, name: str) -> ThemeSpec:
|
|
40
|
+
b = palette
|
|
41
|
+
fields = {
|
|
42
|
+
"bg": b[0x0], "editor_bg": b[0x0], "sidebar_bg": b[0x1], "line_hl": b[0x1], "sel_bg": b[0x2],
|
|
43
|
+
"t_comment": b[0x3], "gutter_fg": b[0x3], "fg_muted": b[0x4], "fg": b[0x5], "cursor": b[0x5],
|
|
44
|
+
"t_variable": b[0x8], "t_tag": b[0x8], "err_fg": b[0x8], "t_number": b[0x9], "t_constant": b[0x9],
|
|
45
|
+
"t_attr": b[0x9], "warn_fg": b[0xA], "t_type": b[0xA], "t_class": b[0xA], "t_string": b[0xB],
|
|
46
|
+
"ok_fg": b[0xB], "t_regex": b[0xC], "t_escape": b[0xC], "t_builtin": b[0xC], "t_func": b[0xD],
|
|
47
|
+
"accent": b[0xD], "t_keyword": b[0xE], "t_decorator": b[0xF], "t_operator": b[0x5],
|
|
48
|
+
}
|
|
49
|
+
return assemble(theme_id, name, fields)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def load_base16(root: Path, known: set[str]) -> Extension:
|
|
53
|
+
bundle = Bundle(root)
|
|
54
|
+
ext = Extension(id=f"base16.{slug(root.name)}", name=root.name, version="0", kind="base16", path=root)
|
|
55
|
+
for rel in _files(bundle):
|
|
56
|
+
text = decode(bundle.read(rel) or b"")
|
|
57
|
+
stem = Path(rel).stem
|
|
58
|
+
m = _NAME.search(text)
|
|
59
|
+
ext.themes.append(from_base16(parse(text), theme_id=f"base16_{slug(stem)}", name=(m.group(1).strip() if m else title_of(stem))))
|
|
60
|
+
return ext
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
registry.register(Format(
|
|
64
|
+
"base16", "Base16 / Tinted Theming", _is_base16, load_base16, priority=65, suffixes=(".yaml", ".yml"),
|
|
65
|
+
provides="esquemas de 16 cores",
|
|
66
|
+
))
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""Brackets e temas do CodeMirror: cores a partir de CSS/LESS (``.cm-s-*``) e linguagens de ``defineLanguage``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .. import lessish, registry
|
|
11
|
+
from ..common import decode, simple_tokens, title_of
|
|
12
|
+
from ..jsonc import as_dict
|
|
13
|
+
from ..model import Extension, LanguageSpec, ThemeSpec
|
|
14
|
+
from ..registry import Format
|
|
15
|
+
from ..sources import Bundle
|
|
16
|
+
from ..themes import assemble, slug
|
|
17
|
+
|
|
18
|
+
_MAX_FILES = 200
|
|
19
|
+
_TOKEN_FIELDS = {
|
|
20
|
+
"t_keyword": ("cm-keyword",),
|
|
21
|
+
"t_string": ("cm-string",),
|
|
22
|
+
"t_regex": ("cm-string-2",),
|
|
23
|
+
"t_comment": ("cm-comment",),
|
|
24
|
+
"t_number": ("cm-number",),
|
|
25
|
+
"t_func": ("cm-def",),
|
|
26
|
+
"t_type": ("cm-variable-3", "cm-type"),
|
|
27
|
+
"t_variable": ("cm-variable", "cm-variable-2"),
|
|
28
|
+
"t_operator": ("cm-operator",),
|
|
29
|
+
"t_decorator": ("cm-meta",),
|
|
30
|
+
"t_constant": ("cm-atom",),
|
|
31
|
+
"t_builtin": ("cm-builtin",),
|
|
32
|
+
"t_tag": ("cm-tag",),
|
|
33
|
+
"t_attr": ("cm-attribute", "cm-property"),
|
|
34
|
+
"t_heading": ("cm-header",),
|
|
35
|
+
"t_link": ("cm-link",),
|
|
36
|
+
"t_invalid": ("cm-error",),
|
|
37
|
+
}
|
|
38
|
+
_DEFINE = re.compile(r"""defineLanguage\(\s*["']([\w+#-]+)["']\s*,\s*\{(.*?)\}\s*\)""", re.DOTALL)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _package(bundle: Bundle) -> dict[str, Any]:
|
|
42
|
+
raw = bundle.read("package.json")
|
|
43
|
+
try:
|
|
44
|
+
return as_dict(json.loads(decode(raw))) if raw else {}
|
|
45
|
+
except ValueError:
|
|
46
|
+
return {}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _codemirror_css(bundle: Bundle) -> list[str]:
|
|
50
|
+
out = []
|
|
51
|
+
for rel in bundle.with_suffix(".css", ".less")[:_MAX_FILES]:
|
|
52
|
+
raw = bundle.read(rel)
|
|
53
|
+
if raw and b".cm-s-" in raw:
|
|
54
|
+
out.append(rel)
|
|
55
|
+
return out
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _is_brackets(root: Path) -> bool:
|
|
59
|
+
bundle = Bundle(root)
|
|
60
|
+
pkg = _package(bundle)
|
|
61
|
+
if "brackets" in as_dict(pkg.get("engines")):
|
|
62
|
+
return True
|
|
63
|
+
if pkg and not pkg.get("engines") and as_dict(pkg.get("theme")).get("file"):
|
|
64
|
+
return True
|
|
65
|
+
return not pkg and bool(_codemirror_css(bundle))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def theme_from_codemirror(text: str, *, theme_id: str, name: str, dark: bool | None = None) -> ThemeSpec | None:
|
|
69
|
+
table = lessish.variables(text)
|
|
70
|
+
rules = lessish.parse_rules(text, table)
|
|
71
|
+
fields: dict[str, str | None] = {}
|
|
72
|
+
by_class: dict[str, str] = {}
|
|
73
|
+
for selector, decl in rules:
|
|
74
|
+
for sel in selector.split(","):
|
|
75
|
+
last = sel.strip().split()[-1] if sel.strip() else ""
|
|
76
|
+
classes = re.findall(r"\.([\w-]+)", last)
|
|
77
|
+
color = decl.get("color")
|
|
78
|
+
if color and lessish.col.parse(color) is not None:
|
|
79
|
+
for cls in classes:
|
|
80
|
+
if cls.startswith("cm-") and not cls.startswith("cm-s-"):
|
|
81
|
+
by_class[cls] = color
|
|
82
|
+
bg = decl.get("background") or decl.get("background-color")
|
|
83
|
+
if "CodeMirror" in sel and not re.search(r"CodeMirror-\w", sel.split()[-1]) and "cm-" not in last.replace("cm-s-", ""):
|
|
84
|
+
if bg and lessish.col.parse(bg):
|
|
85
|
+
fields["bg"] = fields["editor_bg"] = bg
|
|
86
|
+
if color and lessish.col.parse(color):
|
|
87
|
+
fields["fg"] = color
|
|
88
|
+
elif "CodeMirror-selected" in last and bg:
|
|
89
|
+
fields["sel_bg"] = bg
|
|
90
|
+
elif "CodeMirror-gutters" in last and bg:
|
|
91
|
+
fields["sidebar_bg"] = bg
|
|
92
|
+
elif "CodeMirror-linenumber" in last and color:
|
|
93
|
+
fields["gutter_fg"] = color
|
|
94
|
+
elif "CodeMirror-activeline-background" in last and bg:
|
|
95
|
+
fields["line_hl"] = bg
|
|
96
|
+
elif "CodeMirror-cursor" in last:
|
|
97
|
+
border = decl.get("border-left", "")
|
|
98
|
+
m = re.search(r"(#[0-9a-fA-F]{3,8}|rgba?\([^)]*\)|hsla?\([^)]*\))", border)
|
|
99
|
+
if m:
|
|
100
|
+
fields["cursor"] = m.group(1)
|
|
101
|
+
for target, classes in _TOKEN_FIELDS.items():
|
|
102
|
+
found = next((by_class[c] for c in classes if c in by_class), None)
|
|
103
|
+
if found:
|
|
104
|
+
fields[target] = found
|
|
105
|
+
if not (fields.get("bg") or fields.get("fg")):
|
|
106
|
+
return None
|
|
107
|
+
return assemble(theme_id, name, fields, dark)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _list_of(value: str, key: str) -> list[str]:
|
|
111
|
+
m = re.search(rf"{key}\s*:\s*\[(.*?)\]", value, re.DOTALL)
|
|
112
|
+
return re.findall(r"""["']([^"']+)["']""", m.group(1)) if m else []
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def languages_from_js(text: str, known: set[str]) -> list[LanguageSpec]:
|
|
116
|
+
"""``LanguageManager.defineLanguage`` lido como texto: o JavaScript não é executado."""
|
|
117
|
+
out: list[LanguageSpec] = []
|
|
118
|
+
for lid, body in _DEFINE.findall(text):
|
|
119
|
+
lid = lid.lower()
|
|
120
|
+
exts = [f".{e.lstrip('.').lower()}" for e in _list_of(body, "fileExtensions")]
|
|
121
|
+
if lid in known or not exts:
|
|
122
|
+
continue
|
|
123
|
+
line = _list_of(body, "lineComment")
|
|
124
|
+
block = _list_of(body, "blockComment")
|
|
125
|
+
name = re.search(r"""name\s*:\s*["']([^"']+)["']""", body)
|
|
126
|
+
tokens, kws = simple_tokens(line_comment=line[0] if line else None, block_comment=(block[0], block[1]) if len(block) == 2 else None)
|
|
127
|
+
out.append(LanguageSpec(
|
|
128
|
+
id=lid, label=name.group(1) if name else title_of(lid), extensions=exts,
|
|
129
|
+
comment=line[0].strip() if line else None, comment_block=(block[0], block[1]) if len(block) == 2 else None,
|
|
130
|
+
patterns=tokens, keywords=kws,
|
|
131
|
+
))
|
|
132
|
+
return out
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def load_brackets(root: Path, known: set[str]) -> Extension:
|
|
136
|
+
bundle = Bundle(root)
|
|
137
|
+
pkg = _package(bundle)
|
|
138
|
+
name = str(pkg.get("title") or pkg.get("name") or root.name)
|
|
139
|
+
ext = Extension(
|
|
140
|
+
id=f"brackets.{slug(str(pkg.get('name') or root.name))}", name=name, version=str(pkg.get("version") or "0"),
|
|
141
|
+
kind="brackets", path=root, description=str(pkg.get("description") or ""),
|
|
142
|
+
)
|
|
143
|
+
theme_meta = as_dict(pkg.get("theme"))
|
|
144
|
+
css_files = _codemirror_css(bundle)
|
|
145
|
+
declared = theme_meta.get("file")
|
|
146
|
+
if isinstance(declared, str) and bundle.has(declared.lstrip("./")) and declared.lstrip("./") not in css_files:
|
|
147
|
+
css_files.append(declared.lstrip("./"))
|
|
148
|
+
for rel in css_files:
|
|
149
|
+
stem = Path(rel).stem
|
|
150
|
+
label = name if len(css_files) == 1 and pkg else title_of(stem)
|
|
151
|
+
spec = theme_from_codemirror(
|
|
152
|
+
bundle.text(rel) or "", theme_id=f"brackets_{slug(name)}_{slug(stem)}", name=label,
|
|
153
|
+
dark=theme_meta.get("dark") if isinstance(theme_meta.get("dark"), bool) else None,
|
|
154
|
+
)
|
|
155
|
+
if spec:
|
|
156
|
+
ext.themes.append(spec)
|
|
157
|
+
else:
|
|
158
|
+
ext.warnings.append(f"{Path(rel).name}: nenhuma cor de tema encontrada")
|
|
159
|
+
for rel in bundle.with_suffix(".js")[:_MAX_FILES]:
|
|
160
|
+
raw = bundle.text(rel)
|
|
161
|
+
if raw and "defineLanguage" in raw:
|
|
162
|
+
ext.languages.extend(lg for lg in languages_from_js(raw, known) if not any(x.id == lg.id for x in ext.languages))
|
|
163
|
+
if any(n.endswith(".js") for n in bundle.names()[:2000]) and not theme_meta:
|
|
164
|
+
ext.ignored.append("código JavaScript da extensão (usa a API do Brackets, não é executado)")
|
|
165
|
+
return ext
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
registry.register(Format(
|
|
169
|
+
"brackets", "Brackets / CodeMirror", _is_brackets, load_brackets, priority=11,
|
|
170
|
+
suffixes=(".css", ".less"),
|
|
171
|
+
provides="temas do CodeMirror e linguagens declaradas",
|
|
172
|
+
))
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Eclipse: temas do Eclipse Color Theme, templates de código e gramáticas TextMate (TM4E)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from .. import registry, textmate
|
|
9
|
+
from ..common import decode
|
|
10
|
+
from ..model import Extension, SnippetSpec, ThemeSpec
|
|
11
|
+
from ..registry import Format
|
|
12
|
+
from ..safexml import children, descendants, local, parse_xml
|
|
13
|
+
from ..sources import Bundle
|
|
14
|
+
from ..themes import assemble, slug
|
|
15
|
+
from . import _tm
|
|
16
|
+
|
|
17
|
+
_MAX_ITEMS = 400
|
|
18
|
+
_THEME_TAGS = {
|
|
19
|
+
"t_comment": ("singleLineComment", "multiLineComment"),
|
|
20
|
+
"t_keyword": ("keyword",),
|
|
21
|
+
"t_string": ("string",),
|
|
22
|
+
"t_number": ("number",),
|
|
23
|
+
"t_class": ("class", "interface"),
|
|
24
|
+
"t_type": ("class", "interface"),
|
|
25
|
+
"t_func": ("methodDeclaration", "method"),
|
|
26
|
+
"t_decorator": ("annotation",),
|
|
27
|
+
"t_operator": ("operator",),
|
|
28
|
+
"t_constant": ("constant", "staticFinalField"),
|
|
29
|
+
"t_variable": ("localVariable", "field"),
|
|
30
|
+
"t_attr": ("field",),
|
|
31
|
+
}
|
|
32
|
+
_UI_TAGS = {
|
|
33
|
+
"fg": "foreground", "bg": "background", "editor_bg": "background", "sel_bg": "selectionBackground",
|
|
34
|
+
"sel_fg": "selectionForeground", "gutter_fg": "lineNumber", "line_hl": "currentLine",
|
|
35
|
+
}
|
|
36
|
+
_CONTEXT_LANG = (
|
|
37
|
+
("javascript", "javascript"), ("java", "java"), ("python", "python"), ("pydev", "python"),
|
|
38
|
+
("php", "php"), ("html", "html"), ("css", "css"), ("xml", "xml"), ("sql", "sql"),
|
|
39
|
+
("cdt", "cpp"), ("c++", "cpp"), ("golang", "go"), ("rust", "rust"), ("ruby", "ruby"),
|
|
40
|
+
("shell", "shell"), ("typescript", "typescript"), ("json", "json"),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _is_eclipse(root: Path) -> bool:
|
|
45
|
+
bundle = Bundle(root, jars=True)
|
|
46
|
+
head = (bundle.read("plugin.xml") or b"")[:2000]
|
|
47
|
+
if b"<plugin" in head or b"<?eclipse" in head:
|
|
48
|
+
return True
|
|
49
|
+
for rel in bundle.glob("*.xml")[:12]:
|
|
50
|
+
head = (bundle.read(rel) or b"")[:3000]
|
|
51
|
+
if b"<colorTheme" in head or (b"<templates" in head and b"<template " in head):
|
|
52
|
+
return True
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def from_color_theme(raw: bytes, *, theme_id: str, fallback: str) -> ThemeSpec | None:
|
|
57
|
+
root = parse_xml(raw)
|
|
58
|
+
if root is None or local(root.tag) != "colorTheme":
|
|
59
|
+
return None
|
|
60
|
+
colors = {local(el.tag): el.get("color") for el in root if el.get("color")}
|
|
61
|
+
fields: dict[str, str | None] = {}
|
|
62
|
+
for target, tag in _UI_TAGS.items():
|
|
63
|
+
fields[target] = colors.get(tag)
|
|
64
|
+
for target, tags in _THEME_TAGS.items():
|
|
65
|
+
fields[target] = next((colors[t] for t in tags if t in colors), None)
|
|
66
|
+
if not (fields["bg"] or fields["fg"]):
|
|
67
|
+
return None
|
|
68
|
+
return assemble(theme_id, root.get("name") or fallback, fields)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def convert_template(value: str) -> str:
|
|
72
|
+
"""``${nome}`` do Eclipse vira ``${n:nome}``; ``${cursor}`` vira ``$0`` e ``$$`` vira ``$``."""
|
|
73
|
+
order: dict[str, int] = {}
|
|
74
|
+
|
|
75
|
+
def replace(match: re.Match[str]) -> str:
|
|
76
|
+
if match.group(0) == "$$":
|
|
77
|
+
return "$"
|
|
78
|
+
name = match.group(1).split(":")[0].strip()
|
|
79
|
+
if name == "cursor":
|
|
80
|
+
return "$0"
|
|
81
|
+
if name in ("line_selection", "word_selection"):
|
|
82
|
+
return ""
|
|
83
|
+
if name not in order:
|
|
84
|
+
order[name] = len(order) + 1
|
|
85
|
+
return f"${{{order[name]}:{name}}}"
|
|
86
|
+
return f"${order[name]}"
|
|
87
|
+
|
|
88
|
+
return re.sub(r"\$\$|\$\{([^}]*)\}", replace, value)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _context_lang(context: str) -> str | None:
|
|
92
|
+
low = context.lower()
|
|
93
|
+
return next((lang for key, lang in _CONTEXT_LANG if key in low), None)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _template_snippets(root_el, default_context: str = "") -> list[SnippetSpec]:
|
|
97
|
+
out: list[SnippetSpec] = []
|
|
98
|
+
for tpl in descendants(root_el, "template"):
|
|
99
|
+
name = tpl.get("name")
|
|
100
|
+
body = (tpl.text or "").strip("\n")
|
|
101
|
+
for pattern in children(tpl, "pattern"):
|
|
102
|
+
body = (pattern.text or "").strip("\n")
|
|
103
|
+
lang = _context_lang(tpl.get("context") or tpl.get("contextTypeId") or default_context)
|
|
104
|
+
if name and body and lang and tpl.get("deleted") != "true":
|
|
105
|
+
out.append(SnippetSpec(lang, name, convert_template(body), tpl.get("description") or name))
|
|
106
|
+
return out
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _manifest(raw: bytes | None) -> dict[str, str]:
|
|
110
|
+
if not raw:
|
|
111
|
+
return {}
|
|
112
|
+
text = decode(raw).replace("\r\n", "\n").replace("\n ", "")
|
|
113
|
+
out: dict[str, str] = {}
|
|
114
|
+
for line in text.split("\n"):
|
|
115
|
+
key, sep, value = line.partition(":")
|
|
116
|
+
if sep:
|
|
117
|
+
out[key.strip()] = value.strip()
|
|
118
|
+
return out
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def load_eclipse(root: Path, known: set[str]) -> Extension:
|
|
122
|
+
bundle = Bundle(root, jars=True)
|
|
123
|
+
mf = _manifest(bundle.read("META-INF/MANIFEST.MF"))
|
|
124
|
+
plugin = parse_xml(bundle.read("plugin.xml") or b"")
|
|
125
|
+
sym = mf.get("Bundle-SymbolicName", "").split(";")[0]
|
|
126
|
+
name = mf.get("Bundle-Name") if mf.get("Bundle-Name") and not mf["Bundle-Name"].startswith("%") else (sym or root.name)
|
|
127
|
+
ext = Extension(
|
|
128
|
+
id=f"eclipse.{slug(sym or root.name)}", name=name or root.name, version=mf.get("Bundle-Version", "0"),
|
|
129
|
+
kind="eclipse", path=root, publisher=mf.get("Bundle-Vendor", "") if not mf.get("Bundle-Vendor", "").startswith("%") else "",
|
|
130
|
+
)
|
|
131
|
+
used: set[str] = set()
|
|
132
|
+
for rel in bundle.glob("*.xml")[:_MAX_ITEMS]:
|
|
133
|
+
raw = bundle.read(rel) or b""
|
|
134
|
+
head = raw[:3000]
|
|
135
|
+
if b"<colorTheme" in head:
|
|
136
|
+
stem = Path(rel).stem
|
|
137
|
+
spec = from_color_theme(raw, theme_id=f"eclipse_{slug(ext.name)}_{slug(stem)}", fallback=stem)
|
|
138
|
+
if spec and spec.id not in used:
|
|
139
|
+
used.add(spec.id)
|
|
140
|
+
ext.themes.append(spec)
|
|
141
|
+
elif b"<templates" in head:
|
|
142
|
+
root_el = parse_xml(raw)
|
|
143
|
+
if root_el is not None:
|
|
144
|
+
ext.snippets.extend(_template_snippets(root_el))
|
|
145
|
+
if plugin is not None:
|
|
146
|
+
for el in descendants(plugin, "extension"):
|
|
147
|
+
point = el.get("point") or ""
|
|
148
|
+
if point.endswith("ui.editors.templates"):
|
|
149
|
+
for inc in children(el, "include"):
|
|
150
|
+
ref = bundle.resolve(inc.get("file") or "")
|
|
151
|
+
inc_root = parse_xml(bundle.read(ref) or b"") if ref else None
|
|
152
|
+
if inc_root is not None:
|
|
153
|
+
ext.snippets.extend(_template_snippets(inc_root))
|
|
154
|
+
ext.snippets.extend(_template_snippets(el, default_context=el.get("point") or ""))
|
|
155
|
+
_tm4e(plugin, bundle, ext, known)
|
|
156
|
+
points = {el.get("point", "") for el in descendants(plugin, "extension")}
|
|
157
|
+
handled = ("ui.editors.templates", "tm4e.registry.grammars", "core.contenttype.contentTypes")
|
|
158
|
+
if any(not p.endswith(handled) for p in points):
|
|
159
|
+
ext.ignored.append("contribuições de interface e de código do plugin (OSGi/Java, não executadas)")
|
|
160
|
+
if any(n.endswith(".class") for n in bundle.names()[:5000]) and not any("Java" in i for i in ext.ignored):
|
|
161
|
+
ext.ignored.append("código Java do plugin (OSGi, não executado)")
|
|
162
|
+
return ext
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _tm4e(plugin, bundle: Bundle, ext: Extension, known: set[str]) -> None:
|
|
166
|
+
"""Gramáticas registradas pelo TM4E e as extensões de arquivo dos tipos de conteúdo."""
|
|
167
|
+
scope_exts: dict[str, list[str]] = {}
|
|
168
|
+
type_exts: dict[str, list[str]] = {}
|
|
169
|
+
for ct in descendants(plugin, "content-type"):
|
|
170
|
+
raw = ct.get("file-extensions") or ""
|
|
171
|
+
type_exts[ct.get("id") or ""] = [f".{e.strip().lstrip('.').lower()}" for e in raw.split(",") if e.strip()]
|
|
172
|
+
for bind in descendants(plugin, "scopeNameContentTypeBinding"):
|
|
173
|
+
scope_exts.setdefault(bind.get("scopeName") or "", []).extend(type_exts.get(bind.get("contentTypeId") or "", []))
|
|
174
|
+
for el in descendants(plugin, "grammar"):
|
|
175
|
+
rel = bundle.resolve(el.get("path") or "")
|
|
176
|
+
raw = bundle.read(rel) if rel else None
|
|
177
|
+
if not raw:
|
|
178
|
+
continue
|
|
179
|
+
scope = el.get("scopeName") or ""
|
|
180
|
+
try:
|
|
181
|
+
grammar = textmate.load_grammar(raw)
|
|
182
|
+
grammar.setdefault("scopeName", scope)
|
|
183
|
+
exts = scope_exts.get(scope) or None
|
|
184
|
+
_tm.language_from_grammar(grammar, ext, known, fallback=Path(rel).name.split(".")[0], extensions=exts)
|
|
185
|
+
except Exception as exc:
|
|
186
|
+
ext.warnings.append(f"gramática ilegível: {Path(rel or '').name} ({type(exc).__name__})")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
registry.register(Format(
|
|
190
|
+
"eclipse", "Eclipse", _is_eclipse, load_eclipse, priority=31,
|
|
191
|
+
suffixes=(),
|
|
192
|
+
provides="temas do Eclipse Color Theme, templates e gramáticas TextMate",
|
|
193
|
+
))
|