Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature Insert param reference/output filter #264

Merged
merged 9 commits into from
Sep 30, 2024
Prev Previous commit
Next Next commit
Refactor move get_expanded_tool_document to GalaxyToolXmlDocument
davelopez committed Sep 30, 2024
commit f3413ee89b35a8faedf02e02ab6763a0c19f036e
18 changes: 18 additions & 0 deletions server/galaxyls/services/tools/document.py
Original file line number Diff line number Diff line change
@@ -7,10 +7,12 @@
)

from anytree import find # type: ignore
from galaxy.util import xml_macros
from lsprotocol.types import (
Position,
Range,
)
from lxml import etree
from pygls.workspace import Document

from galaxyls.services.tools.constants import (
@@ -228,6 +230,22 @@ def get_import_macro_file_range(self, file_path: Optional[str]) -> Optional[Rang
return self.xml_document.get_full_range(imp)
return None

def get_expanded_tool_document(self) -> "GalaxyToolXmlDocument":
"""If the given tool document uses macros, a new tool document with the expanded macros is returned,
otherwise, the same document is returned.
"""
if self.uses_macros:
try:
document = self.document
expanded_tool_tree, _ = xml_macros.load_with_references(document.path)
expanded_tool_tree = cast(etree._ElementTree, expanded_tool_tree) # type: ignore
expanded_source = etree.tostring(expanded_tool_tree, encoding=str)
expanded_document = Document(uri=document.uri, source=expanded_source, version=document.version)
return GalaxyToolXmlDocument(expanded_document)
except BaseException:
return self
return self

def get_tool_id(self) -> Optional[str]:
"""Gets the identifier of the tool"""
tool_element = self.get_tool_element()
21 changes: 1 addition & 20 deletions server/galaxyls/services/tools/generators/snippets.py
Original file line number Diff line number Diff line change
@@ -10,13 +10,10 @@
cast,
)

from galaxy.util import xml_macros
from lsprotocol.types import (
Position,
Range,
)
from lxml import etree
from pygls.workspace import Document

from galaxyls.services.tools.constants import (
DASH,
@@ -32,7 +29,7 @@ class SnippetGenerator(ABC):

def __init__(self, tool_document: GalaxyToolXmlDocument, tabSize: int = 4) -> None:
self.tool_document = tool_document
self.expanded_document = self._get_expanded_tool_document(tool_document)
self.expanded_document = tool_document.get_expanded_tool_document()
self.tabstop_count: int = 0
self.indent_spaces: str = " " * tabSize
super().__init__()
@@ -63,22 +60,6 @@ def _find_snippet_insert_position(self) -> Union[Position, Range]:
snippet will be inserted."""
pass

def _get_expanded_tool_document(self, tool_document: GalaxyToolXmlDocument) -> GalaxyToolXmlDocument:
"""If the given tool document uses macros, a new tool document with the expanded macros is returned,
otherwise, the same document is returned.
"""
if tool_document.uses_macros:
try:
document = tool_document.document
expanded_tool_tree, _ = xml_macros.load_with_references(document.path)
expanded_tool_tree = cast(etree._ElementTree, expanded_tool_tree) # type: ignore
expanded_source = etree.tostring(expanded_tool_tree, encoding=str)
expanded_document = Document(uri=document.uri, source=expanded_source, version=document.version)
return GalaxyToolXmlDocument(expanded_document)
except BaseException:
return tool_document
return tool_document

def _get_next_tabstop(self) -> str:
"""Increments the tabstop count and returns the current tabstop
in TextMate format.