diff --git a/src/commandEntryView.ts b/src/commandEntryView.ts index 2429be1..beb63bb 100644 --- a/src/commandEntryView.ts +++ b/src/commandEntryView.ts @@ -1,10 +1,10 @@ -import * as vscode from 'vscode'; import IBMi from '@halcyontech/vscode-ibmi-types/api/IBMi'; +import * as vscode from 'vscode'; import { CLPrompter } from './clPrompter'; +import { CommandEntryJobManager } from './commandEntryJobManager'; import { CommandEntryHistory, CommandExecutionMode } from './commandEntryModel'; -import { CommandEntryService } from './commandEntryService'; import { detectCommandEntryPrefix } from './commandEntryPrefixes'; -import { CommandEntryJobManager } from './commandEntryJobManager'; +import { CommandEntryService } from './commandEntryService'; import { updateConnectionSqlSettings } from './commandEntrySqlSettings'; import { configureSqlResultPanelAssets, notifySqlResultSessionClosed, setSqlResultPanelRequestHandler, showSqlResultPanel } from './sqlResultPanel'; @@ -949,6 +949,35 @@ export class CommandEntryViewProvider implements vscode.WebviewViewProvider { }); return; } + + const selectCommand = /^([^\s]*)\*/.exec(command); + if (selectCommand !== null) { + this.post({ type: 'notice', message: vscode.l10n.t("Selecting command...") }); + const [name, library] = connection.upperCaseName(selectCommand[1]).split('/').reverse(); + + if (name.length > 10) { + this.post({ type: 'notice', message: vscode.l10n.t("{0} is not a valid command name", name) }); + } + + const libraries = library ? [library] : [connection.getConfig().currentLibrary ?? '', ...connection.getConfig().libraryList, '*LIBL'].filter(Boolean); + const query = [...libraries].map(lib => `select OBJLIB, OBJNAME, OBJTEXT from table(QSYS2.OBJECT_STATISTICS('${lib}', 'CMD', '${name}*'))`).join(' union all ') + ' order by OBJLIB, OBJNAME'; + const suggestions = (await connection.runSQL(query)).map(row => ({ library: String(row.OBJLIB), name: String(row.OBJNAME), text: row.OBJTEXT !== null ? String(row.OBJTEXT) : undefined })); + + if (suggestions.length > 0) { + const selection = (await vscode.window.showQuickPick(suggestions.map(s => ({ label: `${s.library}/${s.name}`, description: s.text })), { title: vscode.l10n.t("Select command") }))?.label; + if (selection !== undefined) { + this.post({ type: 'setCommand', command: selection }); + this.post({ type: 'focusInput' }); + } + this.post({ type: 'notice', message: undefined }); + } + else { + this.post({ type: 'notice', message: vscode.l10n.t("No selection match for {0} in {1}", name, library ? library : vscode.l10n.t("the library list")) }); + } + + return; + } + this.running = true; this.activeExecutionId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`; const sqlJobId = this.currentSqlJobId(connection); @@ -967,6 +996,7 @@ export class CommandEntryViewProvider implements vscode.WebviewViewProvider { sqlJobId, statusMessage }); + try { const execution = await this.service.execute(connection, command, mode, this.activeExecutionId); const executionForPost = isSql