mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-04 09:35:38 -05:00
Use existing resource for untitled if it is already open (#11536)
* use existing resource for untitled if it is already open * remove unnecessary call
This commit is contained in:
@@ -43,7 +43,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 = await this.queryEditorService.newSqlEditor({ open: false, initalContent: content }) as UntitledQueryEditorInput;
|
||||
queryEditorInput = await this.queryEditorService.newSqlEditor({ resource: this.editorService.isOpen(activeEditor) ? activeEditor.resource : undefined, open: false, initalContent: content }) as UntitledQueryEditorInput;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/commo
|
||||
import { isThenable } from 'vs/base/common/async';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResultsInput';
|
||||
import { extUri } from 'vs/base/common/resources';
|
||||
|
||||
suite('Query Input Factory', () => {
|
||||
|
||||
@@ -104,7 +105,7 @@ suite('Query Input Factory', () => {
|
||||
const response = queryEditorLanguageAssociation.convertInput(input);
|
||||
assert(isThenable(response));
|
||||
await response;
|
||||
assert(newsqlEditorStub.calledWithExactly({ open: false, initalContent: '' }));
|
||||
assert(newsqlEditorStub.calledWithExactly({ resource: undefined, open: false, initalContent: '' }));
|
||||
assert(connectionManagementService.numberConnects === 1, 'Convert input should have called connect when active editor connection exists');
|
||||
});
|
||||
|
||||
@@ -134,6 +135,27 @@ suite('Query Input Factory', () => {
|
||||
assert(connectionManagementService.numberConnects === 0, 'Convert input should not have been called connect when no global connections exist');
|
||||
});
|
||||
|
||||
test('uses existing resource if provided', async () => {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
const editorService = new MockEditorService(instantiationService);
|
||||
instantiationService.stub(IEditorService, editorService);
|
||||
const queryEditorLanguageAssociation = instantiationService.createInstance(QueryEditorLanguageAssociation);
|
||||
const untitledService = instantiationService.invokeFunction(accessor => accessor.get(IUntitledTextEditorService));
|
||||
const queryeditorservice = instantiationService.invokeFunction(accessor => accessor.get(IQueryEditorService));
|
||||
const input = instantiationService.createInstance(UntitledTextEditorInput, untitledService.create());
|
||||
sinon.stub(editorService, 'isOpen', (editor: IEditorInput) => extUri.isEqual(editor.resource, input.resource));
|
||||
const newsqlEditorStub = sinon.stub(queryeditorservice, 'newSqlEditor', () => {
|
||||
const untitledInput = instantiationService.createInstance(UntitledTextEditorInput, untitledService.create());
|
||||
const queryResultsInput: QueryResultsInput = instantiationService.createInstance(QueryResultsInput, untitledInput.resource.toString());
|
||||
let queryInput = instantiationService.createInstance(UntitledQueryEditorInput, '', untitledInput, queryResultsInput);
|
||||
return queryInput;
|
||||
});
|
||||
const response = queryEditorLanguageAssociation.convertInput(input);
|
||||
assert(isThenable(response));
|
||||
await response;
|
||||
assert(newsqlEditorStub.calledWithExactly({ resource: input.resource, open: false, initalContent: '' }));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
class ServiceAccessor {
|
||||
|
||||
@@ -48,8 +48,7 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
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 });
|
||||
let docUri: URI = options.resource ?? URI.from({ scheme: Schemas.untitled, path: await this.createUntitledSqlFilePath() });
|
||||
|
||||
// Create a sql document pane with accoutrements
|
||||
const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: 'sql' }) as UntitledTextEditorInput;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IConnectableInput } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export interface IQueryEditorOptions extends IEditorOptions {
|
||||
|
||||
@@ -27,6 +28,10 @@ export interface INewSqlEditorOptions {
|
||||
* defaults to true
|
||||
*/
|
||||
open?: boolean;
|
||||
/**
|
||||
* use an existing resource, if this matches a resource already open that resource will be opened instead
|
||||
*/
|
||||
resource?: URI
|
||||
}
|
||||
|
||||
export interface IQueryEditorService {
|
||||
|
||||
Reference in New Issue
Block a user