diff --git a/src/sql/workbench/common/editor/query/untitledQueryEditorInput.ts b/src/sql/base/query/browser/untitledQueryEditorInput.ts similarity index 88% rename from src/sql/workbench/common/editor/query/untitledQueryEditorInput.ts rename to src/sql/base/query/browser/untitledQueryEditorInput.ts index 138eb91a20..94dcf780a2 100644 --- a/src/sql/workbench/common/editor/query/untitledQueryEditorInput.ts +++ b/src/sql/base/query/browser/untitledQueryEditorInput.ts @@ -12,12 +12,14 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel'; -import { EncodingMode, IEncodingSupport } from 'vs/workbench/services/textfile/common/textfiles'; +import { EncodingMode } from 'vs/workbench/services/textfile/common/textfiles'; import { EditorInputCapabilities } from 'vs/workbench/common/editor'; +import { UNTITLED_QUERY_EDITOR_TYPEID } from 'sql/workbench/common/constants'; +import { IUntitledQueryEditorInput } from 'sql/base/query/common/untitledQueryEditorInput'; -export class UntitledQueryEditorInput extends QueryEditorInput implements IEncodingSupport { +export class UntitledQueryEditorInput extends QueryEditorInput implements IUntitledQueryEditorInput { - public static readonly ID = 'workbench.editorInput.untitledQueryInput'; + public static readonly ID = UNTITLED_QUERY_EDITOR_TYPEID; constructor( description: string | undefined, diff --git a/src/sql/base/query/common/untitledQueryEditorInput.ts b/src/sql/base/query/common/untitledQueryEditorInput.ts new file mode 100644 index 0000000000..7de64e0ec0 --- /dev/null +++ b/src/sql/base/query/common/untitledQueryEditorInput.ts @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { IConnectableInput } from 'sql/platform/connection/common/connectionManagement'; +import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService'; +import { EditorInputCapabilities } from 'vs/workbench/common/editor'; +import { EditorInput } from 'vs/workbench/common/editor/editorInput'; +import { EncodingMode } from 'vs/workbench/services/textfile/common/textfiles'; +import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; +import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel'; + +export interface IUntitledQueryEditorInput extends EditorInput, IConnectableInput { + + resolve(): Promise; + + text: UntitledTextEditorInput; + + hasAssociatedFilePath: boolean; + + setMode(mode: string): void + + getMode(): string | undefined; + + typeId: string; + + getEncoding(): string | undefined; + + setEncoding(encoding: string, mode: EncodingMode): Promise + + capabilities: EditorInputCapabilities +} diff --git a/src/sql/workbench/browser/editor/resourceViewer/resourceViewerInput.ts b/src/sql/workbench/browser/editor/resourceViewer/resourceViewerInput.ts index 44916ba7ae..3ea24455e0 100644 --- a/src/sql/workbench/browser/editor/resourceViewer/resourceViewerInput.ts +++ b/src/sql/workbench/browser/editor/resourceViewer/resourceViewerInput.ts @@ -13,6 +13,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import { ButtonColumn } from 'sql/base/browser/ui/table/plugins/buttonColumn.plugin'; import { getDataGridFormatter } from 'sql/workbench/services/dataGridProvider/browser/dataGridProviderUtils'; import { FilterableColumn } from 'sql/base/browser/ui/table/interfaces'; +import { RESOURCE_VIEWER_TYPEID } from 'sql/workbench/common/constants'; export interface ColumnDefinition extends FilterableColumn { name: string; @@ -22,7 +23,7 @@ export interface ColumnDefinition extends FilterableColumn export class ResourceViewerInput extends EditorInput { - public static ID: string = 'workbench.editorInput.resourceViewerInput'; + public static ID: string = RESOURCE_VIEWER_TYPEID; private _dataGridProvider: DataGridProvider; private _data: azdata.DataGridItem[] = []; diff --git a/src/sql/workbench/common/constants.ts b/src/sql/workbench/common/constants.ts index b7ca98f98d..6fe1296d50 100644 --- a/src/sql/workbench/common/constants.ts +++ b/src/sql/workbench/common/constants.ts @@ -30,6 +30,9 @@ export const InputBoxFocusedKey = new RawContextKey('inputBoxFocus', fa export const SearchInputBoxFocusedKey = new RawContextKey('searchInputBoxFocus', false); export const UNTITLED_NOTEBOOK_TYPEID = 'workbench.editorinputs.untitledNotebookInput'; +export const UNTITLED_QUERY_EDITOR_TYPEID = 'workbench.editorinputs.untitledQueryInput'; +export const FILE_QUERY_EDITOR_TYPEID = 'workbench.editorinputs.fileQueryInput'; +export const RESOURCE_VIEWER_TYPEID = 'workbench.editorinputs.resourceViewerInput'; export const enum NotebookLanguage { Notebook = 'Notebook', diff --git a/src/sql/workbench/contrib/query/browser/fileQueryEditorInput.ts b/src/sql/workbench/contrib/query/browser/fileQueryEditorInput.ts index 5557ab282b..8712f3e6bc 100644 --- a/src/sql/workbench/contrib/query/browser/fileQueryEditorInput.ts +++ b/src/sql/workbench/contrib/query/browser/fileQueryEditorInput.ts @@ -14,10 +14,11 @@ import { IMoveResult, GroupIdentifier } from 'vs/workbench/common/editor'; import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel'; import { EncodingMode, ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles'; import { URI } from 'vs/base/common/uri'; +import { FILE_QUERY_EDITOR_TYPEID } from 'sql/workbench/common/constants'; export class FileQueryEditorInput extends QueryEditorInput { - public static readonly ID = 'workbench.editorInput.fileQueryInput'; + public static readonly ID = FILE_QUERY_EDITOR_TYPEID; constructor( description: string, diff --git a/src/sql/workbench/contrib/query/browser/query.contribution.ts b/src/sql/workbench/contrib/query/browser/query.contribution.ts index d309a036e3..de790ebdb3 100644 --- a/src/sql/workbench/contrib/query/browser/query.contribution.ts +++ b/src/sql/workbench/contrib/query/browser/query.contribution.ts @@ -32,7 +32,7 @@ import { SqlFlavorStatusbarItem, ChangeFlavorAction } from 'sql/workbench/contri import { EditorExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor'; import { FileQueryEditorInput } from 'sql/workbench/contrib/query/browser/fileQueryEditorInput'; import { FileQueryEditorInputSerializer, QueryEditorLanguageAssociation, UntitledQueryEditorInputSerializer } from 'sql/workbench/contrib/query/browser/queryInputFactory'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { ILanguageAssociationRegistry, Extensions as LanguageAssociationExtensions } from 'sql/workbench/services/languageAssociation/common/languageAssociation'; import { NewQueryTask, OE_NEW_QUERY_ACTION_ID, DE_NEW_QUERY_COMMAND_ID } from 'sql/workbench/contrib/query/browser/queryActions'; import { TreeNodeContextKey } from 'sql/workbench/services/objectExplorer/common/treeNodeContextKey'; diff --git a/src/sql/workbench/contrib/query/browser/queryEditor.ts b/src/sql/workbench/contrib/query/browser/queryEditor.ts index 1074a892b1..89322c8b10 100644 --- a/src/sql/workbench/contrib/query/browser/queryEditor.ts +++ b/src/sql/workbench/contrib/query/browser/queryEditor.ts @@ -39,7 +39,7 @@ import * as queryContext from 'sql/workbench/contrib/query/common/queryContext'; import { Taskbar, ITaskbarContent } from 'sql/base/browser/ui/taskbar/taskbar'; import * as actions from 'sql/workbench/contrib/query/browser/queryActions'; import { IRange } from 'vs/editor/common/core/range'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { IEditorOptions } from 'vs/platform/editor/common/editor'; diff --git a/src/sql/workbench/contrib/query/browser/queryInputFactory.ts b/src/sql/workbench/contrib/query/browser/queryInputFactory.ts index 9817ffe960..bf94aa18cc 100644 --- a/src/sql/workbench/contrib/query/browser/queryInputFactory.ts +++ b/src/sql/workbench/contrib/query/browser/queryInputFactory.ts @@ -8,7 +8,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResultsInput'; import { FILE_EDITOR_INPUT_ID } from 'vs/workbench/contrib/files/common/files'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { FileQueryEditorInput } from 'sql/workbench/contrib/query/browser/fileQueryEditorInput'; import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; diff --git a/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts b/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts index 430c46adf0..d28389b6d1 100644 --- a/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts +++ b/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts @@ -23,7 +23,7 @@ import * as TypeMoq from 'typemoq'; import * as assert from 'assert'; import { TestFileService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices'; import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService'; import { TestQueryModelService } from 'sql/workbench/services/query/test/common/testQueryModelService'; import { URI } from 'vs/base/common/uri'; diff --git a/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts b/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts index e6e06665ef..ad09f06367 100644 --- a/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts +++ b/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts @@ -20,7 +20,7 @@ import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane'; import { workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices'; import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { TestQueryModelService } from 'sql/workbench/services/query/test/common/testQueryModelService'; import { Event } from 'vs/base/common/event'; import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService'; diff --git a/src/sql/workbench/contrib/query/test/browser/queryInputFactory.test.ts b/src/sql/workbench/contrib/query/test/browser/queryInputFactory.test.ts index 6cb80988ed..1273cc6d56 100644 --- a/src/sql/workbench/contrib/query/test/browser/queryInputFactory.test.ts +++ b/src/sql/workbench/contrib/query/test/browser/queryInputFactory.test.ts @@ -19,7 +19,7 @@ import { TestConnectionManagementService } from 'sql/platform/connection/test/co import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; import { IConnectionManagementService, IConnectionCompletionOptions, IConnectionCallbacks, IConnectionResult } from 'sql/platform/connection/common/connectionManagement'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService'; import { isThenable } from 'vs/base/common/async'; diff --git a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts index 77be3c094d..c596a40a4d 100644 --- a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts @@ -7,7 +7,7 @@ import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResult import { EditDataInput } from 'sql/workbench/browser/editData/editDataInput'; import { ConnectionType, IConnectableInput, IConnectionCompletionOptions, IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; import { IQueryEditorService, INewSqlEditorOptions } from 'sql/workbench/services/queryEditor/common/queryEditorService'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; diff --git a/src/sql/workbench/services/queryEditor/common/queryEditorService.ts b/src/sql/workbench/services/queryEditor/common/queryEditorService.ts index 82d586873b..8b5148c4b8 100644 --- a/src/sql/workbench/services/queryEditor/common/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/common/queryEditorService.ts @@ -7,7 +7,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'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; +import { IUntitledQueryEditorInput } from 'sql/base/query/common/untitledQueryEditorInput'; export interface IQueryEditorOptions extends IEditorOptions { @@ -45,7 +45,7 @@ export interface IQueryEditorService { _serviceBrand: undefined; // Creates new untitled document for SQL/KUSTO queries and opens it in a new editor tab - newSqlEditor(options?: INewSqlEditorOptions, connectionProviderName?: string): Promise; + newSqlEditor(options?: INewSqlEditorOptions, connectionProviderName?: string): Promise; // Creates new edit data session newEditDataEditor(schemaName: string, tableName: string, queryString: string): Promise; diff --git a/src/sql/workbench/services/queryEditor/test/common/testQueryEditorService.ts b/src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts similarity index 85% rename from src/sql/workbench/services/queryEditor/test/common/testQueryEditorService.ts rename to src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts index fbb647f9ea..1af4e963f2 100644 --- a/src/sql/workbench/services/queryEditor/test/common/testQueryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts @@ -6,10 +6,11 @@ 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'; +import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResultsInput'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { IUntitledQueryEditorInput } from 'sql/base/query/common/untitledQueryEditorInput'; export class TestQueryEditorService implements IQueryEditorService { _serviceBrand: undefined; @@ -19,7 +20,7 @@ export class TestQueryEditorService implements IQueryEditorService { @IEditorService private readonly editorService: IEditorService) { } - newSqlEditor(options?: INewSqlEditorOptions): Promise { + newSqlEditor(options?: INewSqlEditorOptions): Promise { const base = this.editorService.createEditorInput({ forceUntitled: true }) as UntitledTextEditorInput; return Promise.resolve(this.instantiationService.createInstance(UntitledQueryEditorInput, '', base, new QueryResultsInput(base.resource.toString(true)))); } diff --git a/src/sql/workbench/test/browser/parts/editor/editorStatusModeSelect.test.ts b/src/sql/workbench/test/browser/parts/editor/editorStatusModeSelect.test.ts index 95e4177887..9f974f5789 100644 --- a/src/sql/workbench/test/browser/parts/editor/editorStatusModeSelect.test.ts +++ b/src/sql/workbench/test/browser/parts/editor/editorStatusModeSelect.test.ts @@ -15,7 +15,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService'; import { Registry } from 'vs/platform/registry/common/platform'; import { ILanguageAssociationRegistry, Extensions as LanguageAssociationExtensions } from 'sql/workbench/services/languageAssociation/common/languageAssociation'; -import { TestQueryEditorService } from 'sql/workbench/services/queryEditor/test/common/testQueryEditorService'; +import { TestQueryEditorService } from 'sql/workbench/services/queryEditor/test/browser/testQueryEditorService'; import { ITestInstantiationService, TestEditorService } from 'vs/workbench/test/browser/workbenchTestServices'; import { NotebookServiceStub } from 'sql/workbench/contrib/notebook/test/stubs'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; diff --git a/src/sql/workbench/test/workbenchTestServices.ts b/src/sql/workbench/test/workbenchTestServices.ts index 0d0424c8d1..231b512b40 100644 --- a/src/sql/workbench/test/workbenchTestServices.ts +++ b/src/sql/workbench/test/workbenchTestServices.ts @@ -11,7 +11,7 @@ import { TestConnectionManagementService } from 'sql/platform/connection/test/co import { TestObjectExplorerService } from 'sql/workbench/services/objectExplorer/test/browser/testObjectExplorerService'; import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService'; import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService'; -import { TestQueryEditorService } from 'sql/workbench/services/queryEditor/test/common/testQueryEditorService'; +import { TestQueryEditorService } from 'sql/workbench/services/queryEditor/test/browser/testQueryEditorService'; import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement'; import { TestQueryManagementService } from 'sql/workbench/services/query/test/common/testQueryManagementService'; diff --git a/src/vs/workbench/services/untitled/common/untitledTextEditorHandler.ts b/src/vs/workbench/services/untitled/common/untitledTextEditorHandler.ts index e46459d82a..5658305c98 100644 --- a/src/vs/workbench/services/untitled/common/untitledTextEditorHandler.ts +++ b/src/vs/workbench/services/untitled/common/untitledTextEditorHandler.ts @@ -19,8 +19,7 @@ import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/u import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { NO_TYPE_ID } from 'vs/workbench/services/workingCopy/common/workingCopy'; import { IWorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService'; -import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/untitledQueryEditorInput'; // {{SQL CARBON EDIT}} Handle our untitled inputs as well -import { UNTITLED_NOTEBOOK_TYPEID } from 'sql/workbench/common/constants'; // {{SQL CARBON EDIT}} Handle our untitled inputs as well +import { UNTITLED_NOTEBOOK_TYPEID, UNTITLED_QUERY_EDITOR_TYPEID } from 'sql/workbench/common/constants'; // {{SQL CARBON EDIT}} Handle our untitled inputs as well interface ISerializedUntitledTextEditorInput { resourceJSON: UriComponents; @@ -103,7 +102,7 @@ export class UntitledTextEditorWorkingCopyEditorHandler extends Disposable imple private installHandler(): void { this._register(this.workingCopyEditorService.registerHandler({ handles: workingCopy => workingCopy.resource.scheme === Schemas.untitled && workingCopy.typeId === NO_TYPE_ID, - isOpen: (workingCopy, editor) => (editor instanceof UntitledTextEditorInput || editor instanceof UntitledQueryEditorInput || editor.typeId === UNTITLED_NOTEBOOK_TYPEID) && isEqual(workingCopy.resource, editor.resource), // {{SQL CARBON EDIT}} Handle our untitled inputs as well. Notebook input can't be imported due to layering currently so just use the typeID for that + isOpen: (workingCopy, editor) => (editor instanceof UntitledTextEditorInput || editor.typeId === UNTITLED_QUERY_EDITOR_TYPEID || editor.typeId === UNTITLED_NOTEBOOK_TYPEID) && isEqual(workingCopy.resource, editor.resource), // {{SQL CARBON EDIT}} Handle our untitled inputs as well. Notebook input can't be imported due to layering currently so just use the typeID for that createEditor: workingCopy => { let editorInputResource: URI;