diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index 6e37626..816b58b 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -92,6 +92,23 @@ def get_xml(namespace: str, version: str): return _xml_cache[filename] +ONLINE_DOCS = { + "Adw-1": "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/", + "Gdk-4.0": "https://docs.gtk.org/gdk4/", + "GdkPixbuf-2.0": "https://docs.gtk.org/gdk-pixbuf/", + "Gio-2.0": "https://docs.gtk.org/gio/", + "GLib-2.0": "https://docs.gtk.org/glib/", + "GModule-2.0": "https://docs.gtk.org/gmodule/", + "GObject-2.0": "https://docs.gtk.org/gobject/", + "Gsk-4.0": "https://docs.gtk.org/gsk4/", + "Gtk-4.0": "https://docs.gtk.org/gtk4/", + "GtkSource-5": "https://gnome.pages.gitlab.gnome.org/gtksourceview/gtksourceview5", + "Pango-1.0": "https://docs.gtk.org/Pango/", + "Shumate-1.0": "https://gnome.pages.gitlab.gnome.org/libshumate/", + "WebKit2-4.1": "https://webkitgtk.org/reference/webkit2gtk/stable/", +} + + class GirType: @property def doc(self) -> T.Optional[str]: @@ -291,10 +308,17 @@ class GirNode: except: # Not a huge deal, but if you want docs in the language server you # should ensure .gir files are installed - pass + sections.append("Documentation is not installed") + + if self.online_docs: + sections.append(f"[Online documentation]({self.online_docs})") return "\n\n---\n\n".join(sections) + @property + def online_docs(self) -> T.Optional[str]: + return None + @property def signature(self) -> T.Optional[str]: return None @@ -328,6 +352,14 @@ class Property(GirNode): def construct_only(self) -> bool: return self.tl.PROP_CONSTRUCT_ONLY == 1 + @property + def online_docs(self) -> T.Optional[str]: + if ns := self.get_containing(Namespace).online_docs: + assert self.container is not None + return f"{ns}property.{self.container.name}.{self.name}.html" + else: + return None + class Argument(GirNode): def __init__(self, container: GirNode, tl: typelib.Typelib) -> None: @@ -380,6 +412,14 @@ class Signal(GirNode): ) return f"signal {self.container.full_name}::{self.name} ({args})" + @property + def online_docs(self) -> T.Optional[str]: + if ns := self.get_containing(Namespace).online_docs: + assert self.container is not None + return f"{ns}signal.{self.container.name}.{self.name}.html" + else: + return None + class Interface(GirNode, GirType): def __init__(self, ns: "Namespace", tl: typelib.Typelib): @@ -432,6 +472,13 @@ class Interface(GirNode, GirType): return True return False + @property + def online_docs(self) -> T.Optional[str]: + if ns := self.get_containing(Namespace).online_docs: + return f"{ns}interface.{self.name}.html" + else: + return None + class Class(GirNode, GirType): def __init__(self, ns: "Namespace", tl: typelib.Typelib) -> None: @@ -544,6 +591,13 @@ class Class(GirNode, GirType): for impl in self.implements: yield from impl.signals.values() + @property + def online_docs(self) -> T.Optional[str]: + if ns := self.get_containing(Namespace).online_docs: + return f"{ns}class.{self.name}.html" + else: + return None + class TemplateType(GirType): def __init__(self, name: str, parent: T.Optional[GirType]): @@ -646,6 +700,13 @@ class Enumeration(GirNode, GirType): def assignable_to(self, type: GirType) -> bool: return type == self + @property + def online_docs(self) -> T.Optional[str]: + if ns := self.get_containing(Namespace).online_docs: + return f"{ns}enum.{self.name}.html" + else: + return None + class Boxed(GirNode, GirType): def __init__(self, ns: "Namespace", tl: typelib.Typelib) -> None: @@ -658,6 +719,13 @@ class Boxed(GirNode, GirType): def assignable_to(self, type) -> bool: return type == self + @property + def online_docs(self) -> T.Optional[str]: + if ns := self.get_containing(Namespace).online_docs: + return f"{ns}boxed.{self.name}.html" + else: + return None + class Bitfield(Enumeration): def __init__(self, ns: "Namespace", tl: typelib.Typelib) -> None: @@ -753,6 +821,10 @@ class Namespace(GirNode): else: return self.get_type(type_name) + @property + def online_docs(self) -> T.Optional[str]: + return ONLINE_DOCS.get(f"{self.name}-{self.version}") + class Repository(GirNode): def __init__(self, tl: typelib.Typelib) -> None: