mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
Fix handling of connections in editors (#9682)
* fix handling of connections in editors * initial tests * remove test
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResultsInput';
|
||||
import { EditDataInput } from 'sql/workbench/browser/editData/editDataInput';
|
||||
import { IConnectableInput } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { IQueryEditorService, INewSqlEditorOptions } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput';
|
||||
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
@@ -18,6 +18,11 @@ import { EditDataResultsInput } from 'sql/workbench/browser/editData/editDataRes
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { UntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
|
||||
const defaults: INewSqlEditorOptions = {
|
||||
open: true
|
||||
};
|
||||
|
||||
/**
|
||||
* Service wrapper for opening and creating SQL documents as sql editor inputs
|
||||
@@ -39,36 +44,30 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
/**
|
||||
* Creates new untitled document for SQL query and opens in new editor tab
|
||||
*/
|
||||
public newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean, objectName?: string): Promise<IConnectableInput> {
|
||||
return new Promise<IConnectableInput>(async (resolve, reject) => {
|
||||
try {
|
||||
// Create file path and file URI
|
||||
let filePath = await this.createUntitledSqlFilePath();
|
||||
let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath });
|
||||
public async newSqlEditor(options: INewSqlEditorOptions = {}): Promise<IConnectableInput> {
|
||||
options = mixin(options, defaults, false);
|
||||
// Create file path and file URI
|
||||
let filePath = await this.createUntitledSqlFilePath();
|
||||
let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath });
|
||||
|
||||
// Create a sql document pane with accoutrements
|
||||
const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: 'sql' }) as UntitledTextEditorInput;
|
||||
let untitledEditorModel = await fileInput.resolve() as UntitledTextEditorModel;
|
||||
if (sqlContent) {
|
||||
untitledEditorModel.textEditorModel.setValue(sqlContent);
|
||||
if (isDirty === false || (isDirty === undefined && !this._configurationService.getValue<boolean>('sql.promptToSaveGeneratedFiles'))) {
|
||||
untitledEditorModel.setDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, docUri.toString());
|
||||
let queryInput = this._instantiationService.createInstance(UntitledQueryEditorInput, objectName, fileInput, queryResultsInput);
|
||||
|
||||
this._editorService.openEditor(queryInput, { pinned: true })
|
||||
.then((editor) => {
|
||||
resolve(editor.input as UntitledQueryEditorInput);
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
// Create a sql document pane with accoutrements
|
||||
const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: 'sql' }) as UntitledTextEditorInput;
|
||||
let untitledEditorModel = await fileInput.resolve() as UntitledTextEditorModel;
|
||||
if (options.initalContent) {
|
||||
untitledEditorModel.textEditorModel.setValue(options.initalContent);
|
||||
if (options.dirty === false || (options.dirty === undefined && !this._configurationService.getValue<boolean>('sql.promptToSaveGeneratedFiles'))) {
|
||||
untitledEditorModel.setDirty(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, docUri.toString());
|
||||
let queryInput = this._instantiationService.createInstance(UntitledQueryEditorInput, options.description, fileInput, queryResultsInput);
|
||||
|
||||
if (options.open) {
|
||||
await this._editorService.openEditor(queryInput, { pinned: true });
|
||||
}
|
||||
|
||||
return queryInput;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user