Skip to content

Commit

Permalink
Add command to insert param references for output filters
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Sep 30, 2024
1 parent 42cc011 commit d7c5ce1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
16 changes: 14 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,22 @@
"category": "Galaxy Tools",
"enablement": "galaxytools:isActive",
"icon": "$(open-preview)"
}
,
},
{
"command": "galaxytools.insert.paramReference",
"title": "Insert a reference to a param element.",
"category": "Galaxy Tools",
"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": [
Expand Down Expand Up @@ -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": {
Expand Down
13 changes: 8 additions & 5 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions server/galaxyls/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion server/galaxyls/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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] = []
Expand Down

0 comments on commit d7c5ce1

Please sign in to comment.