Skip to content

Commit 9a2497b

Browse files
committed
impl sqlnb for sqltools
1 parent 6e016b1 commit 9a2497b

File tree

10 files changed

+1576
-25
lines changed

10 files changed

+1576
-25
lines changed
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

packages/extension/package.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@
113113
"configuration": "./language/language-configuration.json"
114114
}
115115
],
116+
"notebooks": [
117+
{
118+
"type": "sqltools-notebook",
119+
"displayName": "SQLTools Notebook",
120+
"selector": [
121+
{
122+
"filenamePattern": "*.sqlnb"
123+
}
124+
]
125+
}
126+
],
116127
"grammars": [
117128
{
118129
"language": "sql",
@@ -121,6 +132,47 @@
121132
}
122133
],
123134
"commands": [
135+
{
136+
"title": "List Available SQLTools Commands",
137+
"command": "sqltools.notebook.listCommands",
138+
"category": "SQLTools Notebook Debug"
139+
},
140+
{
141+
"title": "Select Connection for Cell",
142+
"command": "sqltools.notebook.selectCellConnection",
143+
"category": "SQLTools Notebook",
144+
"icon": {
145+
"light": "icons/connect-light.svg",
146+
"dark": "icons/connect-dark.svg"
147+
}
148+
},
149+
{
150+
"title": "Clear Connection for Cell",
151+
"command": "sqltools.notebook.clearCellConnection",
152+
"category": "SQLTools Notebook",
153+
"icon": {
154+
"light": "icons/disconnect-light.svg",
155+
"dark": "icons/disconnect-dark.svg"
156+
}
157+
},
158+
{
159+
"title": "Show SQL Notebook Connection Help",
160+
"command": "sqltools.notebook.showConnectionHelp",
161+
"category": "SQLTools Notebook",
162+
"icon": {
163+
"light": "icons/help-light.svg",
164+
"dark": "icons/help-dark.svg"
165+
}
166+
},
167+
{
168+
"title": "Limit Query Results",
169+
"command": "sqltools.notebook.limitResults",
170+
"category": "SQLTools Notebook",
171+
"icon": {
172+
"light": "icons/limit-light.svg",
173+
"dark": "icons/limit-dark.svg"
174+
}
175+
},
124176
{
125177
"title": "Connect",
126178
"command": "sqltools.selectConnection",
@@ -411,6 +463,54 @@
411463
"key": "ctrl+e ctrl+q",
412464
"mac": "cmd+e q",
413465
"when": "!config.sqltools.disableChordKeybindings && editorTextFocus && editorHasSelection"
466+
},
467+
{
468+
"command": "sqltools.executeQuery",
469+
"key": "ctrl+alt+e",
470+
"mac": "cmd+alt+e",
471+
"when": "editorTextFocus && editorLangId == 'sql'"
472+
},
473+
{
474+
"command": "sqltools.executeCurrentQuery",
475+
"key": "ctrl+alt+q",
476+
"mac": "cmd+alt+q",
477+
"when": "editorTextFocus && editorLangId == 'sql'"
478+
},
479+
{
480+
"command": "sqltools.executeQueryFromFile",
481+
"key": "ctrl+alt+f",
482+
"mac": "cmd+alt+f",
483+
"when": "editorTextFocus && editorLangId == 'sql'"
484+
},
485+
{
486+
"command": "sqltools.formatSql",
487+
"key": "shift+alt+f",
488+
"mac": "shift+alt+f",
489+
"when": "editorHasSelection && editorLangId == 'sql'"
490+
},
491+
{
492+
"command": "sqltools.formatSql",
493+
"key": "shift+alt+f",
494+
"mac": "shift+alt+f",
495+
"when": "editorHasSelection"
496+
},
497+
{
498+
"command": "sqltools.notebook.selectCellConnection",
499+
"key": "ctrl+k ctrl+c",
500+
"mac": "cmd+k cmd+c",
501+
"when": "notebookEditorFocused && notebookType == 'sqltools-notebook'"
502+
},
503+
{
504+
"command": "sqltools.notebook.clearCellConnection",
505+
"key": "ctrl+k ctrl+r",
506+
"mac": "cmd+k cmd+r",
507+
"when": "notebookEditorFocused && notebookType == 'sqltools-notebook'"
508+
},
509+
{
510+
"command": "sqltools.notebook.showConnectionHelp",
511+
"key": "ctrl+k ctrl+h",
512+
"mac": "cmd+k cmd+h",
513+
"when": "notebookType == 'sqltools-notebook'"
414514
}
415515
],
416516
"configuration": {
@@ -1069,6 +1169,22 @@
10691169
{
10701170
"command": "sqltools.bookmarkSelection",
10711171
"when": "editorHasSelection"
1172+
},
1173+
{
1174+
"command": "sqltools.notebook.selectConnection",
1175+
"when": "notebookType == 'sqltools-notebook'"
1176+
}
1177+
],
1178+
"notebook/title": [
1179+
{
1180+
"command": "sqltools.notebook.selectCellConnection",
1181+
"when": "notebookType == 'sqltools-notebook'",
1182+
"group": "navigation"
1183+
},
1184+
{
1185+
"command": "sqltools.notebook.showConnectionHelp",
1186+
"when": "notebookType == 'sqltools-notebook'",
1187+
"group": "navigation"
10721188
}
10731189
],
10741190
"view/title": [

packages/extension/src/index.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import PluginResourcesMap from '@sqltools/util/plugin-resources';
1313
import SQLToolsLanguageClient from './language-client';
1414
import Timer from '@sqltools/util/timer';
1515
import Utils from './api/utils';
16+
import { registerSQLNotebook, deactivateSQLNotebook } from './notebook';
1617

1718
const log = createLogger();
1819

@@ -78,6 +79,9 @@ export class SQLToolsExtension implements IExtension {
7879
}
7980

8081
public deactivate = (): void => {
82+
// Clean up notebook resources
83+
deactivateSQLNotebook();
84+
8185
return Context.subscriptions.forEach((sub) => void sub.dispose());
8286
}
8387

@@ -295,30 +299,49 @@ export class SQLToolsExtension implements IExtension {
295299
}
296300
}
297301

