From 027e7253d8ffe1611397217349b601b0bc66d5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 2 Aug 2023 19:36:07 +0200 Subject: [PATCH] switch to full parse and rebuild --- sphinxcontrib/phpdomain.py | 95 ++++++++++++++++++++++++-------------- test/log.txt | 19 ++++---- test/rst_doc.html | 3 -- 3 files changed, 69 insertions(+), 48 deletions(-) diff --git a/sphinxcontrib/phpdomain.py b/sphinxcontrib/phpdomain.py index e683a9df..18d9a4fd 100644 --- a/sphinxcontrib/phpdomain.py +++ b/sphinxcontrib/phpdomain.py @@ -207,48 +207,75 @@ def handle_signature(self, sig, signode): log_warning(signode, "Invalid signature: " + sig) raise ValueError - visibility, modifiers, name_prefix, name, arglist, retann, enumtype = m.groups() + visibility, modifiers, classname, name, arglist, retann, enumtype = m.groups() - if not name_prefix: - name_prefix = "" - - # determine namespace and class name (if applicable), as well as full name - namespace = self.options.get( + # parse & resolve classname and name + env_namespace = self.options.get( "namespace", self.env.temp_data.get("php:namespace") ) + env_class = self.env.temp_data.get("php:class") separator = separators[self.objtype] - - if "::" in name_prefix: - classname = name_prefix.rstrip("::") + if ( + self.objtype == "const" + and not classname + and (not env_class or name.startswith(NS)) + ): + separator = None + type_in_class = separator != None + + if not classname: + # log_assert(signode, not name.startswith('$')) + if name.startswith("$"): + name = name[1:] + if type_in_class: + log_assert(signode, env_class) + classname = NS + env_class + else: + classname = name + name = None else: - classname = self.env.temp_data.get("php:class") + log_assert(signode, type_in_class) + log_assert(signode, classname.endswith("::")) + classname = classname[:-2] + # log_assert(signode, name.startswith('$') == (separator and separator.endswith('$'))) # not strictly needed + if name.startswith("$"): + name = name[1:] if self.objtype == "global": - namespace = None + name = "$" + classname classname = None + elif classname.startswith(NS): + classname = classname[1:] + elif env_namespace: + classname = env_namespace + NS + classname + + if not type_in_class and self.objtype != "global": + name = classname.split(NS)[-1] + classname = "" + elif classname and env_namespace and classname.startswith(env_namespace + NS): + classname = classname[len(env_namespace + NS) :] + + if not classname: fullname = name + elif not name: + fullname = classname else: - if name_prefix: - fullname = name_prefix + name - - # Currently in a class, but not creating another class, - elif classname and not self.objtype in [ - "class", - "exception", - "interface", - "trait", - "enum", - "function", - ]: - if not self.env.temp_data["php:in_class"]: - name_prefix = classname + separator - - fullname = classname + separator + name + fullname = classname + separator + name + + name_prefix = classname + if not name_prefix: + name_prefix = None + # elif type_in_class and not self.env.temp_data['php:in_class']: + elif type_in_class: + if not self.env.temp_data.get("php:in_class", False): + name_prefix = name_prefix + separator else: - classname = "" - fullname = name + name_prefix = None + + print([env_namespace, classname, name, fullname, name_prefix]) + print() - signode["namespace"] = namespace + signode["namespace"] = env_namespace signode["class"] = self.class_name = classname signode["fullname"] = fullname @@ -264,16 +291,16 @@ def handle_signature(self, sig, signode): signode += addnodes.desc_annotation(sig_prefix, sig_prefix) if name_prefix: - if namespace and not self.env.temp_data["php:in_class"]: - name_prefix = namespace + NS + name_prefix + if env_namespace and not self.env.temp_data["php:in_class"]: + name_prefix = env_namespace + NS + name_prefix signode += addnodes.desc_addname(name_prefix, name_prefix) elif ( - namespace + env_namespace and not self.env.temp_data.get("php:in_class", False) and self.env.config.add_module_names ): - nodetext = namespace + NS + nodetext = env_namespace + NS signode += addnodes.desc_addname(nodetext, nodetext) signode += addnodes.desc_name(name, name) diff --git a/test/log.txt b/test/log.txt index f218c034..2e9daac0 100644 --- a/test/log.txt +++ b/test/log.txt @@ -1,11 +1,8 @@ -test/log.md:3: WARNING: Unknown directive type: 'php:namespacee' [myst.directive_unknown] -test/log.md:8: WARNING: [phpdomain] Invalid signature: x(); -test/log.md:13: [phpdomain] Target Aa::simplify not found -test/log.md:15: [phpdomain] Target A::simplifyy not found -test/ns.md:48: [phpdomain] Target A2::simplify not found -test/ns.md:53: [phpdomain] Target Bar2\A::simplify not found -test/rst_doc.md:506: [phpdomain] Target OtherLibrary\int|string|ReturnedClass|\LibraryName\SubPackage\SubpackageInterface|null not found -test/rst_doc2.md:11: [phpdomain] Target Imagine\Image\ImageInterface::draw not found -test/rst_doc2.md:17: [phpdomain] Target Imagine\Image\PointInterface not found -test/rst_doc2.md:17: [phpdomain] Target Imagine\Image\BoxInterface not found -test/rst_doc2.md:17: [phpdomain] Target Imagine\Image\Color not found +test/ns.md:59: [phpdomain.info] Target A::simplify not found +test/ns.md:69: [phpdomain.info] Target A2::simplify not found +test/ns.md:74: [phpdomain.info] Target Bar2\A::simplify not found +test/rst_doc.md:506: [phpdomain.info] Target OtherLibrary\int|string|ReturnedClass|\LibraryName\SubPackage\SubpackageInterface|null not found +test/rst_doc2.md:11: [phpdomain.info] Target Imagine\Image\ImageInterface::draw not found +test/rst_doc2.md:17: [phpdomain.info] Target Imagine\Image\PointInterface not found +test/rst_doc2.md:17: [phpdomain.info] Target Imagine\Image\BoxInterface not found +test/rst_doc2.md:17: [phpdomain.info] Target Imagine\Image\Color not found diff --git a/test/rst_doc.html b/test/rst_doc.html index 24e4e5c5..6d418515 100644 --- a/test/rst_doc.html +++ b/test/rst_doc.html @@ -687,9 +687,6 @@

Namespaced elementsA class in a namespace

- - LibraryClass:: - instanceMethod