def _get_test_suite_from_document( self, xml_document: XmlDocument) -> Optional[TestSuiteInfoResult]: tool = GalaxyToolXmlDocument.from_xml_document(xml_document) tool_id = tool.get_tool_id() tests_range = tool.get_tests_range() if tool_id and tests_range: tests = tool.get_tests() test_cases: List[TestInfoResult] = [] id = 1 for test in tests: range = xml_document.get_full_range(test) if range: test_cases.append( TestInfoResult( tool_id=tool_id, test_id=str(id), uri=xml_document.document.uri, range=range, ), ) id += 1 return TestSuiteInfoResult( tool_id=tool_id, uri=xml_document.document.uri, range=tests_range, children=test_cases, ) return None
def get_macro_names(self, tool_xml: XmlDocument) -> Set[str]: tool = GalaxyToolXmlDocument.from_xml_document(tool_xml) macros = self._get_macro_definitions(tool_xml) imported_macro_files = self._get_imported_macro_files_from_tool(tool) for file in imported_macro_files.values(): macros.update(file.macros) return set(macros.keys())
def validate_document(self, xml_document: XmlDocument) -> List[Diagnostic]: """Validates the XML document and returns a list of diagnostics if there are any problems. Args: xml_document (XmlDocument): The XML document. Can be a tool wrapper or macro definition file. Returns: List[Diagnostic]: The list of issues found in the document. """ syntax_errors = self._check_syntax(xml_document.document) if syntax_errors: return syntax_errors if not xml_document.is_tool_file: return [] tool = GalaxyToolXmlDocument.from_xml_document(xml_document) try: xml_tree = etree.fromstring(tool.source) return self._validate_tree(xml_tree) except ExpandMacrosFoundException: result = self._validate_expanded(tool) return result except etree.XMLSyntaxError as e: return self._build_diagnostics_from_syntax_error(e)
def load_macro_definitions(self, tool_xml: XmlDocument) -> ToolMacroDefinitions: tool = GalaxyToolXmlDocument.from_xml_document(tool_xml) tokens = self._get_token_definitions(tool_xml) macros = self._get_macro_definitions(tool_xml) imported_macro_files = self._get_imported_macro_files_from_tool(tool) for file in imported_macro_files.values(): tokens.update(file.tokens) macros.update(file.macros) return ToolMacroDefinitions( tool_document=tool_xml, imported_macros=imported_macro_files, tokens=tokens, macros=macros, )
def get_available_refactoring_actions( self, xml_document: XmlDocument, params: CodeActionParams) -> List[CodeAction]: """Gets a collection of possible refactoring code actions on a selected chunk of the document.""" code_actions = [] text_in_range = xml_document.get_text_in_range(params.range) target_element_tag = self._get_valid_full_element_tag(text_in_range) if target_element_tag is not None: macro = MacroData(name=target_element_tag, content=text_in_range.strip()) macro_definitions = self.macros.definitions_provider.load_macro_definitions( xml_document) tool = GalaxyToolXmlDocument.from_xml_document(xml_document) code_actions.extend( self.macros.create_extract_to_macros_file_actions( tool, macro_definitions, macro, params)) code_actions.extend( self.macros.create_extract_to_local_macro_actions( tool, macro, params)) return code_actions