mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
More layering and strictness (#9004)
* move handling generated files to the serilization classes * remove unneeded methods * add more folders to strictire compile, add more strict compile options * update ci * wip * add more layering and fix issues * add more strictness * remove unnecessary assertion * add missing checks * fix indentation * wip * remove jsdoc * fix layering * fix compile * fix compile errors * wip * wip * finish layering * fix css * more layering * remove no longer good parts * fix issues with startup * another try * fix startup
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { EditorInput } from 'vs/workbench/common/editor';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
import { Extensions as ILanguageAssociationExtensions, ILanguageAssociationRegistry } from 'sql/workbench/services/languageAssociation/common/languageAssociation';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
||||
const languageRegistry = Registry.as<ILanguageAssociationRegistry>(ILanguageAssociationExtensions.LanguageAssociations);
|
||||
|
||||
export function doHandleUpgrade(editor?: EditorInput): EditorInput | undefined {
|
||||
if (editor instanceof UntitledTextEditorInput || editor instanceof FileEditorInput) {
|
||||
let language: string;
|
||||
if (editor instanceof UntitledTextEditorInput) {
|
||||
language = editor.getMode();
|
||||
} else {
|
||||
editor.getPreferredMode();
|
||||
}
|
||||
const association = languageRegistry.getAssociationForLanguage(language);
|
||||
if (association) {
|
||||
return association.convertInput(editor);
|
||||
}
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IEditorInput, EditorInput } from 'vs/workbench/common/editor';
|
||||
import { ServicesAccessor, IInstantiationService, BrandedService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
export type InputCreator = (servicesAccessor: ServicesAccessor, activeEditor: IEditorInput) => EditorInput | undefined;
|
||||
export type BaseInputCreator = (activeEditor: IEditorInput) => IEditorInput;
|
||||
|
||||
export interface ILanguageAssociation {
|
||||
convertInput(activeEditor: IEditorInput): EditorInput | undefined;
|
||||
createBase(activeEditor: IEditorInput): IEditorInput;
|
||||
}
|
||||
|
||||
type ILanguageAssociationSignature<Services extends BrandedService[]> = new (...services: Services) => ILanguageAssociation;
|
||||
|
||||
export interface ILanguageAssociationRegistry {
|
||||
registerLanguageAssociation<Services extends BrandedService[]>(languages: string[], contribution: ILanguageAssociationSignature<Services>, isDefault?: boolean): IDisposable;
|
||||
getAssociationForLanguage(language: string): ILanguageAssociation;
|
||||
readonly defaultAssociation: [string, ILanguageAssociation];
|
||||
|
||||
/**
|
||||
* Starts the registry by providing the required services.
|
||||
*/
|
||||
start(accessor: ServicesAccessor): void;
|
||||
}
|
||||
|
||||
const languageAssociationRegistry = new class implements ILanguageAssociationRegistry {
|
||||
private associationsInstances = new Map<string, ILanguageAssociation>();
|
||||
private associationContructors = new Map<string, ILanguageAssociationSignature<BrandedService[]>>();
|
||||
private defaultAssociationsInstance?: [string, ILanguageAssociation];
|
||||
private defaultAssociationsConstructor?: [string, ILanguageAssociationSignature<BrandedService[]>];
|
||||
|
||||
start(accessor: ServicesAccessor): void {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
|
||||
for (const [language, ctor] of this.associationContructors) {
|
||||
const instance = instantiationService.createInstance(ctor);
|
||||
this.associationsInstances.set(language, instance);
|
||||
}
|
||||
|
||||
if (this.defaultAssociationsConstructor) {
|
||||
this.defaultAssociationsInstance = [this.defaultAssociationsConstructor[0], instantiationService.createInstance(this.defaultAssociationsConstructor[1])];
|
||||
}
|
||||
}
|
||||
|
||||
registerLanguageAssociation<Services extends BrandedService[]>(languages: string[], contribution: ILanguageAssociationSignature<Services>, isDefault?: boolean): IDisposable {
|
||||
for (const language of languages) {
|
||||
this.associationContructors.set(language, contribution);
|
||||
}
|
||||
|
||||
if (isDefault) {
|
||||
this.defaultAssociationsConstructor = [languages[0], contribution];
|
||||
}
|
||||
|
||||
return toDisposable(() => {
|
||||
for (const language of languages) {
|
||||
this.associationContructors.delete(language);
|
||||
this.associationsInstances.delete(language);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getAssociationForLanguage(language: string): ILanguageAssociation | undefined {
|
||||
return this.associationsInstances.get(language);
|
||||
}
|
||||
|
||||
get defaultAssociation(): [string, ILanguageAssociation] | undefined {
|
||||
return this.defaultAssociationsInstance;
|
||||
}
|
||||
};
|
||||
|
||||
export const Extensions = {
|
||||
LanguageAssociations: 'workbench.contributions.editor.languageAssociation'
|
||||
};
|
||||
|
||||
Registry.add(Extensions.LanguageAssociations, languageAssociationRegistry);
|
||||
Reference in New Issue
Block a user