From 2cb9ef9310cc273b8ec7a1a7334ead1acc5d5104 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:35:04 +0200 Subject: [PATCH] Include attributes in symbols provider --- server/galaxyls/services/symbols.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/server/galaxyls/services/symbols.py b/server/galaxyls/services/symbols.py index facefc6..914fd85 100644 --- a/server/galaxyls/services/symbols.py +++ b/server/galaxyls/services/symbols.py @@ -9,7 +9,11 @@ ) from galaxyls.services.xml.document import XmlDocument -from galaxyls.services.xml.nodes import XmlElement +from galaxyls.services.xml.nodes import ( + XmlAttribute, + XmlElement, + XmlSyntaxNode, +) from galaxyls.services.xml.utils import convert_document_offsets_to_range @@ -25,6 +29,8 @@ def get_document_symbols(self, xml_document: XmlDocument) -> List[DocumentSymbol def _get_element_children_symbols(self, element: XmlElement, xml_document: XmlDocument) -> List[DocumentSymbol]: result: List[DocumentSymbol] = [] for child in element.children: + if isinstance(child, XmlAttribute): + result.append(self._get_attribute_symbol_definition(xml_document, child)) if isinstance(child, XmlElement): result.append(self._get_element_symbol_definition(xml_document, child)) return result @@ -32,7 +38,7 @@ def _get_element_children_symbols(self, element: XmlElement, xml_document: XmlDo def _get_element_symbol_definition(self, xml_document: XmlDocument, element: XmlElement) -> DocumentSymbol: element_range = convert_document_offsets_to_range(xml_document.document, element.start, element.end) return DocumentSymbol( - name=self._get_element_symbol_name(element), + name=self._get_node_name(element), kind=SymbolKind.Field, detail=self._get_element_symbol_detail(element, xml_document), range=element_range, @@ -40,8 +46,18 @@ def _get_element_symbol_definition(self, xml_document: XmlDocument, element: Xml children=self._get_element_children_symbols(element, xml_document), ) - def _get_element_symbol_name(self, element: XmlElement) -> str: - return element.name or "" + def _get_attribute_symbol_definition(self, xml_document: XmlDocument, attribute: XmlAttribute) -> DocumentSymbol: + attribute_range = convert_document_offsets_to_range(xml_document.document, attribute.start, attribute.end) + return DocumentSymbol( + name=self._get_node_name(attribute), + kind=SymbolKind.Property, + detail=attribute.value.unquoted if attribute.value else None, + range=attribute_range, + selection_range=attribute_range, + ) + + def _get_node_name(self, node: XmlSyntaxNode) -> str: + return node.name or "" def _get_element_symbol_detail(self, element: XmlElement, xml_document: XmlDocument) -> Optional[str]: if element.name in ["option", "when", "add", "remove"]: