migrate ui components to gpui-kit
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Phase A fix-up: route gpui_kit::component imports to their real module paths,
|
||||
rewrite font-weight helpers. Run from repo root. Idempotent."""
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# item -> full module path under gpui_kit::component (None = keep at root)
|
||||
MODULE_PATHS = {
|
||||
"Avatar": "avatar",
|
||||
"Button": "button",
|
||||
"ButtonVariants": "button",
|
||||
"ButtonVariant": "button",
|
||||
"ButtonCustomVariant": "button",
|
||||
"ButtonGroup": "button",
|
||||
"DropdownButton": "button",
|
||||
"Toggle": "button",
|
||||
"Notification": "notification",
|
||||
"NotificationType": "notification",
|
||||
"Switch": "switch",
|
||||
"GroupBox": "group_box",
|
||||
"GroupBoxVariants": "group_box",
|
||||
"GroupBoxVariant": "group_box",
|
||||
"Tab": "tab",
|
||||
"TabBar": "tab",
|
||||
"Scrollbar": "scroll",
|
||||
"ScrollableElement": "scroll",
|
||||
"Input": "input",
|
||||
"InputState": "input",
|
||||
"Textarea": "textarea" if False else "input",
|
||||
"TextareaState": "input",
|
||||
"InputEvent": "input",
|
||||
"PopupMenu": "menu",
|
||||
"PopupMenuItem": "menu",
|
||||
"DropdownMenu": "menu",
|
||||
"ContextMenu": "menu",
|
||||
"Dialog": "dialog",
|
||||
"DialogButtonProps": "dialog",
|
||||
"AlertDialog": "dialog",
|
||||
"DockArea": "dock",
|
||||
"DockLayout": "dock",
|
||||
"DockPlacement": "dock",
|
||||
"Panel": "dock",
|
||||
"PanelEvent": "dock",
|
||||
"PanelHandle": "dock",
|
||||
"ClosePanel": "dock",
|
||||
"DockSkin": "dock",
|
||||
"Spinner": "spinner",
|
||||
"Tooltip": "tooltip",
|
||||
"Badge": "badge",
|
||||
"Marker": "marker",
|
||||
"Kbd": "kbd",
|
||||
"Sidebar": "sidebar",
|
||||
"SidebarMenu": "sidebar",
|
||||
"SidebarMenuItem": "sidebar",
|
||||
"SidebarGroup": "sidebar",
|
||||
"SidebarHeader": "sidebar",
|
||||
"SidebarFooter": "sidebar",
|
||||
"SidebarItem": "sidebar",
|
||||
}
|
||||
|
||||
FILES = list(Path("crates").rglob("*.rs"))
|
||||
|
||||
kit_re = re.compile(r"^use gpui_kit::component::\{([^}]*)\};")
|
||||
|
||||
for f in FILES:
|
||||
src = f.read_text()
|
||||
lines = src.split("\n")
|
||||
buckets = {}
|
||||
keep = []
|
||||
for line in lines:
|
||||
m = kit_re.match(line.strip())
|
||||
if m:
|
||||
for item in [i.strip() for i in m.group(1).split(",") if i.strip()]:
|
||||
base = item.split(" as ")[0].strip()
|
||||
mod = MODULE_PATHS.get(base)
|
||||
buckets.setdefault(mod, []).append(item)
|
||||
else:
|
||||
keep.append(line)
|
||||
if buckets:
|
||||
imports = []
|
||||
for mod, items in sorted(buckets.items(), key=lambda kv: kv[0] or ""):
|
||||
uniq = sorted(set(items))
|
||||
if mod is None:
|
||||
imports.append(f"use gpui_kit::component::{{{', '.join(uniq)}}};")
|
||||
else:
|
||||
imports.append(f"use gpui_kit::component::{mod}::{{{', '.join(uniq)}}};")
|
||||
# insert after the last existing `use` at top or just append imports where first import was
|
||||
keep[0:0] = imports
|
||||
src = "\n".join(keep)
|
||||
|
||||
# font weight helpers (gpui_base::StyledExt has none)
|
||||
src = src.replace(".font_semibold()", ".font_weight(gpui::FontWeight::SEMIBOLD)")
|
||||
src = src.replace(".font_medium()", ".font_weight(gpui::FontWeight::MEDIUM)")
|
||||
src = src.replace(".font_normal()", ".font_weight(gpui::FontWeight::NORMAL)")
|
||||
|
||||
if src != f.read_text():
|
||||
f.write_text(src)
|
||||
print("fixed", f)
|
||||
Reference in New Issue
Block a user