Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KXI-46005: Workbook and datasource files should be put into a dedicated folder #309

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -228,7 +230,8 @@
"icon": {
"dark": "./resources/dark/add-scratchpad.svg",
"light": "./resources/light/add-scratchpad.svg"
}
},
"enablement": "workspaceFolderCount > 0"
},
{
"category": "KX",
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export async function activate(context: ExtensionContext) {
uri,
DataSourceEditorProvider.viewType,
);
await commands.executeCommand("workbench.action.files.save", uri);
}
},
),
Expand All @@ -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);
}
},
),
Expand All @@ -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);
}
},
),
Expand Down
15 changes: 13 additions & 2 deletions src/services/workspaceTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export async function addWorkspaceFile(
item: FileTreeItem,
name: string,
ext: string,
directory = ".kx",
) {
const folders = workspace.workspaceFolders;
if (folders) {
Expand All @@ -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;
}
Expand All @@ -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");
}
}
Loading