Skip to content

Commit

Permalink
Fix #33439
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Oct 30, 2017
1 parent be68d85 commit 997eb0e
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 149 deletions.
157 changes: 68 additions & 89 deletions src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorE
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { MarkdownString } from 'vs/base/common/htmlContent';
import { overrideIdentifierFromKey, IConfigurationService, ConfigurationTarget, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { overrideIdentifierFromKey, IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';

export interface IPreferencesRenderer<T> extends IDisposable {
Expand Down Expand Up @@ -175,7 +175,7 @@ export class UserSettingsRenderer extends Disposable implements IPreferencesRend

export class WorkspaceSettingsRenderer extends UserSettingsRenderer implements IPreferencesRenderer<ISetting> {

private untrustedSettingRenderer: UnsupportedWorkspaceSettingsRenderer;
private unsupportedSettingsRenderer: UnsupportedSettingsRenderer;
private workspaceConfigurationRenderer: WorkspaceConfigurationRenderer;

constructor(editor: ICodeEditor, preferencesModel: SettingsEditorModel,
Expand All @@ -187,7 +187,7 @@ export class WorkspaceSettingsRenderer extends UserSettingsRenderer implements I
@IInstantiationService instantiationService: IInstantiationService
) {
super(editor, preferencesModel, preferencesService, telemetryService, textFileService, configurationService, messageService, instantiationService);
this.untrustedSettingRenderer = this._register(instantiationService.createInstance(UnsupportedWorkspaceSettingsRenderer, editor, preferencesModel));
this.unsupportedSettingsRenderer = this._register(instantiationService.createInstance(UnsupportedSettingsRenderer, editor, preferencesModel));
this.workspaceConfigurationRenderer = this._register(instantiationService.createInstance(WorkspaceConfigurationRenderer, editor, preferencesModel));
}

Expand All @@ -197,14 +197,14 @@ export class WorkspaceSettingsRenderer extends UserSettingsRenderer implements I

public render(): void {
super.render();
this.untrustedSettingRenderer.render();
this.unsupportedSettingsRenderer.render();
this.workspaceConfigurationRenderer.render();
}
}

export class FolderSettingsRenderer extends UserSettingsRenderer implements IPreferencesRenderer<ISetting> {

private unsupportedWorkbenchSettingsRenderer: UnsupportedWorkbenchSettingsRenderer;
private unsupportedSettingsRenderer: UnsupportedSettingsRenderer;

constructor(editor: ICodeEditor, preferencesModel: SettingsEditorModel,
@IPreferencesService preferencesService: IPreferencesService,
Expand All @@ -215,7 +215,7 @@ export class FolderSettingsRenderer extends UserSettingsRenderer implements IPre
@IInstantiationService instantiationService: IInstantiationService
) {
super(editor, preferencesModel, preferencesService, telemetryService, textFileService, configurationService, messageService, instantiationService);
this.unsupportedWorkbenchSettingsRenderer = this._register(instantiationService.createInstance(UnsupportedWorkbenchSettingsRenderer, editor, preferencesModel));
this.unsupportedSettingsRenderer = this._register(instantiationService.createInstance(UnsupportedSettingsRenderer, editor, preferencesModel));
}

protected createHeader(): void {
Expand All @@ -224,7 +224,7 @@ export class FolderSettingsRenderer extends UserSettingsRenderer implements IPre

public render(): void {
super.render();
this.unsupportedWorkbenchSettingsRenderer.render();
this.unsupportedSettingsRenderer.render();
}
}

Expand Down Expand Up @@ -1088,124 +1088,103 @@ class SettingHighlighter extends Disposable {
}
}

class UnsupportedWorkspaceSettingsRenderer extends Disposable {

constructor(private editor: editorCommon.ICommonCodeEditor, private workspaceSettingsEditorModel: SettingsEditorModel,
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
@IMarkerService private markerService: IMarkerService
) {
super();
this._register(this.configurationService.onDidChangeConfiguration(e => this.onDidConfigurationChange(e)));
}

private getMarkerMessage(settingKey: string): string {
switch (settingKey) {
case 'php.validate.executablePath':
return nls.localize('unsupportedPHPExecutablePathSetting', "This setting must be a User Setting. To configure PHP for the workspace, open a PHP file and click on 'PHP Path' in the status bar.");
default:
return nls.localize('unsupportedWorkspaceSetting', "This setting must be a User Setting.");
}
}

public render(): void {
const unsupportedWorkspaceKeys = this.configurationService.getUnsupportedWorkspaceKeys();
if (unsupportedWorkspaceKeys.length) {
const markerData: IMarkerData[] = [];
for (const unsupportedKey of unsupportedWorkspaceKeys) {
const setting = this.workspaceSettingsEditorModel.getPreference(unsupportedKey);
if (setting) {
markerData.push({
severity: Severity.Warning,
startLineNumber: setting.keyRange.startLineNumber,
startColumn: setting.keyRange.startColumn,
endLineNumber: setting.keyRange.endLineNumber,
endColumn: setting.keyRange.endColumn,
message: this.getMarkerMessage(unsupportedKey)
});
}
}
if (markerData.length) {
this.markerService.changeOne('preferencesEditor', this.workspaceSettingsEditorModel.uri, markerData);
} else {
this.markerService.remove('preferencesEditor', [this.workspaceSettingsEditorModel.uri]);
}
}
}

private onDidConfigurationChange(event: IConfigurationChangeEvent): void {
if (event.source === ConfigurationTarget.DEFAULT || event.source === ConfigurationTarget.WORKSPACE || event.source === ConfigurationTarget.WORKSPACE_FOLDER) {
this.render();
}
}

public dispose(): void {
this.markerService.remove('preferencesEditor', [this.workspaceSettingsEditorModel.uri]);
super.dispose();
}
}

class UnsupportedWorkbenchSettingsRenderer extends Disposable {
class UnsupportedSettingsRenderer extends Disposable {

private decorationIds: string[] = [];
private renderingDelayer: Delayer<void> = new Delayer<void>(200);

constructor(private editor: editorCommon.ICommonCodeEditor, private workspaceSettingsEditorModel: SettingsEditorModel,
constructor(
private editor: editorCommon.ICommonCodeEditor,
private settingsEditorModel: SettingsEditorModel,
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
@IMarkerService private markerService: IMarkerService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super();
this._register(this.editor.getModel().onDidChangeContent(() => this.renderingDelayer.trigger(() => this.render())));
}

public render(): void {
const ranges: IRange[] = [];
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).getConfigurationProperties();
for (const settingsGroup of this.workspaceSettingsEditorModel.settingsGroups) {
const ranges: IRange[] = [];
const markerData: IMarkerData[] = [];
for (const settingsGroup of this.settingsEditorModel.settingsGroups) {
for (const section of settingsGroup.sections) {
for (const setting of section.settings) {
if (configurationRegistry[setting.key] && configurationRegistry[setting.key].scope === ConfigurationScope.WINDOW) {
ranges.push({
startLineNumber: setting.keyRange.startLineNumber,
startColumn: setting.keyRange.startColumn - 1,
endLineNumber: setting.valueRange.endLineNumber,
endColumn: setting.valueRange.endColumn
});
if (this.settingsEditorModel.configurationTarget === ConfigurationTarget.WORKSPACE || this.settingsEditorModel.configurationTarget === ConfigurationTarget.WORKSPACE_FOLDER) {
// Show warnings for executable settings
if (configurationRegistry[setting.key] && configurationRegistry[setting.key].isExecutable) {
markerData.push({
severity: Severity.Warning,
startLineNumber: setting.keyRange.startLineNumber,
startColumn: setting.keyRange.startColumn,
endLineNumber: setting.keyRange.endLineNumber,
endColumn: setting.keyRange.endColumn,
message: this.getMarkerMessage(setting.key)
});
}
}
if (this.settingsEditorModel.configurationTarget === ConfigurationTarget.WORKSPACE_FOLDER) {
// Dim and show information for window settings
if (configurationRegistry[setting.key] && configurationRegistry[setting.key].scope === ConfigurationScope.WINDOW) {
ranges.push({
startLineNumber: setting.keyRange.startLineNumber,
startColumn: setting.keyRange.startColumn - 1,
endLineNumber: setting.valueRange.endLineNumber,
endColumn: setting.valueRange.endColumn
});
}
}
}
}
}
if (markerData.length) {
this.markerService.changeOne('preferencesEditor', this.settingsEditorModel.uri, markerData);
} else {
this.markerService.remove('preferencesEditor', [this.settingsEditorModel.uri]);
}
this.editor.changeDecorations(changeAccessor => this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, ranges.map(range => this.createDecoration(range, this.editor.getModel()))));
}

private static _DIM_CONFIGUARATION_ = ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'dim-configuration',
beforeContentClassName: 'unsupportedWorkbenhSettingInfo',
hoverMessage: new MarkdownString().appendText(nls.localize('unsupportedWorkbenchSetting', "This setting cannot be applied now. It will be applied when you open this folder directly."))
});

private static _DIM_CONFIGUARATION_DEV_MODE = ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'dim-configuration',
beforeContentClassName: 'unsupportedWorkbenhSettingInfo',
hoverMessage: new MarkdownString().appendText(nls.localize('unsupportedWorkbenchSettingDevMode', "This setting cannot be applied now. It will be applied if you define it's scope as 'resource' while registering, or when you open this folder directly."))
});

private createDecoration(range: IRange, model: editorCommon.IModel): editorCommon.IModelDeltaDecoration {
return {
range,
options: !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment ? UnsupportedWorkbenchSettingsRenderer._DIM_CONFIGUARATION_DEV_MODE : UnsupportedWorkbenchSettingsRenderer._DIM_CONFIGUARATION_
options: !this.environmentService.isBuilt || this.environmentService.isExtensionDevelopment ? UnsupportedSettingsRenderer._DIM_CONFIGUARATION_DEV_MODE : UnsupportedSettingsRenderer._DIM_CONFIGUARATION_
};
}

private getMarkerMessage(settingKey: string): string {
switch (settingKey) {
case 'php.validate.executablePath':
return nls.localize('unsupportedPHPExecutablePathSetting', "This setting must be a User Setting. To configure PHP for the workspace, open a PHP file and click on 'PHP Path' in the status bar.");
default:
return nls.localize('unsupportedWorkspaceSetting', "This setting must be a User Setting.");
}
}

public dispose(): void {
this.markerService.remove('preferencesEditor', [this.settingsEditorModel.uri]);
if (this.decorationIds) {
this.decorationIds = this.editor.changeDecorations(changeAccessor => {
return changeAccessor.deltaDecorations(this.decorationIds, []);
});
}
super.dispose();
}

private static _DIM_CONFIGUARATION_ = ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'dim-configuration',
beforeContentClassName: 'unsupportedWorkbenhSettingInfo',
hoverMessage: new MarkdownString().appendText(nls.localize('unsupportedWorkbenchSetting', "This setting cannot be applied now. It will be applied when you open this folder directly."))
});

