Add editor contribution tests (#8784)

* wip

* rewrite association

* fix tests

* add more tests

* fix tests

* fix more tests

* fix tests
This commit is contained in:
Anthony Dresser
2020-01-10 18:57:47 -08:00
committed by GitHub
parent 0059ffb777
commit 2f6c944317
16 changed files with 421 additions and 75 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorInputFactory, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions } from 'vs/workbench/common/editor';
import { IEditorInputFactory, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions, IEditorInput } from 'vs/workbench/common/editor';
import { Registry } from 'vs/platform/registry/common/platform';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { QueryResultsInput } from 'sql/workbench/contrib/query/common/queryResultsInput';
@@ -12,9 +12,33 @@ import { UntitledQueryEditorInput } from 'sql/workbench/contrib/query/common/unt
import { FileQueryEditorInput } from 'sql/workbench/contrib/query/common/fileQueryEditorInput';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
import { ILanguageAssociation } from 'sql/workbench/common/languageAssociation';
import { QueryEditorInput } from 'sql/workbench/contrib/query/common/queryEditorInput';
const editorInputFactoryRegistry = Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories);
export class QueryEditorLanguageAssociation implements ILanguageAssociation {
static readonly isDefault = true;
static readonly languages = ['sql'];
constructor(@IInstantiationService private readonly instantiationService: IInstantiationService) { }
convertInput(activeEditor: IEditorInput): QueryEditorInput {
const queryResultsInput = this.instantiationService.createInstance(QueryResultsInput, activeEditor.getResource().toString(true));
if (activeEditor instanceof FileEditorInput) {
return this.instantiationService.createInstance(FileQueryEditorInput, '', activeEditor, queryResultsInput);
} else if (activeEditor instanceof UntitledTextEditorInput) {
return this.instantiationService.createInstance(UntitledQueryEditorInput, '', activeEditor, queryResultsInput);
} else {
return undefined;
}
}
createBase(activeEditor: QueryEditorInput): IEditorInput {
return activeEditor.text;
}
}
export class FileQueryEditorInputFactory implements IEditorInputFactory {
serialize(editorInput: FileQueryEditorInput): string {
const factory = editorInputFactoryRegistry.getEditorInputFactory(FILE_EDITOR_INPUT_ID);