Skip to content

Commit

Permalink
Include attributes in symbols provider
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Oct 12, 2023
1 parent 73286c7 commit 2cb9ef9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions server/galaxyls/services/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -25,23 +29,35 @@ 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

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,
selection_range=element_range,
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"]:
Expand Down

0 comments on commit 2cb9ef9

Please sign in to comment.