Fix lost results on query editor save (#21043)

* Fix lost results on query editor save

* Fix typos
This commit is contained in:
Karl Burtram
2022-10-31 14:51:12 -07:00
committed by GitHub
parent 4ade808695
commit e0e333c35f
4 changed files with 36 additions and 14 deletions

View File

@@ -13,12 +13,15 @@ import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverServ
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel'; import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel';
import { EncodingMode } from 'vs/workbench/services/textfile/common/textfiles'; import { EncodingMode } from 'vs/workbench/services/textfile/common/textfiles';
import { GroupIdentifier, ISaveOptions, EditorInputCapabilities, IUntypedEditorInput } from 'vs/workbench/common/editor'; import { GroupIdentifier, ISaveOptions, EditorInputCapabilities, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, isEditorInputWithOptionsAndGroup } from 'vs/workbench/common/editor';
import { FileQueryEditorInput } from 'sql/workbench/contrib/query/browser/fileQueryEditorInput'; import { FileQueryEditorInput } from 'sql/workbench/contrib/query/browser/fileQueryEditorInput';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput'; import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput';
import { UNTITLED_QUERY_EDITOR_TYPEID } from 'sql/workbench/common/constants'; import { UNTITLED_QUERY_EDITOR_TYPEID } from 'sql/workbench/common/constants';
import { IUntitledQueryEditorInput } from 'sql/base/query/common/untitledQueryEditorInput'; import { IUntitledQueryEditorInput } from 'sql/base/query/common/untitledQueryEditorInput';
import { IEditorResolverService } from 'vs/workbench/services/editor/common/editorResolverService';
import { Uri } from 'vscode';
import { ILogService } from 'vs/platform/log/common/log';
export class UntitledQueryEditorInput extends QueryEditorInput implements IUntitledQueryEditorInput { export class UntitledQueryEditorInput extends QueryEditorInput implements IUntitledQueryEditorInput {
@@ -32,6 +35,8 @@ export class UntitledQueryEditorInput extends QueryEditorInput implements IUntit
@IQueryModelService queryModelService: IQueryModelService, @IQueryModelService queryModelService: IQueryModelService,
@IConfigurationService configurationService: IConfigurationService, @IConfigurationService configurationService: IConfigurationService,
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@ILogService private readonly logService: ILogService,
@IEditorResolverService private readonly editorResolverService: IEditorResolverService
) { ) {
super(description, text, results, connectionManagementService, queryModelService, configurationService, instantiationService); super(description, text, results, connectionManagementService, queryModelService, configurationService, instantiationService);
// Set the mode explicitely to stop the auto language detection service from changing the mode unexpectedly. // Set the mode explicitely to stop the auto language detection service from changing the mode unexpectedly.
@@ -54,23 +59,31 @@ export class UntitledQueryEditorInput extends QueryEditorInput implements IUntit
override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<IUntypedEditorInput | undefined> { override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<IUntypedEditorInput | undefined> {
let fileEditorInput = await this.text.save(group, options); let fileEditorInput = await this.text.save(group, options);
return this.createFileQueryEditorInput(fileEditorInput); return this.createFileQueryEditorInput(fileEditorInput, group);
} }
override async saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IUntypedEditorInput | undefined> { override async saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IUntypedEditorInput | undefined> {
let fileEditorInput = await this.text.saveAs(group, options); let fileEditorInput = await this.text.saveAs(group, options);
return this.createFileQueryEditorInput(fileEditorInput); return this.createFileQueryEditorInput(fileEditorInput, group);
} }
private async createFileQueryEditorInput(fileEditorInput: IUntypedEditorInput): Promise<IUntypedEditorInput> { private async createFileQueryEditorInput(untypedEditor: IUntypedEditorInput, group: GroupIdentifier): Promise<IUntypedEditorInput> {
// Create our own FileQueryEditorInput wrapper here so that the existing state (connection, results, etc) can be transferred from this input to the new file input. // Create our own FileQueryEditorInput wrapper here so that the existing state (connection, results, etc) can be transferred from this input to the new file input.
try { try {
let newUri = (<any>fileEditorInput).resource.toString(true); let newUri: Uri = (<any>untypedEditor).resource;
await this.changeConnectionUri(newUri); let newUriString = newUri.toString(true);
this._results.uri = newUri; await this.changeConnectionUri(newUriString);
let newInput = this.instantiationService.createInstance(FileQueryEditorInput, '', (fileEditorInput as FileEditorInput), this.results);
newInput.state.setState(this.state); // create a FileQueryEditorInput from the untyped editor input
return newInput; this._results.uri = newUriString;
const editor = await this.editorResolverService.resolveEditor({ resource: (<any>untypedEditor).resource, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }, group);
if (isEditorInputWithOptionsAndGroup(editor)) {
let newInput = this.instantiationService.createInstance(FileQueryEditorInput, '', <FileEditorInput>(editor.editor), this.results);
newInput.state.setState(this.state);
return newInput;
} else {
throw new Error(`Could not resolved editor for resource '${newUriString}'`);
}
} }
catch (error) { catch (error) {
/** /**
@@ -79,7 +92,8 @@ export class UntitledQueryEditorInput extends QueryEditorInput implements IUntit
* the connection will be undefined and the file appears to be disconnected even if its not, change the connection to fix this. * the connection will be undefined and the file appears to be disconnected even if its not, change the connection to fix this.
* also the results shown will be the old results, until run is clicked again. * also the results shown will be the old results, until run is clicked again.
*/ */
return fileEditorInput; this.logService.warn(error.message);
return untypedEditor;
} }
} }

View File

@@ -312,10 +312,10 @@ export class QueryEditor extends EditorPane {
// TODO: Allow query provider to provide the language mode. // TODO: Allow query provider to provide the language mode.
if (this.input instanceof UntitledQueryEditorInput) { if (this.input instanceof UntitledQueryEditorInput) {
if ((providerId === 'KUSTO') || this.languageService.getExtensions('Kusto').indexOf(fileExtension) > -1) { if ((providerId === 'KUSTO') || this.languageService.getExtensions('kusto').indexOf(fileExtension) > -1) {
this.input.setMode('kusto'); this.input.setMode('kusto');
} }
else if (providerId === 'LOGANALYTICS' || this.languageService.getExtensions('LogAnalytics').indexOf(fileExtension) > -1) { else if (providerId === 'LOGANALYTICS' || this.languageService.getExtensions('loganalytics').indexOf(fileExtension) > -1) {
this.input.setMode('loganalytics'); this.input.setMode('loganalytics');
} }
} }

View File

@@ -314,7 +314,9 @@ suite('SQL QueryEditor Tests', () => {
connectionManagementService.object, connectionManagementService.object,
queryModelService.object, queryModelService.object,
configurationService.object, configurationService.object,
testinstantiationService testinstantiationService,
undefined,
undefined
); );
}); });

View File

@@ -41,6 +41,7 @@ import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService'; import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
import { FileQueryEditorInput } from 'sql/workbench/contrib/query/browser/fileQueryEditorInput'; // {{SQL CARBON EDIT}} - add type
type CachedEditorInput = TextResourceEditorInput | IFileEditorInput | UntitledTextEditorInput; type CachedEditorInput = TextResourceEditorInput | IFileEditorInput | UntitledTextEditorInput;
@@ -1129,6 +1130,11 @@ export class EditorService extends Disposable implements EditorServiceImpl {
break; // failed or cancelled, abort break; // failed or cancelled, abort
} }
// {{SQL CARBON EDIT}} - disable editor resolution when replacing editors to maintain previous state
if (result instanceof FileQueryEditorInput) {
editorOptions.override = EditorResolution.DISABLED;
}
// Replace editor preserving viewstate (either across all groups or // Replace editor preserving viewstate (either across all groups or
// only selected group) if the resulting editor is different from the // only selected group) if the resulting editor is different from the
// current one. // current one.