Skip to content
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
731 changes: 731 additions & 0 deletions dist/extension.js

Large diffs are not rendered by default.

36 changes: 29 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "postgres-explorer",
"displayName": "PostgreSQL Explorer",
"version": "0.0.4",
"version": "0.0.5",
"description": "PostgreSQL database explorer for VS Code with notebook support",
"publisher": "ric-v",
"private": false,
Expand Down Expand Up @@ -80,6 +80,11 @@
"command": "postgresExplorer.openColumnNotebook",
"title": "Open Column Analysis",
"category": "Postgres Explorer"
},
{
"command": "postgres-explorer.showViewProperties",
"title": "Show View Properties",
"icon": "$(info)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -108,7 +113,9 @@
{
"filenamePattern": "*.pgsql"
}
]
],
"priority": "default",
"enableScripts": true
},
{
"type": "postgres-query",
Expand All @@ -117,7 +124,9 @@
{
"filenamePattern": "*.pgquery"
}
]
],
"priority": "default",
"enableScripts": true
}
],
"notebookRenderer": [
Expand Down Expand Up @@ -201,6 +210,11 @@
"command": "postgres-explorer.deleteConnection",
"when": "view == postgresExplorer && viewItem == connection",
"group": "inline@0"
},
{
"command": "postgres-explorer.showViewProperties",
"when": "view == postgresExplorer && viewItem == view",
"group": "inline@2"
}
]
}
Expand All @@ -219,11 +233,14 @@
"onNotebook:postgres-notebook",
"onNotebook:postgres-query"
],
"main": "./out/extension.js",
"main": "./dist/extension.js",
"scripts": {
"vscode:prepublish": "npm run compile",
"vscode:prepublish": "yarn run esbuild-base --minify",
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./"
"watch": "tsc -watch -p ./",
"esbuild": "yarn esbuild-base --sourcemap",
"esbuild-watch": "yarn esbuild-base --sourcemap --watch"
},
"dependencies": {
"pg": "^8.11.3",
Expand All @@ -234,6 +251,11 @@
"@types/node": "^16.18.126",
"@types/pg": "^8.11.11",
"@types/vscode": "^1.80.0",
"typescript": "^4.5.5"
"typescript": "^4.5.5",
"esbuild": "^0.19.12"
},
"resolutions": {
"webpack": "^5.76.0",
"webpack-cli": "^5.0.0"
}
}
98 changes: 94 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,81 @@ import { PostgresKernel } from './notebookKernel';
import { PostgresNotebookSerializer } from './postgresNotebook';

export function activate(context: vscode.ExtensionContext) {
// Create kernel with message handler
console.log('postgres-explorer: Activating extension');

// Create kernel with message handler to handle notebook cell output messages
const kernel = new PostgresKernel((message) => {
vscode.window.showInformationMessage(message);
console.log('Extension: Received message from kernel:', message);
if (message.type === 'custom' && message.command === 'export') {
console.log('Extension: Handling export command');
vscode.commands.executeCommand('postgres-explorer.exportData', {
format: message.format,
content: message.content,
filename: message.filename
});
}
});
context.subscriptions.push(kernel);

// Register global command to handle exports
context.subscriptions.push(
vscode.commands.registerCommand('postgres-explorer.exportData', async (args) => {
console.log('Extension: Export command triggered with args:', args);
try {
const { format, content, filename } = args;
const saveUri = await vscode.window.showSaveDialog({
defaultUri: vscode.Uri.file(filename),
filters: {
'CSV files': ['csv'],
'Excel files': ['xls', 'xlsx']
}
},
saveLabel: `Export as ${format.toUpperCase()}`
});

console.log('Extension: Save dialog result:', saveUri?.fsPath);
if (saveUri) {
console.log('Extension: Writing file content, size:', content.length);
await vscode.workspace.fs.writeFile(
saveUri,
Buffer.from(content)
Buffer.from(content, 'utf-8')
);
console.log('Extension: File written successfully');
vscode.window.showInformationMessage(
`Successfully exported to ${saveUri.fsPath}`
);
}
} catch (err: any) {
console.error('Extension: Export failed:', err);
vscode.window.showErrorMessage(`Export failed: ${err.message}`);
}
})
);

// Register save file command
context.subscriptions.push(
vscode.commands.registerCommand('postgres-explorer.saveFile', async (args) => {
try {
console.log('Saving file with args:', args);
const { content, filename, type } = args;

const saveUri = await vscode.window.showSaveDialog({
defaultUri: vscode.Uri.file(filename),
filters: {
'CSV files': ['csv'],
'Excel files': ['xls', 'xlsx']
},
saveLabel: `Export as ${type.toUpperCase()}`
});

if (saveUri) {
await vscode.workspace.fs.writeFile(
saveUri,
Buffer.from(content)
);
vscode.window.showInformationMessage(`Successfully exported to ${saveUri.fsPath}`);
}
} catch (err: any) {
console.error('Save file failed:', err);
vscode.window.showErrorMessage(`Export failed: ${err.message}`);
}
})
Expand Down Expand Up @@ -124,6 +170,50 @@ export function activate(context: vscode.ExtensionContext) {
})
);

context.subscriptions.push(
vscode.commands.registerCommand('postgres-explorer.showViewProperties', async (item: DatabaseTreeItem) => {
if (!item || !item.schema || !item.connectionId) {
vscode.window.showErrorMessage('Invalid view selection');
return;
}

const connections = vscode.workspace.getConfiguration().get<any[]>('postgresExplorer.connections') || [];
const connection = connections.find(c => c.id === item.connectionId);
if (!connection) {
vscode.window.showErrorMessage('Connection not found');
return;
}

let client: Client | undefined;
try {
client = new Client({
host: connection.host,
port: connection.port,
user: connection.username,
password: String(connection.password),
database: item.databaseName || connection.database,
connectionTimeoutMillis: 5000
});

await client.connect();

// Pass the connected client to TablePropertiesPanel with isView flag
await TablePropertiesPanel.show(client, item.schema!, item.label, true);
} catch (err: any) {
const errorMessage = err?.message || 'Unknown error occurred';
vscode.window.showErrorMessage(`Failed to show view properties: ${errorMessage}`);

if (client) {
try {
await client.end();
} catch (closeErr) {
console.error('Error closing connection:', closeErr);
}
}
}
})
);

context.subscriptions.push(
vscode.commands.registerCommand('postgres-explorer.connect', async () => {
try {
Expand Down
Loading