diff --git a/src/sql/workbench/common/languageAssociation.ts b/src/sql/workbench/common/languageAssociation.ts index cdc8b48489..738b527e36 100644 --- a/src/sql/workbench/common/languageAssociation.ts +++ b/src/sql/workbench/common/languageAssociation.ts @@ -83,7 +83,7 @@ export const Extensions = { Registry.add(Extensions.LanguageAssociations, languageAssociationRegistery); -export function doHandleUpgrade(editor: EditorInput): EditorInput { +export function doHandleUpgrade(editor?: EditorInput): EditorInput | undefined { if (editor instanceof UntitledTextEditorInput || editor instanceof FileEditorInput) { const activeWidget = getCodeEditor(editor); const textModel = activeWidget.getModel(); diff --git a/src/sql/workbench/contrib/commandLine/test/electron-browser/commandLine.test.ts b/src/sql/workbench/contrib/commandLine/test/electron-browser/commandLine.test.ts index 155f76ae59..f7da1c77d0 100644 --- a/src/sql/workbench/contrib/commandLine/test/electron-browser/commandLine.test.ts +++ b/src/sql/workbench/contrib/commandLine/test/electron-browser/commandLine.test.ts @@ -394,7 +394,7 @@ suite('commandLineService tests', () => { const instantiationService = new TestInstantiationService(); let uri = URI.file(args._[0]); const untitledEditorInput = new UntitledTextEditorInput(uri, false, '', '', '', instantiationService, undefined, new LabelService(undefined, undefined), undefined, undefined); - const queryInput = new UntitledQueryEditorInput(undefined, untitledEditorInput, undefined, connectionManagementService.object, querymodelService.object, configurationService.object, undefined); + const queryInput = new UntitledQueryEditorInput(undefined, untitledEditorInput, undefined, connectionManagementService.object, querymodelService.object, configurationService.object); queryInput.state.connected = true; const editorService: TypeMoq.Mock = TypeMoq.Mock.ofType(TestEditorService, TypeMoq.MockBehavior.Strict); editorService.setup(e => e.editors).returns(() => [queryInput]); diff --git a/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts b/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts index 04451c4461..4f909c0574 100644 --- a/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts +++ b/src/sql/workbench/contrib/query/common/fileQueryEditorInput.ts @@ -13,7 +13,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { EncodingMode } from 'vs/workbench/common/editor'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel'; -import { IFileService } from 'vs/platform/files/common/files'; type PublicPart = { [K in keyof T]: T[K] }; @@ -27,10 +26,9 @@ export class FileQueryEditorInput extends QueryEditorInput implements PublicPart results: QueryResultsInput, @IConnectionManagementService connectionManagementService: IConnectionManagementService, @IQueryModelService queryModelService: IQueryModelService, - @IConfigurationService configurationService: IConfigurationService, - @IFileService fileService: IFileService + @IConfigurationService configurationService: IConfigurationService ) { - super(description, text, results, connectionManagementService, queryModelService, configurationService, fileService); + super(description, text, results, connectionManagementService, queryModelService, configurationService); } public resolve(): Promise { diff --git a/src/sql/workbench/contrib/query/common/queryEditorInput.ts b/src/sql/workbench/contrib/query/common/queryEditorInput.ts index dd949001ee..06db032822 100644 --- a/src/sql/workbench/contrib/query/common/queryEditorInput.ts +++ b/src/sql/workbench/contrib/query/common/queryEditorInput.ts @@ -9,7 +9,6 @@ import { Emitter } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; import { EditorInput, GroupIdentifier, IRevertOptions, ISaveOptions, IEditorInput } from 'vs/workbench/common/editor'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { IFileService } from 'vs/platform/files/common/files'; import { IConnectionManagementService, IConnectableInput, INewConnectionParams, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement'; import { QueryResultsInput } from 'sql/workbench/contrib/query/common/queryResultsInput'; @@ -123,8 +122,7 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab protected _results: QueryResultsInput, @IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService, @IQueryModelService private readonly queryModelService: IQueryModelService, - @IConfigurationService private readonly configurationService: IConfigurationService, - @IFileService private _fileService: IFileService + @IConfigurationService private readonly configurationService: IConfigurationService ) { super(); @@ -199,10 +197,6 @@ export abstract class QueryEditorInput extends EditorInput implements IConnectab return (this._text instanceof inputType); } - public inputFileExists(): Promise { - return this._fileService.exists(this.getResource()); - } - public getName(longForm?: boolean): string { if (this.configurationService.getValue('sql.showConnectionInfoInTitle')) { let profile = this.connectionManagementService.getConnectionProfile(this.uri); diff --git a/src/sql/workbench/contrib/query/common/queryInputFactory.ts b/src/sql/workbench/contrib/query/common/queryInputFactory.ts index 06e14cdf37..1d2f8438e4 100644 --- a/src/sql/workbench/contrib/query/common/queryInputFactory.ts +++ b/src/sql/workbench/contrib/query/common/queryInputFactory.ts @@ -19,6 +19,8 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType } from 'sql/platform/connection/common/connectionManagement'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { onUnexpectedError } from 'vs/base/common/errors'; +import { IFileService } from 'vs/platform/files/common/files'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; const editorInputFactoryRegistry = Registry.as(EditorInputExtensions.EditorInputFactories); @@ -63,6 +65,10 @@ export class QueryEditorLanguageAssociation implements ILanguageAssociation { } export class FileQueryEditorInputFactory implements IEditorInputFactory { + + constructor(@IFileService private readonly fileService: IFileService) { + + } serialize(editorInput: FileQueryEditorInput): string { const factory = editorInputFactoryRegistry.getEditorInputFactory(FILE_EDITOR_INPUT_ID); if (factory) { @@ -74,8 +80,14 @@ export class FileQueryEditorInputFactory implements IEditorInputFactory { deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): FileQueryEditorInput | undefined { const factory = editorInputFactoryRegistry.getEditorInputFactory(FILE_EDITOR_INPUT_ID); const fileEditorInput = factory.deserialize(instantiationService, serializedEditorInput) as FileEditorInput; - const queryResultsInput = instantiationService.createInstance(QueryResultsInput, fileEditorInput.getResource().toString()); - return instantiationService.createInstance(FileQueryEditorInput, '', fileEditorInput, queryResultsInput); + // only successfully deserilize the file if the resource actually exists + if (this.fileService.exists(fileEditorInput.getResource())) { + const queryResultsInput = instantiationService.createInstance(QueryResultsInput, fileEditorInput.getResource().toString()); + return instantiationService.createInstance(FileQueryEditorInput, '', fileEditorInput, queryResultsInput); + } else { + fileEditorInput.dispose(); + return undefined; + } } canSerialize(): boolean { // we can always serialize query inputs @@ -84,9 +96,12 @@ export class FileQueryEditorInputFactory implements IEditorInputFactory { } export class UntitledQueryEditorInputFactory implements IEditorInputFactory { + + constructor(@IConfigurationService private readonly configurationService: IConfigurationService) { } serialize(editorInput: UntitledQueryEditorInput): string { const factory = editorInputFactoryRegistry.getEditorInputFactory(UntitledTextEditorInput.ID); - if (factory) { + // only serialize non-dirty files if the user has that setting + if (factory && (editorInput.isDirty() || this.configurationService.getValue('sql.promptToSaveGeneratedFiles'))) { return factory.serialize(editorInput.text); // serialize based on the underlying input } return undefined; diff --git a/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts b/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts index e8bf6b824e..d46d00968a 100644 --- a/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts +++ b/src/sql/workbench/contrib/query/common/untitledQueryEditorInput.ts @@ -11,7 +11,6 @@ import { IQueryModelService } from 'sql/workbench/services/query/common/queryMod import { IEncodingSupport, EncodingMode } from 'vs/workbench/common/editor'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService'; -import { IFileService } from 'vs/platform/files/common/files'; import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput'; import { UntitledTextEditorModel } from 'vs/workbench/common/editor/untitledTextEditorModel'; @@ -29,10 +28,9 @@ export class UntitledQueryEditorInput extends QueryEditorInput implements IEncod results: QueryResultsInput, @IConnectionManagementService connectionManagementService: IConnectionManagementService, @IQueryModelService queryModelService: IQueryModelService, - @IConfigurationService configurationService: IConfigurationService, - @IFileService fileService: IFileService + @IConfigurationService configurationService: IConfigurationService ) { - super(description, text, results, connectionManagementService, queryModelService, configurationService, fileService); + super(description, text, results, connectionManagementService, queryModelService, configurationService); } public resolve(): Promise { 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 f3afe2188d..2d41241b47 100644 --- a/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts +++ b/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts @@ -296,8 +296,7 @@ suite('SQL QueryEditor Tests', () => { undefined, connectionManagementService.object, queryModelService.object, - configurationService.object, - undefined + configurationService.object ); }); diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 371985d992..43bf1de5fa 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -429,8 +429,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView { return; // nothing to show } - await this._group.removeNonExitingEditor(); // {{SQL CARBON EDIT}} @udeeshagautam perform async correction for non-existing files - // Determine editor options let options: EditorOptions; if (from instanceof EditorGroupView) { diff --git a/src/vs/workbench/common/editor/editorGroup.ts b/src/vs/workbench/common/editor/editorGroup.ts index bd8e017c20..4105724996 100644 --- a/src/vs/workbench/common/editor/editorGroup.ts +++ b/src/vs/workbench/common/editor/editorGroup.ts @@ -9,12 +9,9 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'; import { dispose, Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Registry } from 'vs/platform/registry/common/platform'; -import { coalesce, firstIndex } from 'vs/base/common/arrays'; +import { coalesce } from 'vs/base/common/arrays'; // {{SQL CARBON EDIT}} -import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput'; -import { QueryEditorInput } from 'sql/workbench/contrib/query/common/queryEditorInput'; -import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput'; import { doHandleUpgrade } from 'sql/workbench/common/languageAssociation'; const EditorOpenPositioning = { @@ -624,14 +621,6 @@ export class EditorGroup extends Disposable { this.editors.forEach(e => { const factory = registry.getEditorInputFactory(e.getTypeId()); if (factory) { - // {{SQL CARBON EDIT}} - // don't serialize unmodified unitited files - if (e instanceof UntitledTextEditorInput && !e.isDirty() - && !this.configurationService.getValue('sql.promptToSaveGeneratedFiles')) { - return; - } - // {{SQL CARBON EDIT}} - End - const value = factory.serialize(e); if (typeof value === 'string') { serializedEditors.push({ id: e.getTypeId(), value }); @@ -689,26 +678,4 @@ export class EditorGroup extends Disposable { return this._id; } - - // {{SQL CARBON EDIT}} - async removeNonExitingEditor(): Promise { - let n = 0; - while (n < this.editors.length) { - let editor = this.editors[n]; - if (editor instanceof QueryEditorInput && editor.matchInputInstanceType(FileEditorInput) && !editor.isDirty() && await editor.inputFileExists() === false && this.editors.length > 1) { - // remove from editors list so that they do not get restored - this.editors.splice(n, 1); - let index = firstIndex(this.mru, e => e.matches(editor)); - - // remove from MRU list otherwise later if we try to close them it leaves a sticky active editor with no data - this.mru.splice(index, 1); - this.active = this.isActive(editor) ? this.editors[0] : this.active; - editor.dispose(); - } - else { - n++; - } - } - } - // {{SQL CARBON EDIT}} }