Add openQueryDocument API (#16117)

* Add openQueryDocument API

* Remove open call

* Change try name
This commit is contained in:
Charles Gagnon
2021-07-13 17:56:35 -07:00
committed by GitHub
parent a7311764be
commit a0f46fec65
7 changed files with 40 additions and 11 deletions

View File

@@ -80,11 +80,7 @@ export class PredictService {
predictParams.outputColumns || [], predictParams.outputColumns || [],
predictParams); predictParams);
} }
let document = await this._apiWrapper.openTextDocument({ const document = await azdata.queryeditor.openQueryDocument({ content: query });
language: 'sql',
content: query
});
await this._apiWrapper.executeCommand('vscode.open', document.uri);
await this._apiWrapper.connect(document.uri.toString(), connection.connectionId); await this._apiWrapper.connect(document.uri.toString(), connection.connectionId);
this._apiWrapper.runQuery(document.uri.toString(), undefined, false); this._apiWrapper.runQuery(document.uri.toString(), undefined, false);
return query; return query;

View File

@@ -98,9 +98,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
// (they're left out for perf purposes) // (they're left out for perf purposes)
const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString()); const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString());
const result = await appContext.getService<INotebookConvertService>(Constants.NotebookConvertService).convertNotebookToSql(doc.getText()); const result = await appContext.getService<INotebookConvertService>(Constants.NotebookConvertService).convertNotebookToSql(doc.getText());
await azdata.queryeditor.openQueryDocument({ content: result.content });
const sqlDoc = await vscode.workspace.openTextDocument({ language: 'sql', content: result.content });
await vscode.commands.executeCommand('vscode.open', sqlDoc.uri);
} catch (err) { } catch (err) {
vscode.window.showErrorMessage(localize('mssql.errorConvertingToSQL', "An error occurred converting the Notebook document to SQL. Error : {0}", err.toString())); vscode.window.showErrorMessage(localize('mssql.errorConvertingToSQL', "An error occurred converting the Notebook document to SQL. Error : {0}", err.toString()));
} }

View File