298-
let instance: SQLToolsExtension;
299302
export function activate(ctx: ExtensionContext) {
303+
Context.set(ctx);
304+
migrateFilesToNewPaths();
305+
306+
// Register SQL notebook functionality
307+
registerSQLNotebook(ctx);
308+
300309
try {
301-
Context.set(ctx);
302-
if (instance) return;
303-
migrateFilesToNewPaths();
304-
instance = new SQLToolsExtension();
305-
instance.registerPlugin([
306-
FormatterPlugin,
310+
const ext = new SQLToolsExtension();
311+
312+
// Register plugins - use the correct approach for each plugin
313+
ext.registerPlugin([
314+
// These are already plugin objects, don't need 'new'
307315
ConnectionManagerPlugin,
308-
new HistoryManagerPlugin,
309-
new BookmarksManagerPlugin,
310-
new AuthenticationProviderPlugin,
311-
new ObjectDropProviderPlugin,
312-
])
313-
return instance.activate();
314-
315-
} catch (err) {
316-
log.fatal('failed to activate: %O', err);
316+
FormatterPlugin,
317+
// These need instantiation as they're exported as classes
318+
new ObjectDropProviderPlugin(),
319+
new HistoryManagerPlugin(),
320+
new BookmarksManagerPlugin(),
321+
new AuthenticationProviderPlugin(),
322+
]);
323+
324+
return ext.activate();
325+
} catch (e) {
326+
// Create an error handler with a string message
327+
const handler = ErrorHandler.create('Failed to activate extension');
328+
// Then pass the actual error to the handler
329+
handler(e);
317330
}
318331
}
319332

320333
export function deactivate() {
321-
if (!instance) return;
322-
instance.deactivate();
323-
instance = undefined;
334+
// Clean up notebook resources
335+
deactivateSQLNotebook();
336+
337+
// Just call dispose on each subscription
338+
if (Context.subscriptions) {
339+
Context.subscriptions.forEach(sub => {
340+
try {
341+
sub.dispose();
342+
} catch (e) {
343+
// Ignore dispose errors
344+
}
345+
});
346+
}
324347
}

0 commit comments

Comments
 (0)