private static _DIM_CONFIGUARATION_DEV_MODE = ModelDecorationOptions.register({
stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
inlineClassName: 'dim-configuration',
beforeContentClassName: 'unsupportedWorkbenhSettingInfo',
hoverMessage: new MarkdownString().appendText(nls.localize('unsupportedWorkbenchSettingDevMode', "This setting cannot be applied now. It will be applied if you define it's scope as 'resource' while registering, or when you open this folder directly."))
});
}

class WorkspaceConfigurationRenderer extends Disposable {
Expand Down
11 changes: 8 additions & 3 deletions src/vs/workbench/parts/preferences/browser/preferencesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { IJSONEditingService } from 'vs/workbench/services/configuration/common/
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IModeService } from 'vs/editor/common/services/modeService';
import { parse } from 'vs/base/common/json';

const emptyEditableSettingsContent = '{\n}';

Expand Down Expand Up @@ -327,9 +328,13 @@ export class PreferencesService extends Disposable implements IPreferencesServic

private createSettingsIfNotExists(target: ConfigurationTarget, resource: URI): TPromise<void> {
if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE && target === ConfigurationTarget.WORKSPACE) {
if (!this.configurationService.keys().workspace.length) {
return this.jsonEditingService.write(resource, { key: 'settings', value: {} }, true).then(null, () => { });
}
return this.fileService.resolveContent(this.contextService.getWorkspace().configuration)
.then(content => {
if (Object.keys(parse(content.value)).indexOf('settings') === -1) {
return this.jsonEditingService.write(resource, { key: 'settings', value: {} }, true).then(null, () => { });
}
return null;
});
}
return this.createIfNotExists(resource, emptyEditableSettingsContent).then(() => { });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IPreferencesService } from 'vs/workbench/parts/preferences/common/prefe
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';



Expand All @@ -28,6 +29,7 @@ class UnsupportedWorkspaceSettingsContribution implements IWorkbenchContribution

constructor(
@ILifecycleService lifecycleService: ILifecycleService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@IWorkspaceConfigurationService private workspaceConfigurationService: IWorkspaceConfigurationService,
@IPreferencesService private preferencesService: IPreferencesService,
@IMessageService private messageService: IMessageService,
Expand All @@ -36,6 +38,7 @@ class UnsupportedWorkspaceSettingsContribution implements IWorkbenchContribution
) {
lifecycleService.onShutdown(this.dispose, this);
this.toDispose.push(this.workspaceConfigurationService.onDidChangeConfiguration(e => this.checkWorkspaceSettings()));
this.toDispose.push(workspaceContextService.onDidChangeWorkspaceFolders(e => this.checkWorkspaceSettings()));
}

getId(): string {
Expand Down
Loading

0 comments on commit 997eb0e

Please sign in to comment.