From d7c5ce1b65fd40dabb0420d49a94c2aa5452ac43 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:48:07 +0200 Subject: [PATCH] Add command to insert param references for output filters --- client/package.json | 16 ++++++++++++++-- client/src/commands.ts | 13 ++++++++----- server/galaxyls/constants.py | 1 + server/galaxyls/server.py | 15 ++++++++++++++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/client/package.json b/client/package.json index a188fce..fd5ea1e 100644 --- a/client/package.json +++ b/client/package.json @@ -132,8 +132,7 @@ "category": "Galaxy Tools", "enablement": "galaxytools:isActive", "icon": "$(open-preview)" - } - , + }, { "command": "galaxytools.insert.paramReference", "title": "Insert a reference to a param element.", @@ -141,6 +140,14 @@ "enablement": "galaxytools:isActive", "icon": "$(insert)", "when": "editorTextFocus" + }, + { + "command": "galaxytools.insert.paramFilterReference", + "title": "Insert a reference to a param element to be used as output filter.", + "category": "Galaxy Tools", + "enablement": "galaxytools:isActive", + "icon": "$(insert)", + "when": "editorTextFocus" } ], "keybindings": [ @@ -168,6 +175,11 @@ "command": "galaxytools.insert.paramReference", "key": "ctrl+alt+i ctrl+alt+p", "mac": "cmd+alt+i cmd+alt+p" + }, + { + "command": "galaxytools.insert.paramFilterReference", + "key": "ctrl+alt+i ctrl+alt+f", + "mac": "cmd+alt+i cmd+alt+f" } ], "configuration": { diff --git a/client/src/commands.ts b/client/src/commands.ts index 689e74e..5a30135 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -34,6 +34,7 @@ export namespace Commands { export const GENERATE_EXPANDED_DOCUMENT: ICommand = getCommands("generate.expandedDocument"); export const PREVIEW_EXPANDED_DOCUMENT: ICommand = getCommands("preview.expandedDocument"); export const INSERT_PARAM_REFERENCE: ICommand = getCommands("insert.paramReference"); + export const INSERT_PARAM_FILTER_REFERENCE: ICommand = getCommands("insert.paramFilterReference"); } interface GeneratedSnippetResult { @@ -129,10 +130,12 @@ function setupGenerateTestCases(client: LanguageClient, context: ExtensionContex } function setupInsertParamReference(client: LanguageClient, context: ExtensionContext) { - const insertParamReferenceHandler = async () => { + context.subscriptions.push(commands.registerCommand(Commands.INSERT_PARAM_REFERENCE.internal, () => { pickParamReferenceToInsert(client, Commands.INSERT_PARAM_REFERENCE.external); - }; - context.subscriptions.push(commands.registerCommand(Commands.INSERT_PARAM_REFERENCE.internal, insertParamReferenceHandler)); + })); + context.subscriptions.push(commands.registerCommand(Commands.INSERT_PARAM_FILTER_REFERENCE.internal, () => { + pickParamReferenceToInsert(client, Commands.INSERT_PARAM_FILTER_REFERENCE.external); + })) } function setupAutoCloseTags(client: LanguageClient, context: ExtensionContext) { @@ -226,7 +229,7 @@ async function requestInsertSnippet(client: LanguageClient, command: string) { } } -async function pickParamReferenceToInsert(client: LanguageClient, command: string) { +async function pickParamReferenceToInsert(client: LanguageClient, command: string, pickerTitle: string = "Select a parameter reference to insert") { const activeEditor = window.activeTextEditor; if (!activeEditor) return; @@ -239,7 +242,7 @@ async function pickParamReferenceToInsert(client: LanguageClient, command: strin } try { - const selected = await window.showQuickPick(response.references, { title: "Select a parameter reference to insert" }); + const selected = await window.showQuickPick(response.references, { title: pickerTitle }); if (!selected) return; activeEditor.edit(editBuilder => { diff --git a/server/galaxyls/constants.py b/server/galaxyls/constants.py index 96f1341..4ec03b4 100644 --- a/server/galaxyls/constants.py +++ b/server/galaxyls/constants.py @@ -16,6 +16,7 @@ class Commands: DISCOVER_TESTS_IN_DOCUMENT = "gls.tests.discoverInDocument" GENERATE_EXPANDED_DOCUMENT = "gls.generate.expandedDocument" INSERT_PARAM_REFERENCE = "gls.insert.paramReference" + INSERT_PARAM_FILTER_REFERENCE = "gls.insert.paramFilterReference" class DiagnosticCodes: diff --git a/server/galaxyls/server.py b/server/galaxyls/server.py index 10f2fb8..9c65543 100644 --- a/server/galaxyls/server.py +++ b/server/galaxyls/server.py @@ -303,7 +303,7 @@ def discover_tests_in_document_command( async def cmd_insert_param_reference( server: GalaxyToolsLanguageServer, parameters: CommandParameters ) -> Optional[ParamReferencesResult]: - """Provides a list of possible parameter references to be inserted in the document.""" + """Provides a list of possible parameter references to be inserted in the command section of the document.""" params = convert_to(parameters[0], TextDocumentIdentifier) document = _get_valid_document(server, params.uri) if document: @@ -312,6 +312,19 @@ async def cmd_insert_param_reference( return None +@language_server.command(Commands.INSERT_PARAM_FILTER_REFERENCE) +async def cmd_insert_param_filter_reference( + server: GalaxyToolsLanguageServer, parameters: CommandParameters +) -> Optional[ParamReferencesResult]: + """Provides a list of possible parameter references to be inserted as output filters.""" + params = convert_to(parameters[0], TextDocumentIdentifier) + document = _get_valid_document(server, params.uri) + if document: + xml_document = _get_xml_document(document) + return server.service.param_references_provider.get_param_filter_references(xml_document) + return None + + def _validate(server: GalaxyToolsLanguageServer, params) -> None: """Validates the Galaxy tool and reports any problem found.""" diagnostics: List[Diagnostic] = []