@@ -9,6 +9,19 @@ import * as vscode from 'vscode';
declare module 'azdata' { declare module 'azdata' {
export namespace queryeditor {
/**
* Opens an untitled text document. The editor will prompt the user for a file
* path when the document is to be saved. The `options` parameter allows to
* specify the *content* of the document.
*
* @param options Options to control how the document will be created.
* @param providerId Optional provider ID this editor will be associated with. Defaults to MSSQL.
* @return A promise that resolves to a [document](#QueryDocument).
*/
export function openQueryDocument(options?: { content?: string; }, providerId?: string): Thenable<QueryDocument>;
}
export namespace nb { export namespace nb {
export interface NotebookDocument { export interface NotebookDocument {
/** /**

View File

@@ -16,6 +16,8 @@ import { IQueryManagementService } from 'sql/workbench/services/query/common/que
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile'; import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ILogService } from 'vs/platform/log/common/log'; import { ILogService } from 'vs/platform/log/common/log';
import { URI } from 'vs/base/common/uri';
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor) @extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape { export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape {
@@ -29,7 +31,8 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
@IQueryModelService private _queryModelService: IQueryModelService, @IQueryModelService private _queryModelService: IQueryModelService,
@IEditorService private _editorService: IEditorService, @IEditorService private _editorService: IEditorService,
@IQueryManagementService private _queryManagementService: IQueryManagementService, @IQueryManagementService private _queryManagementService: IQueryManagementService,
@ILogService private _logService: ILogService @ILogService private _logService: ILogService,
@IQueryEditorService private _queryEditorService: IQueryEditorService
) { ) {
super(); super();
if (extHostContext) { if (extHostContext) {
@@ -145,4 +148,9 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
public $setQueryExecutionOptions(fileUri: string, options: azdata.QueryExecutionOptions): Thenable<void> { public $setQueryExecutionOptions(fileUri: string, options: azdata.QueryExecutionOptions): Thenable<void> {
return this._queryManagementService.setQueryExecutionOptions(fileUri, options); return this._queryManagementService.setQueryExecutionOptions(fileUri, options);
} }
public async $createQueryDocument(options?: { content?: string }, providerId?: string): Promise<URI> {
const queryInput = await this._queryEditorService.newSqlEditor({ initalContent: options.content }, providerId);
return queryInput.resource;
}
} }

View File

@@ -9,6 +9,7 @@ import * as azdata from 'azdata';
import { IQueryEvent } from 'sql/workbench/services/query/common/queryModel'; import { IQueryEvent } from 'sql/workbench/services/query/common/queryModel';
import { mssqlProviderName } from 'sql/platform/connection/common/constants'; import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { Disposable } from 'vs/workbench/api/common/extHostTypes'; import { Disposable } from 'vs/workbench/api/common/extHostTypes';
import { URI } from 'vs/base/common/uri';
class ExtHostQueryDocument implements azdata.queryeditor.QueryDocument { class ExtHostQueryDocument implements azdata.queryeditor.QueryDocument {
constructor( constructor(
@@ -77,4 +78,7 @@ export class ExtHostQueryEditor implements ExtHostQueryEditorShape {
}); });
} }
public createQueryDocument(options?: { content?: string }, providerId?: string): Promise<URI> {
return this._proxy.$createQueryDocument(options, providerId).then(data => URI.revive(data));
}
} }

View File

@@ -35,6 +35,7 @@ import { IExtensionApiFactory as vsIApiFactory, createApiFactoryAndRegisterActor
import { IExtHostCommands } from 'vs/workbench/api/common/extHostCommands'; import { IExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { ExtHostWorkspace } from 'sql/workbench/api/common/extHostWorkspace'; import { ExtHostWorkspace } from 'sql/workbench/api/common/extHostWorkspace';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService'; import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
import { URI } from 'vs/base/common/uri';
export interface IAzdataExtensionApiFactory { export interface IAzdataExtensionApiFactory {
(extension: IExtensionDescription): typeof azdata; (extension: IExtensionDescription): typeof azdata;
@@ -96,7 +97,6 @@ export function createAdsApiFactory(accessor: ServicesAccessor): IAdsExtensionAp
const extHostNotebookDocumentsAndEditors = rpcProtocol.set(SqlExtHostContext.ExtHostNotebookDocumentsAndEditors, new ExtHostNotebookDocumentsAndEditors(rpcProtocol)); const extHostNotebookDocumentsAndEditors = rpcProtocol.set(SqlExtHostContext.ExtHostNotebookDocumentsAndEditors, new ExtHostNotebookDocumentsAndEditors(rpcProtocol));
const extHostExtensionManagement = rpcProtocol.set(SqlExtHostContext.ExtHostExtensionManagement, new ExtHostExtensionManagement(rpcProtocol)); const extHostExtensionManagement = rpcProtocol.set(SqlExtHostContext.ExtHostExtensionManagement, new ExtHostExtensionManagement(rpcProtocol));
const extHostWorkspace = rpcProtocol.set(SqlExtHostContext.ExtHostWorkspace, new ExtHostWorkspace(rpcProtocol)); const extHostWorkspace = rpcProtocol.set(SqlExtHostContext.ExtHostWorkspace, new ExtHostWorkspace(rpcProtocol));
return { return {
azdata: function (extension: IExtensionDescription): typeof azdata { azdata: function (extension: IExtensionDescription): typeof azdata {
// namespace: connection // namespace: connection
@@ -506,6 +506,15 @@ export function createAdsApiFactory(accessor: ServicesAccessor): IAdsExtensionAp
getQueryDocument(fileUri: string): Thenable<azdata.queryeditor.QueryDocument> { getQueryDocument(fileUri: string): Thenable<azdata.queryeditor.QueryDocument> {
return extHostQueryEditor.$getQueryDocument(fileUri); return extHostQueryEditor.$getQueryDocument(fileUri);
},
openQueryDocument(options?: { content?: string; }, providerId?: string): Thenable<azdata.queryeditor.QueryDocument> {
let uriPromise: Thenable<URI>;
uriPromise = extHostQueryEditor.createQueryDocument(options, providerId);
return uriPromise.then(uri => {
return extHostQueryEditor.$getQueryDocument(uri.toString());
});
} }
}; };

View File

@@ -7,7 +7,7 @@ import {
createMainContextProxyIdentifier as createMainId, createMainContextProxyIdentifier as createMainId,
createExtHostContextProxyIdentifier as createExtId createExtHostContextProxyIdentifier as createExtId
} from 'vs/workbench/services/extensions/common/proxyIdentifier'; } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import { UriComponents } from 'vs/base/common/uri'; import { URI, UriComponents } from 'vs/base/common/uri';
import { IDisposable } from 'vs/base/common/lifecycle'; import { IDisposable } from 'vs/base/common/lifecycle';
@@ -847,6 +847,7 @@ export interface MainThreadQueryEditorShape extends IDisposable {
$setQueryExecutionOptions(fileUri: string, options: azdata.QueryExecutionOptions): Thenable<void>; $setQueryExecutionOptions(fileUri: string, options: azdata.QueryExecutionOptions): Thenable<void>;
$registerQueryInfoListener(handle: number): void; $registerQueryInfoListener(handle: number): void;
$unregisterQueryInfoListener(handle: number): void; $unregisterQueryInfoListener(handle: number): void;
$createQueryDocument(options?: { content?: string }, providerId?: string): Promise<URI>;
} }
export interface ExtHostNotebookShape { export interface ExtHostNotebookShape {