mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
Fix handling of connections in editors (#9682)
* fix handling of connections in editors * initial tests * remove test
This commit is contained in:
@@ -45,7 +45,7 @@ export async function scriptSelect(connectionProfile: IConnectionProfile, metada
|
||||
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newSqlEditor(result.script);
|
||||
const owner = await queryEditorService.newSqlEditor({ initalContent: result.script });
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
|
||||
@@ -127,7 +127,7 @@ export async function script(connectionProfile: IConnectionProfile, metadata: az
|
||||
|
||||
if (script) {
|
||||
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
|
||||
const owner = await queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description);
|
||||
const owner = await queryEditorService.newSqlEditor({ initalContent: script, description });
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
|
||||
@@ -79,10 +79,10 @@ export function getCurrentGlobalConnection(objectExplorerService: IObjectExplore
|
||||
if (activeInput) {
|
||||
// dashboard Connection
|
||||
if (activeInput instanceof DashboardInput && activeInput.uri) {
|
||||
connection = connectionManagementService.getConnectionProfile(activeInput.uri.toString());
|
||||
connection = connectionManagementService.getConnectionProfile(activeInput.uri);
|
||||
} else if (activeInput.resource) {
|
||||
// editor Connection
|
||||
connection = connectionManagementService.getConnectionProfile(activeInput.resource.toString());
|
||||
connection = connectionManagementService.getConnectionProfile(activeInput.resource.toString(true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ export function openNewQuery(accessor: ServicesAccessor, profile?: IConnectionPr
|
||||
if (!profile) {
|
||||
profile = getCurrentGlobalConnection(objectExplorerService, connectionManagementService, editorService);
|
||||
}
|
||||
return queryEditorService.newSqlEditor(initalContent).then((owner: IConnectableInput) => {
|
||||
return queryEditorService.newSqlEditor({ initalContent }).then((owner: IConnectableInput) => {
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: onConnection, input: owner },
|
||||
|
||||
@@ -42,7 +42,7 @@ export class QueryEditorLanguageAssociation implements ILanguageAssociation {
|
||||
queryEditorInput = this.instantiationService.createInstance(FileQueryEditorInput, '', activeEditor, queryResultsInput);
|
||||
} else if (activeEditor instanceof UntitledTextEditorInput) {
|
||||
const content = (await activeEditor.resolve()).textEditorModel.getValue();
|
||||
queryEditorInput = (this.queryEditorService.newSqlEditor(content) as any) as UntitledQueryEditorInput;
|
||||
queryEditorInput = await this.queryEditorService.newSqlEditor({ open: false, initalContent: content }) as UntitledQueryEditorInput;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export class ScriptAction extends Action {
|
||||
public async run(element: TaskNode): Promise<boolean> {
|
||||
if (element instanceof TaskNode) {
|
||||
if (element.script && element.script !== '') {
|
||||
this._queryEditorService.newSqlEditor(element.script);
|
||||
this._queryEditorService.newSqlEditor({ initalContent: element.script });
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,12 +16,25 @@ export interface IQueryEditorOptions extends IEditorOptions {
|
||||
|
||||
export const IQueryEditorService = createDecorator<IQueryEditorService>('QueryEditorService');
|
||||
|
||||
export interface INewSqlEditorOptions {
|
||||
initalContent?: string;
|
||||
/**
|
||||
* Defaults based on user configuration
|
||||
*/
|
||||
dirty?: boolean;
|
||||
description?: string;
|
||||
/**
|
||||
* defaults to true
|
||||
*/
|
||||
open?: boolean;
|
||||
}
|
||||
|
||||
export interface IQueryEditorService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
// Creates new untitled document for SQL queries and opens it in a new editor tab
|
||||
newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean, objectName?: string): Promise<IConnectableInput>;
|
||||
newSqlEditor(options?: INewSqlEditorOptions): Promise<IConnectableInput>;
|
||||
|
||||
// Creates new edit data session
|
||||
newEditDataEditor(schemaName: string, tableName: string, queryString: string): Promise<IConnectableInput>;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { IQueryEditorService, INewSqlEditorOptions } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { IConnectableInput } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput';
|
||||
@@ -17,10 +17,9 @@ export class TestQueryEditorService implements IQueryEditorService {
|
||||
constructor(
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@IEditorService private readonly editorService: IEditorService) {
|
||||
|
||||
}
|
||||
|
||||
newSqlEditor(sqlContent?: string, connectionProviderName?: string, isDirty?: boolean, objectName?: string): Promise<IConnectableInput> {
|
||||
newSqlEditor(options?: INewSqlEditorOptions): Promise<IConnectableInput> {
|
||||
const base = this.editorService.createEditorInput({ forceUntitled: true }) as UntitledTextEditorInput;
|
||||
return Promise.resolve(this.instantiationService.createInstance(UntitledQueryEditorInput, '', base, new QueryResultsInput(base.resource.toString(true))));
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ export class TaskService implements ITaskService {
|
||||
if ((task.status === TaskStatus.Succeeded || task.status === TaskStatus.SucceededWithWarning)
|
||||
&& eventArgs.script && eventArgs.script !== '') {
|
||||
if (task.taskExecutionMode === TaskExecutionMode.script) {
|
||||
this.queryEditorService.newSqlEditor(eventArgs.script);
|
||||
this.queryEditorService.newSqlEditor({ initalContent: eventArgs.script });
|
||||
} else if (task.taskExecutionMode === TaskExecutionMode.executeAndScript) {
|
||||
task.script = eventArgs.script;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user