mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Bug/restore query editor tabs (#6654)
* trial run for query editor temp file fix * Fixing restore tabs bug with right layering * Moving FileService change from vscode to our code
This commit is contained in:
@@ -10,6 +10,7 @@ import { URI } from 'vs/base/common/uri';
|
||||
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
|
||||
import { EditorInput, ConfirmResult, EncodingMode, IEncodingSupport } 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/parts/query/common/queryResultsInput';
|
||||
@@ -18,6 +19,7 @@ import { IQueryModelService } from 'sql/platform/query/common/queryModel';
|
||||
import { ISelectionData, ExecutionPlanOptions } from 'azdata';
|
||||
import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel';
|
||||
import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
|
||||
const MAX_SIZE = 13;
|
||||
|
||||
@@ -117,7 +119,8 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
|
||||
private _connectionProviderName: string,
|
||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||
@IQueryModelService private _queryModelService: IQueryModelService,
|
||||
@IConfigurationService private _configurationService: IConfigurationService
|
||||
@IConfigurationService private _configurationService: IConfigurationService,
|
||||
@IFileService private _fileService: IFileService
|
||||
) {
|
||||
super();
|
||||
this._updateSelection = new Emitter<ISelectionData>();
|
||||
@@ -218,6 +221,14 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
|
||||
return false;
|
||||
}
|
||||
|
||||
public matchInputInstanceType(inputType: any): boolean {
|
||||
return (this._sql instanceof inputType);
|
||||
}
|
||||
|
||||
public inputFileExists(): Promise<boolean> {
|
||||
return this._fileService.exists(this.getResource());
|
||||
}
|
||||
|
||||
public getName(longForm?: boolean): string {
|
||||
if (this._configurationService.getValue('sql.showConnectionInfoInTitle')) {
|
||||
let profile = this._connectionManagementService.getConnectionProfile(this.uri);
|
||||
|
||||
@@ -294,6 +294,7 @@ suite('SQL QueryEditor Tests', () => {
|
||||
undefined,
|
||||
connectionManagementService.object,
|
||||
queryModelService.object,
|
||||
undefined,
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
@@ -76,7 +76,7 @@ suite('TaskUtilities', function () {
|
||||
// Mock the workbench service to return the active tab connection
|
||||
let tabConnectionUri = 'file://test_uri';
|
||||
let editorInput = new UntitledEditorInput(URI.parse(tabConnectionUri), false, undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
let queryInput = new QueryInput(undefined, editorInput, undefined, undefined, undefined, undefined, undefined);
|
||||
let queryInput = new QueryInput(undefined, editorInput, undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
mockConnectionManagementService.setup(x => x.getConnectionProfile(tabConnectionUri)).returns(() => tabProfile);
|
||||
|
||||
// If I call getCurrentGlobalConnection, it should return the expected profile from the active tab
|
||||
|
||||
@@ -426,6 +426,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
}
|
||||
|
||||
private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise<void> {
|
||||
await this._group.removeNonExitingEditor(); // {{SQL CARBON EDIT}} @udeeshagautam perform async correction for non-existing files
|
||||
|
||||
if (this._group.count === 0) {
|
||||
return; // nothing to show
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorIn
|
||||
import * as CustomInputConverter from 'sql/workbench/common/customInputConverter';
|
||||
import { NotebookInput } from 'sql/workbench/parts/notebook/common/models/notebookInput';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as os from 'os';
|
||||
|
||||
const EditorOpenPositioning = {
|
||||
LEFT: 'left',
|
||||
@@ -666,15 +664,6 @@ export class EditorGroup extends Disposable {
|
||||
&& !this.configurationService.getValue<boolean>('sql.promptToSaveGeneratedFiles')) {
|
||||
return;
|
||||
}
|
||||
// Do not add generated files from Temp if file is not dirty
|
||||
if (e instanceof FileEditorInput && !e.isDirty()) {
|
||||
let filePath = e.getResource() ? e.getResource().fsPath : undefined;
|
||||
let tempPath = os.tmpdir();
|
||||
if (filePath && tempPath &&
|
||||
filePath.toLocaleLowerCase().includes(path.join(tempPath.toLocaleLowerCase(), 'mssql_definition'))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// {{SQL CARBON EDIT}} - End
|
||||
|
||||
const value = factory.serialize(e);
|
||||
@@ -740,4 +729,26 @@ export class EditorGroup extends Disposable {
|
||||
this.preview = this.editors[data.preview];
|
||||
}
|
||||
}
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
async removeNonExitingEditor(): Promise<void> {
|
||||
let n = 0;
|
||||
while (n < this.editors.length) {
|
||||
let editor = this.editors[n];
|
||||
if (editor instanceof QueryInput && 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 = this.mru.findIndex(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.close();
|
||||
}
|
||||
else {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// {{SQL CARBON EDIT}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user