@@ -6,12 +6,14 @@ import { Bucket, BucketSettings } from "couchbase";
66import { QueryWorkbench } from "../../workbench/queryWorkbench" ;
77import {
88 showQueryContextStatusbar ,
9+ showQueryContextStatusbarNotebook ,
910 showSearchContextStatusbar ,
1011} from "../../util/queryContextUtils" ;
1112import { getActiveConnection } from "../../util/connections" ;
1213import { SearchWorkbench } from "../../commands/fts/SearchWorkbench/searchWorkbench" ;
1314import SearchIndexNode from "../../model/SearchIndexNode" ;
1415import { Commands } from "../../commands/extensionCommands/commands" ;
16+ import { QueryKernel } from "../../notebook/controller" ;
1517
1618const fetchBucketNames = (
1719 bucketsSettings : BucketSettings [ ] | undefined ,
@@ -33,6 +35,7 @@ const fetchBucketNames = (
3335
3436export async function fetchQueryContext (
3537 workbench : QueryWorkbench ,
38+ queryKernel : QueryKernel ,
3639 context : vscode . ExtensionContext ,
3740 globalStatusBarItem : any ,
3841) {
@@ -47,9 +50,11 @@ export async function fetchQueryContext(
4750 try {
4851 // Fetch active editor
4952 const activeEditor = vscode . window . activeTextEditor ;
50- if ( ! ( activeEditor && activeEditor . document . languageId === "SQL++" ) ) {
53+ const activeNotebookEditor = vscode . window . activeNotebookEditor ;
54+ const isNotebook = ! ! activeNotebookEditor ;
55+ if ( ! activeNotebookEditor && ! ( activeEditor && activeEditor . document . languageId === "SQL++" ) ) {
5156 vscode . window . showErrorMessage (
52- "Please ensure that the workbench is open/ active" ,
57+ "Please ensure that a SQL++ editor or a notebook is open and active"
5358 ) ;
5459 return ;
5560 }
@@ -96,14 +101,13 @@ export async function fetchQueryContext(
96101
97102 const bucketNameSelected = selectedItem . label ;
98103 if ( bucketNameSelected === "Clear Context" ) {
99- workbench . editorToContext . delete (
100- activeEditor . document . uri . toString ( ) ,
101- ) ;
102- showQueryContextStatusbar (
103- activeEditor ,
104- workbench ,
105- globalStatusBarItem ,
106- ) ;
104+ if ( isNotebook && activeNotebookEditor ) {
105+ queryKernel . notebookToContext . delete ( activeNotebookEditor . notebook . uri . toString ( ) ) ;
106+ showQueryContextStatusbarNotebook ( activeNotebookEditor , queryKernel , globalStatusBarItem ) ;
107+ } else if ( activeEditor ) {
108+ workbench . editorToContext . delete ( activeEditor . document . uri . toString ( ) ) ;
109+ showQueryContextStatusbar ( activeEditor , workbench , globalStatusBarItem ) ;
110+ }
107111 return ;
108112 }
109113 const scopes = await connection . cluster
@@ -128,11 +132,18 @@ export async function fetchQueryContext(
128132 vscode . window . showInformationMessage ( "No scope selected." ) ;
129133 return ;
130134 }
131- workbench . editorToContext . set ( activeEditor . document . uri . toString ( ) , {
135+ const queryContext = {
132136 bucketName : bucketNameSelected ,
133137 scopeName : scopeNameSelected . label ,
134- } ) ;
135- showQueryContextStatusbar ( activeEditor , workbench , globalStatusBarItem ) ;
138+ } ;
139+ if ( isNotebook && activeEditor ) {
140+ const notebookUri = activeNotebookEditor . notebook . uri . toString ( ) ;
141+ queryKernel . notebookToContext . set ( notebookUri , queryContext ) ;
142+ showQueryContextStatusbarNotebook ( activeNotebookEditor , queryKernel , globalStatusBarItem ) ;
143+ } else if ( activeEditor ) {
144+ workbench . editorToContext . set ( activeEditor . document . uri . toString ( ) , queryContext ) ;
145+ showQueryContextStatusbar ( activeEditor , workbench , globalStatusBarItem ) ;
146+ }
136147 } catch ( err ) {
137148 logger . error ( `failed to open and set query context: ${ err } ` ) ;
138149 logger . debug ( err ) ;
0 commit comments