Add Notebook <-> SQL convert (#11590)

* Add Notebook <-> SQL convert

* Update STS
This commit is contained in:
Charles Gagnon
2020-08-03 14:50:24 -07:00
committed by GitHub
parent fbbb9ce529
commit 694f34a4cd
17 changed files with 248 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ import { SqlToolsServer } from './sqlToolsServer';
import { promises as fs } from 'fs';
import { IconPathHelper } from './iconHelper';
import * as nls from 'vscode-nls';
import { INotebookConvertService } from './notebookConvert/notebookConvertService';
const localize = nls.loadMessageBundle();
const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', "This sample code loads the file into a data frame and shows the first 10 results.");
@@ -79,6 +80,24 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
context.subscriptions.push(server);
await server.start(appContext);
vscode.commands.registerCommand('mssql.exportSqlAsNotebook', async (uri: vscode.Uri) => {
const result = await appContext.getService<INotebookConvertService>(Constants.NotebookConvertService).convertSqlToNotebook(uri.toString());
const title = findNextUntitledEditorName();
const untitledUri = vscode.Uri.parse(`untitled:${title}`);
await azdata.nb.showNotebookDocument(untitledUri, { initialContent: result.content });
});
vscode.commands.registerCommand('mssql.exportNotebookToSql', async (uri: vscode.Uri) => {
// SqlToolsService doesn't currently store anything about Notebook documents so we have to pass the raw JSON to it directly
// We use vscode.workspace.textDocuments here because the azdata.nb.notebookDocuments don't actually contain their contents
// (they're left out for perf purposes)
const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString());
const result = await appContext.getService<INotebookConvertService>(Constants.NotebookConvertService).convertNotebookToSql(doc.getText());
const sqlDoc = await vscode.workspace.openTextDocument({ language: 'sql', content: result.content });
await vscode.commands.executeCommand('vscode.open', sqlDoc.uri);
});
return createMssqlApi(appContext);
}