mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 09:35:39 -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:
@@ -1,12 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { EditorReplacementContribution } from 'sql/workbench/common/editorReplacerContribution';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
|
||||
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
|
||||
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
|
||||
workbenchContributionsRegistry.registerWorkbenchContribution(EditorReplacementContribution, LifecyclePhase.Starting);
|
||||
@@ -1,85 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IEditorInput } from 'vs/workbench/common/editor';
|
||||
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import * as path from 'vs/base/common/path';
|
||||
|
||||
import { ILanguageAssociationRegistry, Extensions as LanguageAssociationExtensions } from 'sql/workbench/common/languageAssociation';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
||||
|
||||
const languageAssociationRegistry = Registry.as<ILanguageAssociationRegistry>(LanguageAssociationExtensions.LanguageAssociations);
|
||||
|
||||
export class EditorReplacementContribution implements IWorkbenchContribution {
|
||||
private editorOpeningListener: IDisposable;
|
||||
|
||||
constructor(
|
||||
@IEditorService private readonly editorService: IEditorService,
|
||||
@IModeService private readonly modeService: IModeService
|
||||
) {
|
||||
this.editorOpeningListener = this.editorService.overrideOpenEditor((editor, options, group) => this.onEditorOpening(editor, options, group));
|
||||
}
|
||||
|
||||
private onEditorOpening(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IOpenEditorOverride | undefined {
|
||||
// If the resource was already opened before in the group, do not prevent
|
||||
// the opening of that resource. Otherwise we would have the same settings
|
||||
// opened twice (https://github.com/Microsoft/vscode/issues/36447)
|
||||
// if (group.isOpened(editor)) {
|
||||
// return undefined;
|
||||
// }
|
||||
|
||||
if (!(editor instanceof FileEditorInput) && !(editor instanceof UntitledTextEditorInput)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let language: string;
|
||||
if (editor instanceof FileEditorInput) {
|
||||
language = editor.getPreferredMode();
|
||||
} else if (editor instanceof UntitledTextEditorInput) {
|
||||
language = editor.getMode();
|
||||
}
|
||||
|
||||
if (!language) { // in the case the input doesn't have a preferred mode set we will attempt to guess the mode from the file path
|
||||
language = this.modeService.getModeIdByFilepathOrFirstLine(editor.getResource());
|
||||
}
|
||||
|
||||
if (!language) {
|
||||
// just use the extension
|
||||
language = path.extname(editor.getResource().toString()).slice(1); // remove the .
|
||||
}
|
||||
|
||||
if (!language) {
|
||||
const defaultInputCreator = languageAssociationRegistry.defaultAssociation;
|
||||
if (defaultInputCreator) {
|
||||
editor.setMode(defaultInputCreator[0]);
|
||||
const newInput = defaultInputCreator[1].convertInput(editor);
|
||||
if (newInput) {
|
||||
return { override: this.editorService.openEditor(newInput, options, group) };
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const inputCreator = languageAssociationRegistry.getAssociationForLanguage(language);
|
||||
if (inputCreator) {
|
||||
const newInput = inputCreator.convertInput(editor);
|
||||
if (newInput) {
|
||||
return { override: this.editorService.openEditor(newInput, options, group) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
dispose(this.editorOpeningListener);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||
import { localize } from 'vs/nls';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IHostService } from 'vs/workbench/services/host/browser/host';
|
||||
|
||||
export abstract class AbstractEnablePreviewFeatures implements IWorkbenchContribution {
|
||||
|
||||
private static ENABLE_PREVIEW_FEATURES_SHOWN = 'workbench.enablePreviewFeaturesShown';
|
||||
|
||||
constructor(
|
||||
@IStorageService private readonly storageService: IStorageService,
|
||||
@INotificationService private readonly notificationService: INotificationService,
|
||||
@IHostService private readonly hostService: IHostService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService
|
||||
) { }
|
||||
|
||||
protected handlePreviewFeatures(): void {
|
||||
let previewFeaturesEnabled = this.configurationService.getValue('workbench')['enablePreviewFeatures'];
|
||||
if (previewFeaturesEnabled || this.storageService.get(AbstractEnablePreviewFeatures.ENABLE_PREVIEW_FEATURES_SHOWN, StorageScope.GLOBAL)) {
|
||||
return;
|
||||
}
|
||||
Promise.all([
|
||||
this.hostService.hasFocus,
|
||||
this.getWindowCount()
|
||||
]).then(async ([focused, count]) => {
|
||||
if (!focused && count > 1) {
|
||||
return null;
|
||||
}
|
||||
await this.configurationService.updateValue('workbench.enablePreviewFeatures', false);
|
||||
|
||||
const enablePreviewFeaturesNotice = localize('enablePreviewFeatures.notice', "Preview features are required in order for extensions to be fully supported and for some actions to be available. Would you like to enable preview features?");
|
||||
this.notificationService.prompt(
|
||||
Severity.Info,
|
||||
enablePreviewFeaturesNotice,
|
||||
[{
|
||||
label: localize('enablePreviewFeatures.yes', "Yes"),
|
||||
run: () => {
|
||||
this.configurationService.updateValue('workbench.enablePreviewFeatures', true).catch(e => onUnexpectedError(e));
|
||||
this.storageService.store(AbstractEnablePreviewFeatures.ENABLE_PREVIEW_FEATURES_SHOWN, true, StorageScope.GLOBAL);
|
||||
}
|
||||
}, {
|
||||
label: localize('enablePreviewFeatures.no', "No"),
|
||||
run: () => {
|
||||
this.configurationService.updateValue('workbench.enablePreviewFeatures', false).catch(e => onUnexpectedError(e));
|
||||
}
|
||||
}, {
|
||||
label: localize('enablePreviewFeatures.never', "No, don't show again"),
|
||||
run: () => {
|
||||
this.configurationService.updateValue('workbench.enablePreviewFeatures', false).catch(e => onUnexpectedError(e));
|
||||
this.storageService.store(AbstractEnablePreviewFeatures.ENABLE_PREVIEW_FEATURES_SHOWN, true, StorageScope.GLOBAL);
|
||||
},
|
||||
isSecondary: true
|
||||
}]
|
||||
);
|
||||
}).catch(e => onUnexpectedError(e));
|
||||
}
|
||||
|
||||
protected abstract getWindowCount(): Promise<number>;
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { UntitledTextEditorInput } from 'vs/workbench/common/editor/untitledTextEditorInput';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
import { getCodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
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 languageAssociationRegistery = 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, languageAssociationRegistery);
|
||||
|
||||
export function doHandleUpgrade(editor?: EditorInput): EditorInput | undefined {
|
||||
if (editor instanceof UntitledTextEditorInput || editor instanceof FileEditorInput) {
|
||||
const activeWidget = getCodeEditor(editor);
|
||||
const textModel = activeWidget.getModel();
|
||||
const oldLanguage = textModel.getLanguageIdentifier().language;
|
||||
const association = languageAssociationRegistery.getAssociationForLanguage(oldLanguage);
|
||||
if (association) {
|
||||
return association.convertInput(editor);
|
||||
}
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
@@ -4,11 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as ConnectionConstants from 'sql/platform/connection/common/constants';
|
||||
import { QueryEditorInput } from 'sql/workbench/contrib/query/common/queryEditorInput';
|
||||
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IEditorInput } from 'vs/workbench/common/editor';
|
||||
|
||||
/**
|
||||
* Gets the 'sql' configuration section for use in looking up settings. Note that configs under
|
||||
@@ -23,15 +19,3 @@ export function getSqlConfigValue<T>(workspaceConfigService: IConfigurationServi
|
||||
let config = workspaceConfigService.getValue(ConnectionConstants.sqlConfigSectionName);
|
||||
return config[configName];
|
||||
}
|
||||
|
||||
export function getEditorUri(input: IEditorInput): string {
|
||||
let uri: URI;
|
||||
if (input instanceof QueryEditorInput) {
|
||||
uri = input.getResource();
|
||||
}
|
||||
|
||||
if (uri) {
|
||||
return uri.toString(true);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
|
||||
import { ITreeViewDataProvider, ITreeItem as vsITreeItem, IViewDescriptor, ITreeView as vsITreeView } from 'vs/workbench/common/views';
|
||||
import { IConnectionProfile } from 'azdata';
|
||||
import { ExtensionNodeType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
|
||||
export enum NodeType {
|
||||
Server = 'Server',
|
||||
Database = 'Database'
|
||||
}
|
||||
|
||||
export interface ITreeComponentItem extends vsITreeItem {
|
||||
checked?: boolean;
|
||||
@@ -15,7 +19,7 @@ export interface ITreeComponentItem extends vsITreeItem {
|
||||
}
|
||||
|
||||
export interface IModelViewTreeViewDataProvider extends ITreeViewDataProvider {
|
||||
refresh(itemsToRefreshByHandle: { [treeItemHandle: string]: ITreeComponentItem });
|
||||
refresh(itemsToRefreshByHandle: { [treeItemHandle: string]: ITreeComponentItem }): void;
|
||||
}
|
||||
|
||||
export interface ITreeItem extends vsITreeItem {
|
||||
@@ -23,7 +27,7 @@ export interface ITreeItem extends vsITreeItem {
|
||||
childProvider?: string;
|
||||
payload?: IConnectionProfile; // its possible we will want this to be more generic
|
||||
sqlIcon?: string;
|
||||
type?: ExtensionNodeType;
|
||||
type?: NodeType;
|
||||
}
|
||||
|
||||
export interface ITreeView extends vsITreeView {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
// eslint-disable-next-line code-layering
|
||||
// eslint-disable-next-line code-layering,code-import-patterns
|
||||
import { IElectronService } from 'vs/platform/electron/node/electron';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user