Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editors - respect user configured editorLargeFileConfirmation #184306

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/vs/editor/common/services/textResourceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Event } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { IPosition } from 'vs/editor/common/core/position';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ConfigurationTarget, IConfigurationValue } from 'vs/platform/configuration/common/configuration';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

export const ITextResourceConfigurationService = createDecorator<ITextResourceConfigurationService>('textResourceConfigurationService');
Expand Down Expand Up @@ -50,6 +50,16 @@ export interface ITextResourceConfigurationService {
getValue<T>(resource: URI | undefined, section?: string): T;
getValue<T>(resource: URI | undefined, position?: IPosition, section?: string): T;

/**
* Inspects the values of the section for the given resource by applying language overrides.
*
* @param resource - Resource for which the configuration has to be fetched.
* @param position - Position in the resource for which configuration has to be fetched.
* @param section - Section of the configuration.
*
*/
inspect<T>(resource: URI | undefined, position: IPosition | null, section: string): IConfigurationValue<Readonly<T>>;

/**
* Update the configuration value for the given resource at the effective location.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export class TextResourceConfigurationService extends Disposable implements ITex
return this.configurationService.getValue<T>(section, { resource, overrideIdentifier: language });
}

inspect<T>(resource: URI | undefined, position: IPosition | null, section: string): IConfigurationValue<Readonly<T>> {
const language = resource ? this.getLanguage(resource, position) : undefined;
return this.configurationService.inspect<T>(section, { resource, overrideIdentifier: language });
}

private getLanguage(resource: URI, position: IPosition | null): string | null {
const model = this.modelService.getModel(resource);
if (model) {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/editor/standalone/browser/standaloneServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@ class StandaloneResourceConfigurationService implements ITextResourceConfigurati
});
}

inspect<T>(resource: URI | undefined, position: IPosition | null, section: string): IConfigurationValue<Readonly<T>> {
const language = resource ? this.getLanguage(resource, position) : undefined;
return this.configurationService.inspect<T>(section, { resource, overrideIdentifier: language });
}

private getLanguage(resource: URI, position: IPosition | null): string | null {
const model = this.modelService.getModel(resource);
if (model) {
Expand Down
9 changes: 9 additions & 0 deletions src/vs/platform/configuration/common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export interface IConfigurationValue<T> {
readonly overrideIdentifiers?: string[];
}

export function isConfigured<T>(configValue: IConfigurationValue<T>): configValue is IConfigurationValue<T> & { value: T } {
return configValue.applicationValue !== undefined ||
configValue.userValue !== undefined ||
configValue.userLocalValue !== undefined ||
configValue.userRemoteValue !== undefined ||
configValue.workspaceValue !== undefined ||
configValue.workspaceFolderValue !== undefined;
}

export interface IConfigurationUpdateOptions {
/**
* If `true`, do not notifies the error to user by showing the message box. Default is `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ConfigurationTarget, isConfigured } from 'vs/platform/configuration/common/configuration';
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationService } from 'vs/platform/configuration/common/configurationService';
import { IFileService } from 'vs/platform/files/common/files';
Expand Down Expand Up @@ -200,11 +200,13 @@ suite('ConfigurationService', () => {
assert.strictEqual(res.value, undefined);
assert.strictEqual(res.defaultValue, undefined);
assert.strictEqual(res.userValue, undefined);
assert.strictEqual(isConfigured(res), false);

res = testObject.inspect('lookup.service.testSetting');
assert.strictEqual(res.defaultValue, 'isSet');
assert.strictEqual(res.value, 'isSet');
assert.strictEqual(res.userValue, undefined);
assert.strictEqual(isConfigured(res), false);

await fileService.writeFile(settingsResource, VSBuffer.fromString('{ "lookup.service.testSetting": "bar" }'));

Expand All @@ -213,6 +215,7 @@ suite('ConfigurationService', () => {
assert.strictEqual(res.defaultValue, 'isSet');
assert.strictEqual(res.userValue, 'bar');
assert.strictEqual(res.value, 'bar');
assert.strictEqual(isConfigured(res), true);

}));

Expand Down
14 changes: 10 additions & 4 deletions src/vs/workbench/contrib/files/browser/editors/fileEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Schemas } from 'vs/base/common/network';
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfiguration';
import { isConfigured } from 'vs/platform/configuration/common/configuration';

const enum ForceOpenAs {
None,
Expand Down Expand Up @@ -372,16 +373,21 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
return options.limits; // respect passed in limits if any
}

// We want to determine the large file configuration based on the best defaults
// for the resource but also respecting user settings. We only apply user settings
// if explicitly configured by the user. Otherwise we pick the best limit for the
// resource scheme.

const defaultSizeLimit = getLargeFileConfirmationLimit(this.resource);
let configuredSizeLimit: number | undefined = undefined;

const configuredSizeLimitMb = this.textResourceConfigurationService.getValue<number>(this.resource, 'workbench.editorLargeFileConfirmation');
if (typeof configuredSizeLimitMb === 'number') {
configuredSizeLimit = configuredSizeLimitMb * ByteSize.MB; // normalize to MB
const configuredSizeLimitMb = this.textResourceConfigurationService.inspect<number>(this.resource, null, 'workbench.editorLargeFileConfirmation');
if (isConfigured(configuredSizeLimitMb)) {
configuredSizeLimit = configuredSizeLimitMb.value * ByteSize.MB; // normalize to MB
}

return {
size: Math.max(defaultSizeLimit, configuredSizeLimit ?? defaultSizeLimit) // pick the highest limit
size: configuredSizeLimit ?? defaultSizeLimit
};
}

Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorI
import { EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor, IEditorGroupTitleHeight } from 'vs/workbench/browser/parts/editor/editor';
import { Event, Emitter } from 'vs/base/common/event';
import { IResolvedWorkingCopyBackup, IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IConfigurationService, ConfigurationTarget, IConfigurationValue } from 'vs/platform/configuration/common/configuration';
import { IWorkbenchLayoutService, PanelAlignment, Parts, Position as PartPosition } from 'vs/workbench/services/layout/browser/layoutService';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
Expand Down Expand Up @@ -1335,6 +1335,10 @@ export class TestTextResourceConfigurationService implements ITextResourceConfig
return this.configurationService.getValue(section, { resource });
}

inspect<T>(resource: URI | undefined, position: IPosition | null, section: string): IConfigurationValue<Readonly<T>> {
return this.configurationService.inspect<T>(section, { resource });
}

updateValue(resource: URI, key: string, value: any, configurationTarget?: ConfigurationTarget): Promise<void> {
return this.configurationService.updateValue(key, value);
}
Expand Down