From 8a15341eb6122068017fa3fd1fee67d9322fc61f Mon Sep 17 00:00:00 2001 From: ecmel Date: Tue, 21 May 2024 08:15:33 +0300 Subject: [PATCH] fixes KXI-46005 --- package.json | 15 ++++++++++----- src/extension.ts | 3 +++ src/services/workspaceTreeProvider.ts | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e831f057..54fc0c54 100644 --- a/package.json +++ b/package.json @@ -213,13 +213,15 @@ "category": "KX", "command": "kdb.createDataSource", "title": "New Datasource...", - "icon": "$(add)" + "icon": "$(add)", + "enablement": "workspaceFolderCount > 0" }, { "category": "KX", "command": "kdb.refreshDataSourceExplorer", "title": "Refresh datasources", - "icon": "$(refresh)" + "icon": "$(refresh)", + "enablement": "workspaceFolderCount > 0" }, { "category": "KX", @@ -228,7 +230,8 @@ "icon": { "dark": "./resources/dark/add-scratchpad.svg", "light": "./resources/light/add-scratchpad.svg" - } + }, + "enablement": "workspaceFolderCount > 0" }, { "category": "KX", @@ -237,13 +240,15 @@ "icon": { "dark": "./resources/dark/add-scratchpad-python.svg", "light": "./resources/light/add-scratchpad-python.svg" - } + }, + "enablement": "workspaceFolderCount > 0" }, { "category": "KX", "command": "kdb.refreshScratchpadExplorer", "title": "Refresh workbooks", - "icon": "$(refresh)" + "icon": "$(refresh)", + "enablement": "workspaceFolderCount > 0" }, { "category": "KX", diff --git a/src/extension.ts b/src/extension.ts index 41668b5a..31d2a70a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -324,6 +324,7 @@ export async function activate(context: ExtensionContext) { uri, DataSourceEditorProvider.viewType, ); + await commands.executeCommand("workbench.action.files.save", uri); } }, ), @@ -336,6 +337,7 @@ export async function activate(context: ExtensionContext) { const uri = await addWorkspaceFile(item, "workbook", ".kdb.q"); if (uri) { await window.showTextDocument(uri); + await commands.executeCommand("workbench.action.files.save", uri); } }, ), @@ -345,6 +347,7 @@ export async function activate(context: ExtensionContext) { const uri = await addWorkspaceFile(item, "workbook", ".kdb.py"); if (uri) { await window.showTextDocument(uri); + await commands.executeCommand("workbench.action.files.save", uri); } }, ), diff --git a/src/services/workspaceTreeProvider.ts b/src/services/workspaceTreeProvider.ts index 60ec64dc..46e18f32 100644 --- a/src/services/workspaceTreeProvider.ts +++ b/src/services/workspaceTreeProvider.ts @@ -133,6 +133,7 @@ export async function addWorkspaceFile( item: FileTreeItem, name: string, ext: string, + directory = ".kx", ) { const folders = workspace.workspaceFolders; if (folders) { @@ -143,7 +144,9 @@ export async function addWorkspaceFile( if (folder) { let i = 1; while (true) { - const files = await workspace.findFiles(`${name}-${i}${ext}`); + const files = await workspace.findFiles( + `${directory}/${name}-${i}${ext}`, + ); if (files.length === 0) { break; } @@ -152,11 +155,19 @@ export async function addWorkspaceFile( throw new Error("No available file name found"); } } - const uri = Uri.joinPath(folder.uri, `${name}-${i}${ext}`).with({ + + const uri = Uri.joinPath( + folder.uri, + directory, + `${name}-${i}${ext}`, + ).with({ scheme: "untitled", }); + await workspace.openTextDocument(uri); return uri; } + } else { + throw new Error("No workspace has been opened"); } }