From 635ee454d9a7eb39b35af0fb77c2a6613c0feb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Ujhelyi?= Date: Tue, 18 Feb 2025 19:24:20 +0100 Subject: [PATCH 1/6] ST6RI-823 Allow external magic command defininitions in Jupyter This commit adds a service registration based mechanism that can be used to register additional magic commands to the system. Furthermore, to allow these commands to add new items to the built-in help system, and appropriate extension method was added to SysMLInteractiveHelp --- .../interactive/SysMLInteractiveHelp.java | 92 +++++++++++++------ org.omg.sysml.jupyter.kernel/.classpath | 7 -- org.omg.sysml.jupyter.kernel/pom.xml | 19 ---- .../kernel/IMagicCommandRegistrator.java | 31 +++++++ .../omg/sysml/jupyter/kernel/SysMLKernel.java | 3 + .../src/main/resources/sysml/kernel.json | 5 +- 6 files changed, 101 insertions(+), 56 deletions(-) create mode 100644 org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/IMagicCommandRegistrator.java diff --git a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java index 0808a2917..93355a44a 100644 --- a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java +++ b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java @@ -30,36 +30,33 @@ import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; import org.omg.sysml.plantuml.SysML2PlantUMLStyle; +import com.google.common.base.Preconditions; + public class SysMLInteractiveHelp { - private static final String GENERAL_HELP_STRING = + + private static final String GENERAL_HELP_STRING_PREFIX = "The following SysML v2 magic commands are available.\n" + "For help on a specific command, use \"%help \" or \"% -h\".\n\n" - + "%eval\t\tEvaluate a given expression.\n" - + "%export\t\tSave a file of the JSON representation of the abstract syntax tree rooted in the named element.\n" - + "%help\t\tGet a list of available commands or help on a specific command\n" - + "%list\t\tList loaded library packages or the results of a given query\n" - + "%load\tLoads a model from the repository and adds it to the Xtext index\n" - + "%show\t\tPrint the abstract syntax tree rooted in a named element\n" - + "%projects\tList projects in the repository\n" - + "%publish\tPublish to the repository the modele elements rooted in a named element\n" - + "%view\t\tRender the view specified by the named view usage\n" - + "%viz\t\tVisualize the name model elements\n" ; + private static final String HELP_HELP_SHORT_STRING = "%help\t\tGet a list of available commands or help on a specific command"; private static final String HELP_HELP_STRING = "Usage: %help []\n\n" + "Print help information on the named SysML v2 magic .\n" + "If no is given, then list the available commands.\n"; + private static final String EVAL_HELP_SHORT_STRING = "%eval\t\tEvaluate a given expression."; private static final String EVAL_HELP_STRING = "Usage: %eval [--target=] \n\n" + "Print the results of evaluating on the target given by , which must be fully qualified.\n" + "If a target is not given, then evaluate in global scope.\n"; + private static final String LIST_HELP_SHORT_STRING = "%list\t\tList loaded library packages or the results of a given query"; private static final String LIST_HELP_STRING = "Usage: %list []\n\n" + "If is not given, then list all loaded library packages.\n" @@ -71,6 +68,8 @@ public class SysMLInteractiveHelp { + " ::**\t\tall members of the namespace and, recursively, members of owned namespaces.\n" + "The last two forms may be optionally followed by a filter expression in square brackets.\n"; + private static final String SHOW_HELP_SHORT_STRING = + "%show\t\tPrint the abstract syntax tree rooted in a named element"; private static final String SHOW_HELP_STRING = "Usage: %show [--style=