mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-31 09:10:30 -04:00
Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd * fix issues with merges * bump node version in azpipe * replace license headers * remove duplicate launch task * fix build errors * fix build errors * fix tslint issues * working through package and linux build issues * more work * wip * fix packaged builds * working through linux build errors * wip * wip * wip * fix mac and linux file limits * iterate linux pipeline * disable editor typing * revert series to parallel * remove optimize vscode from linux * fix linting issues * revert testing change * add work round for new node * readd packaging for extensions * fix issue with angular not resolving decorator dependencies
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { isLinux } from 'vs/base/common/platform';
|
||||
import { isEqual } from 'vs/base/common/resources';
|
||||
import { endsWith } from 'vs/base/common/strings';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
||||
import { IEditorInput } from 'vs/workbench/common/editor';
|
||||
import { IEditorService, IOpenEditorOverride } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { FOLDER_SETTINGS_PATH, IPreferencesService, USE_SPLIT_JSON_SETTING } from 'vs/workbench/services/preferences/common/preferences';
|
||||
|
||||
const schemaRegistry = Registry.as<JSONContributionRegistry.IJSONContributionRegistry>(JSONContributionRegistry.Extensions.JSONContribution);
|
||||
|
||||
export class PreferencesContribution implements IWorkbenchContribution {
|
||||
private editorOpeningListener: IDisposable;
|
||||
private settingsListener: IDisposable;
|
||||
|
||||
constructor(
|
||||
@IModelService private readonly modelService: IModelService,
|
||||
@ITextModelService private readonly textModelResolverService: ITextModelService,
|
||||
@IPreferencesService private readonly preferencesService: IPreferencesService,
|
||||
@IModeService private readonly modeService: IModeService,
|
||||
@IEditorService private readonly editorService: IEditorService,
|
||||
@IEnvironmentService private readonly environmentService: IEnvironmentService,
|
||||
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService
|
||||
) {
|
||||
this.settingsListener = this.configurationService.onDidChangeConfiguration(e => {
|
||||
if (e.affectsConfiguration(USE_SPLIT_JSON_SETTING)) {
|
||||
this.handleSettingsEditorOverride();
|
||||
}
|
||||
});
|
||||
this.handleSettingsEditorOverride();
|
||||
|
||||
this.start();
|
||||
}
|
||||
|
||||
private handleSettingsEditorOverride(): void {
|
||||
|
||||
// dispose any old listener we had
|
||||
this.editorOpeningListener = dispose(this.editorOpeningListener);
|
||||
|
||||
// install editor opening listener unless user has disabled this
|
||||
if (!!this.configurationService.getValue(USE_SPLIT_JSON_SETTING)) {
|
||||
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 {
|
||||
const resource = editor.getResource();
|
||||
if (
|
||||
!resource ||
|
||||
!endsWith(resource.path, 'settings.json') || // resource must end in settings.json
|
||||
!this.configurationService.getValue(USE_SPLIT_JSON_SETTING) // user has not disabled default settings editor
|
||||
) {
|
||||
return 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;
|
||||
}
|
||||
|
||||
// Global User Settings File
|
||||
if (isEqual(resource, URI.file(this.environmentService.appSettingsPath), !isLinux)) {
|
||||
return { override: this.preferencesService.openGlobalSettings(true, options, group) };
|
||||
}
|
||||
|
||||
// Single Folder Workspace Settings File
|
||||
const state = this.workspaceService.getWorkbenchState();
|
||||
if (state === WorkbenchState.FOLDER) {
|
||||
const folders = this.workspaceService.getWorkspace().folders;
|
||||
if (isEqual(resource, folders[0].toResource(FOLDER_SETTINGS_PATH))) {
|
||||
return { override: this.preferencesService.openWorkspaceSettings(true, options, group) };
|
||||
}
|
||||
}
|
||||
|
||||
// Multi Folder Workspace Settings File
|
||||
else if (state === WorkbenchState.WORKSPACE) {
|
||||
const folders = this.workspaceService.getWorkspace().folders;
|
||||
for (const folder of folders) {
|
||||
if (isEqual(resource, folder.toResource(FOLDER_SETTINGS_PATH))) {
|
||||
return { override: this.preferencesService.openFolderSettings(folder.uri, true, options, group) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private start(): void {
|
||||
|
||||
this.textModelResolverService.registerTextModelContentProvider('vscode', {
|
||||
provideTextContent: (uri: URI): Promise<ITextModel | null> | null => {
|
||||
if (uri.scheme !== 'vscode') {
|
||||
return null;
|
||||
}
|
||||
if (uri.authority === 'schemas') {
|
||||
const schemaModel = this.getSchemaModel(uri);
|
||||
if (schemaModel) {
|
||||
return Promise.resolve(schemaModel);
|
||||
}
|
||||
}
|
||||
return this.preferencesService.resolveModel(uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getSchemaModel(uri: URI): ITextModel | null {
|
||||
let schema = schemaRegistry.getSchemaContributions().schemas[uri.toString()];
|
||||
if (schema) {
|
||||
const modelContent = JSON.stringify(schema);
|
||||
const languageSelection = this.modeService.create('jsonc');
|
||||
const model = this.modelService.createModel(modelContent, languageSelection, uri);
|
||||
const disposables: IDisposable[] = [];
|
||||
disposables.push(schemaRegistry.onDidChangeSchema(schemaUri => {
|
||||
if (schemaUri === uri.toString()) {
|
||||
schema = schemaRegistry.getSchemaContributions().schemas[uri.toString()];
|
||||
model.setValue(JSON.stringify(schema));
|
||||
}
|
||||
}));
|
||||
disposables.push(model.onWillDispose(() => dispose(disposables)));
|
||||
|
||||
return model;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.editorOpeningListener = dispose(this.editorOpeningListener);
|
||||
this.settingsListener = dispose(this.settingsListener);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user