Skip to content

Commit

Permalink
fixes files cannot be executed from entity tree
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Aug 6, 2024
1 parent 1a4c1f6 commit fc97cae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,18 @@
"group": "q@1",
"when": "editorLangId == python && (resourceFilename =~ /.kdb.py/ || kdb.insightsConnected)"
}
],
"explorer/context": [
{
"command": "kdb.execute.fileQuery",
"group": "q",
"when": "resourceExtname == .q"
},
{
"command": "kdb.execute.pythonFileScratchpadQuery",
"group": "q",
"when": "resourceExtname == .py"
}
]
},
"customEditors": [
Expand Down
11 changes: 9 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import {
renameLabel,
setLabelColor,
} from "./utils/connLabel";
import { activateTextDocument } from "./utils/workspace";

let client: LanguageClient;

Expand Down Expand Up @@ -390,7 +391,10 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand("kdb.execute.selectedQuery", async () => {
await runActiveEditor(ExecutionTypes.QuerySelection);
}),
commands.registerCommand("kdb.execute.fileQuery", async () => {
commands.registerCommand("kdb.execute.fileQuery", async (item) => {
if (item instanceof Uri) {
await activateTextDocument(item);
}
await runActiveEditor(ExecutionTypes.QueryFile);
}),
commands.registerCommand("kdb.execute.pythonScratchpadQuery", async () => {
Expand All @@ -402,7 +406,10 @@ export async function activate(context: ExtensionContext) {
// }),
commands.registerCommand(
"kdb.execute.pythonFileScratchpadQuery",
async () => {
async (item) => {
if (item instanceof Uri) {
await activateTextDocument(item);
}
await runActiveEditor(ExecutionTypes.PythonQueryFile);
},
),
Expand Down
18 changes: 16 additions & 2 deletions src/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* specific language governing permissions and limitations under the License.
*/

import { workspace } from "vscode";
import { Uri, window, workspace } from "vscode";

export function getWorkspaceRoot(
ignoreException: boolean = false
ignoreException: boolean = false,
): string | undefined {
const workspaceRoot =
workspace.workspaceFolders && workspace.workspaceFolders[0].uri.fsPath;
Expand All @@ -32,3 +32,17 @@ export function isWorkspaceOpen(): boolean {
workspace.workspaceFolders && workspace.workspaceFolders[0].uri.fsPath
);
}

export async function activateTextDocument(item: Uri) {
if (item.fsPath) {
let document = workspace.textDocuments.find(
(doc) => doc.uri.fsPath === item.fsPath,
);
if (!document) {
document = await workspace.openTextDocument(item);
}
if (document) {
await window.showTextDocument(document);
}
}
}

0 comments on commit fc97cae

Please sign in to comment.