diff --git a/package.json b/package.json index 6acf73f2..709eaa33 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-db2i", "displayName": "Db2 for IBM i", "description": "Db2 for IBM i tools in VS Code", - "version": "1.14.0", + "version": "1.14.0-dev1", "engines": { "vscode": "^1.95.0" }, @@ -365,6 +365,11 @@ ] }, "commands": [ + { + "command": "vscode-db2i.language.getStatements", + "title": "Get statements", + "category": "Db2 for i" + }, { "command": "vscode-db2i.json.pasteGenerator", "title": "Paste JSON as SQL", @@ -794,6 +799,10 @@ ], "menus": { "commandPalette": [ + { + "command": "vscode-db2i.language.getStatements", + "when": "never" + }, { "command": "vscode-db2i.getStatementUri", "when": "editorLangId == sql" diff --git a/src/contributes.json b/src/contributes.json index 7368a32f..605e7f90 100644 --- a/src/contributes.json +++ b/src/contributes.json @@ -96,6 +96,11 @@ ] }, "commands": [ + { + "command": "vscode-db2i.language.getStatements", + "title": "Get statements", + "category": "Db2 for i" + }, { "command": "vscode-db2i.json.pasteGenerator", "title": "Paste JSON as SQL", @@ -114,6 +119,10 @@ ], "menus": { "commandPalette": [ + { + "command": "vscode-db2i.language.getStatements", + "when": "never" + }, { "command": "vscode-db2i.getStatementUri", "when": "editorLangId == sql" diff --git a/src/language/index.ts b/src/language/index.ts index fac8010e..77e1cbc0 100644 --- a/src/language/index.ts +++ b/src/language/index.ts @@ -1,7 +1,10 @@ +import { commands, Uri, window, workspace } from "vscode"; import { completionProvider } from "./providers/completionProvider"; import { formatProvider } from "./providers/formatProvider"; import { signatureProvider } from "./providers/parameterProvider"; import { problemProvider } from "./providers/problemProvider"; +import { getSqlDocument } from "./providers/logic/parse"; +import { StatementType } from "./sql/types"; export function languageInit() { let functionality = []; @@ -12,6 +15,29 @@ export function languageInit() { signatureProvider, problemProvider ); - + + functionality.push(...registerLanguageCommands()); + return functionality; } + +function registerLanguageCommands() { + return [ + // Programmable API that is not callable through the UI. + // Solely for the use for other extensions. + commands.registerCommand(`vscode-db2i.language.getStatements`, async (uri?: Uri) => { + const document = await workspace.openTextDocument(uri); + + if (document) { + const doc = getSqlDocument(document); + if (doc) { + const groups = doc.getStatementGroups(); + return groups.map(g => ({ + range: g.range, + type: g.statements[0] ? g.statements[0].type : StatementType.Unknown + })); + } + } + }) + ] +} \ No newline at end of file