Skip to content

feat: implement SQL Notebook (.sqlnb) support for SQLTools #1462

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/extension/icons/info-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/extension/icons/info-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/extension/icons/limit-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/extension/icons/limit-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
"configuration": "./language/language-configuration.json"
}
],
"notebooks": [
{
"type": "sqltools-notebook",
"displayName": "SQLTools Notebook",
"selector": [
{
"filenamePattern": "*.sqlnb"
}
]
}
],
"grammars": [
{
"language": "sql",
Expand All @@ -121,6 +132,47 @@
}
],
"commands": [
{
"title": "List Available SQLTools Commands",
"command": "sqltools.notebook.listCommands",
"category": "SQLTools Notebook Debug"
},
{
"title": "Select Connection for Cell",
"command": "sqltools.notebook.selectCellConnection",
"category": "SQLTools Notebook",
"icon": {
"light": "icons/connect-light.svg",
"dark": "icons/connect-dark.svg"
}
},
{
"title": "Clear Connection for Cell",
"command": "sqltools.notebook.clearCellConnection",
"category": "SQLTools Notebook",
"icon": {
"light": "icons/disconnect-light.svg",
"dark": "icons/disconnect-dark.svg"
}
},
{
"title": "Show SQL Notebook Connection Help",
"command": "sqltools.notebook.showConnectionHelp",
"category": "SQLTools Notebook",
"icon": {
"light": "icons/help-light.svg",
"dark": "icons/help-dark.svg"
}
},
{
"title": "Limit Query Results",
"command": "sqltools.notebook.limitResults",
"category": "SQLTools Notebook",
"icon": {
"light": "icons/limit-light.svg",
"dark": "icons/limit-dark.svg"
}
},
{
"title": "Connect",
"command": "sqltools.selectConnection",
Expand Down Expand Up @@ -411,6 +463,54 @@
"key": "ctrl+e ctrl+q",
"mac": "cmd+e q",
"when": "!config.sqltools.disableChordKeybindings && editorTextFocus && editorHasSelection"
},
{
"command": "sqltools.executeQuery",
"key": "ctrl+alt+e",
"mac": "cmd+alt+e",
"when": "editorTextFocus && editorLangId == 'sql'"
},
{
"command": "sqltools.executeCurrentQuery",
"key": "ctrl+alt+q",
"mac": "cmd+alt+q",
"when": "editorTextFocus && editorLangId == 'sql'"
},
{
"command": "sqltools.executeQueryFromFile",
"key": "ctrl+alt+f",
"mac": "cmd+alt+f",
"when": "editorTextFocus && editorLangId == 'sql'"
},
{
"command": "sqltools.formatSql",
"key": "shift+alt+f",
"mac": "shift+alt+f",
"when": "editorHasSelection && editorLangId == 'sql'"
},
{
"command": "sqltools.formatSql",
"key": "shift+alt+f",
"mac": "shift+alt+f",
"when": "editorHasSelection"
},
{
"command": "sqltools.notebook.selectCellConnection",
"key": "ctrl+k ctrl+c",
"mac": "cmd+k cmd+c",
"when": "notebookEditorFocused && notebookType == 'sqltools-notebook'"
},
{
"command": "sqltools.notebook.clearCellConnection",
"key": "ctrl+k ctrl+r",
"mac": "cmd+k cmd+r",
"when": "notebookEditorFocused && notebookType == 'sqltools-notebook'"
},
{
"command": "sqltools.notebook.showConnectionHelp",
"key": "ctrl+k ctrl+h",
"mac": "cmd+k cmd+h",
"when": "notebookType == 'sqltools-notebook'"
}
],
"configuration": {
Expand Down Expand Up @@ -1069,6 +1169,22 @@
{
"command": "sqltools.bookmarkSelection",
"when": "editorHasSelection"
},
{
"command": "sqltools.notebook.selectConnection",
"when": "notebookType == 'sqltools-notebook'"
}
],
"notebook/title": [
{
"command": "sqltools.notebook.selectCellConnection",
"when": "notebookType == 'sqltools-notebook'",
"group": "navigation"
},
{
"command": "sqltools.notebook.showConnectionHelp",
"when": "notebookType == 'sqltools-notebook'",
"group": "navigation"
}
],
"view/title": [
Expand Down
61 changes: 42 additions & 19 deletions packages/extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PluginResourcesMap from '@sqltools/util/plugin-resources';
import SQLToolsLanguageClient from './language-client';
import Timer from '@sqltools/util/timer';
import Utils from './api/utils';
import { registerSQLNotebook, deactivateSQLNotebook } from './notebook';

const log = createLogger();

Expand Down Expand Up @@ -78,6 +79,9 @@ export class SQLToolsExtension implements IExtension {
}

public deactivate = (): void => {
// Clean up notebook resources
deactivateSQLNotebook();

return Context.subscriptions.forEach((sub) => void sub.dispose());
}

Expand Down Expand Up @@ -295,30 +299,49 @@ export class SQLToolsExtension implements IExtension {
}
}

let instance: SQLToolsExtension;
export function activate(ctx: ExtensionContext) {
Context.set(ctx);
migrateFilesToNewPaths();

// Register SQL notebook functionality
registerSQLNotebook(ctx);

try {
Context.set(ctx);
if (instance) return;
migrateFilesToNewPaths();
instance = new SQLToolsExtension();
instance.registerPlugin([
FormatterPlugin,
const ext = new SQLToolsExtension();

// Register plugins - use the correct approach for each plugin
ext.registerPlugin([
// These are already plugin objects, don't need 'new'
ConnectionManagerPlugin,
new HistoryManagerPlugin,
new BookmarksManagerPlugin,
new AuthenticationProviderPlugin,
new ObjectDropProviderPlugin,
])
return instance.activate();

} catch (err) {
log.fatal('failed to activate: %O', err);
FormatterPlugin,
// These need instantiation as they're exported as classes
new ObjectDropProviderPlugin(),
new HistoryManagerPlugin(),
new BookmarksManagerPlugin(),
new AuthenticationProviderPlugin(),
]);

return ext.activate();
} catch (e) {
// Create an error handler with a string message
const handler = ErrorHandler.create('Failed to activate extension');
// Then pass the actual error to the handler
handler(e);
}
}

export function deactivate() {
if (!instance) return;
instance.deactivate();
instance = undefined;
// Clean up notebook resources
deactivateSQLNotebook();

// Just call dispose on each subscription
if (Context.subscriptions) {
Context.subscriptions.forEach(sub => {
try {
sub.dispose();
} catch (e) {
// Ignore dispose errors
}
});
}
}
Loading
Loading