Path: blob/main/src/vs/editor/test/browser/config/editorConfiguration.test.ts
5240 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';7import { IEnvConfiguration } from '../../../browser/config/editorConfiguration.js';8import { migrateOptions } from '../../../browser/config/migrateOptions.js';9import { ConfigurationChangedEvent, EditorOption, IEditorHoverOptions, IQuickSuggestionsOptions } from '../../../common/config/editorOptions.js';10import { EditorZoom } from '../../../common/config/editorZoom.js';11import { TestConfiguration } from './testConfiguration.js';12import { AccessibilitySupport } from '../../../../platform/accessibility/common/accessibility.js';1314suite('Common Editor Config', () => {1516ensureNoDisposablesAreLeakedInTestSuite();1718test('Zoom Level', () => {1920//Zoom levels are defined to go between -5, 20 inclusive21const zoom = EditorZoom;2223zoom.setZoomLevel(0);24assert.strictEqual(zoom.getZoomLevel(), 0);2526zoom.setZoomLevel(-0);27assert.strictEqual(zoom.getZoomLevel(), 0);2829zoom.setZoomLevel(5);30assert.strictEqual(zoom.getZoomLevel(), 5);3132zoom.setZoomLevel(-1);33assert.strictEqual(zoom.getZoomLevel(), -1);3435zoom.setZoomLevel(9);36assert.strictEqual(zoom.getZoomLevel(), 9);3738zoom.setZoomLevel(-9);39assert.strictEqual(zoom.getZoomLevel(), -5);4041zoom.setZoomLevel(20);42assert.strictEqual(zoom.getZoomLevel(), 20);4344zoom.setZoomLevel(-10);45assert.strictEqual(zoom.getZoomLevel(), -5);4647zoom.setZoomLevel(9.1);48assert.strictEqual(zoom.getZoomLevel(), 9.1);4950zoom.setZoomLevel(-9.1);51assert.strictEqual(zoom.getZoomLevel(), -5);5253zoom.setZoomLevel(Infinity);54assert.strictEqual(zoom.getZoomLevel(), 20);5556zoom.setZoomLevel(Number.NEGATIVE_INFINITY);57assert.strictEqual(zoom.getZoomLevel(), -5);58});5960class TestWrappingConfiguration extends TestConfiguration {61protected override _readEnvConfiguration(): IEnvConfiguration {62return {63extraEditorClassName: '',64outerWidth: 1000,65outerHeight: 100,66emptySelectionClipboard: true,67pixelRatio: 1,68accessibilitySupport: AccessibilitySupport.Unknown,69editContextSupported: true,70};71}72}7374function assertWrapping(config: TestConfiguration, isViewportWrapping: boolean, wrappingColumn: number): void {75const options = config.options;76const wrappingInfo = options.get(EditorOption.wrappingInfo);77assert.strictEqual(wrappingInfo.isViewportWrapping, isViewportWrapping);78assert.strictEqual(wrappingInfo.wrappingColumn, wrappingColumn);79}8081test('wordWrap default', () => {82const config = new TestWrappingConfiguration({});83assertWrapping(config, false, -1);84config.dispose();85});8687test('wordWrap compat false', () => {88const config = new TestWrappingConfiguration({89// eslint-disable-next-line local/code-no-any-casts90wordWrap: <any>false91});92assertWrapping(config, false, -1);93config.dispose();94});9596test('wordWrap compat true', () => {97const config = new TestWrappingConfiguration({98// eslint-disable-next-line local/code-no-any-casts99wordWrap: <any>true100});101assertWrapping(config, true, 80);102config.dispose();103});104105test('wordWrap on', () => {106const config = new TestWrappingConfiguration({107wordWrap: 'on'108});109assertWrapping(config, true, 80);110config.dispose();111});112113test('wordWrap on without minimap', () => {114const config = new TestWrappingConfiguration({115wordWrap: 'on',116minimap: {117enabled: false118}119});120assertWrapping(config, true, 88);121config.dispose();122});123124test('wordWrap on does not use wordWrapColumn', () => {125const config = new TestWrappingConfiguration({126wordWrap: 'on',127wordWrapColumn: 10128});129assertWrapping(config, true, 80);130config.dispose();131});132133test('wordWrap off', () => {134const config = new TestWrappingConfiguration({135wordWrap: 'off'136});137assertWrapping(config, false, -1);138config.dispose();139});140141test('wordWrap off does not use wordWrapColumn', () => {142const config = new TestWrappingConfiguration({143wordWrap: 'off',144wordWrapColumn: 10145});146assertWrapping(config, false, -1);147config.dispose();148});149150test('wordWrap wordWrapColumn uses default wordWrapColumn', () => {151const config = new TestWrappingConfiguration({152wordWrap: 'wordWrapColumn'153});154assertWrapping(config, false, 80);155config.dispose();156});157158test('wordWrap wordWrapColumn uses wordWrapColumn', () => {159const config = new TestWrappingConfiguration({160wordWrap: 'wordWrapColumn',161wordWrapColumn: 100162});163assertWrapping(config, false, 100);164config.dispose();165});166167test('wordWrap wordWrapColumn validates wordWrapColumn', () => {168const config = new TestWrappingConfiguration({169wordWrap: 'wordWrapColumn',170wordWrapColumn: -1171});172assertWrapping(config, false, 1);173config.dispose();174});175176test('wordWrap bounded uses default wordWrapColumn', () => {177const config = new TestWrappingConfiguration({178wordWrap: 'bounded'179});180assertWrapping(config, true, 80);181config.dispose();182});183184test('wordWrap bounded uses wordWrapColumn', () => {185const config = new TestWrappingConfiguration({186wordWrap: 'bounded',187wordWrapColumn: 40188});189assertWrapping(config, true, 40);190config.dispose();191});192193test('wordWrap bounded validates wordWrapColumn', () => {194const config = new TestWrappingConfiguration({195wordWrap: 'bounded',196wordWrapColumn: -1197});198assertWrapping(config, true, 1);199config.dispose();200});201202test('issue #53152: Cannot assign to read only property \'enabled\' of object', () => {203const hoverOptions: IEditorHoverOptions = {};204Object.defineProperty(hoverOptions, 'enabled', {205writable: false,206value: 'on'207});208const config = new TestConfiguration({ hover: hoverOptions });209210assert.strictEqual(config.options.get(EditorOption.hover).enabled, 'on');211config.updateOptions({ hover: { enabled: 'off' } });212assert.strictEqual(config.options.get(EditorOption.hover).enabled, 'off');213214config.dispose();215});216217test('does not emit event when nothing changes', () => {218const config = new TestConfiguration({ glyphMargin: true, roundedSelection: false });219let event: ConfigurationChangedEvent | null = null;220const disposable = config.onDidChange(e => event = e);221assert.strictEqual(config.options.get(EditorOption.glyphMargin), true);222223config.updateOptions({ glyphMargin: true });224config.updateOptions({ roundedSelection: false });225assert.strictEqual(event, null);226config.dispose();227disposable.dispose();228});229230test('issue #94931: Unable to open source file', () => {231const config = new TestConfiguration({ quickSuggestions: null! });232const actual = <Readonly<Required<IQuickSuggestionsOptions>>>config.options.get(EditorOption.quickSuggestions);233assert.deepStrictEqual(actual, {234other: 'on',235comments: 'off',236strings: 'off'237});238config.dispose();239});240241test('issue #102920: Can\'t snap or split view with JSON files', () => {242const config = new TestConfiguration({ quickSuggestions: null! });243config.updateOptions({ quickSuggestions: { strings: true } });244const actual = <Readonly<Required<IQuickSuggestionsOptions>>>config.options.get(EditorOption.quickSuggestions);245assert.deepStrictEqual(actual, {246other: 'on',247comments: 'off',248strings: 'on'249});250config.dispose();251});252253test('issue #151926: Untyped editor options apply', () => {254const config = new TestConfiguration({});255config.updateOptions({ unicodeHighlight: { allowedCharacters: { 'x': true } } });256const actual = config.options.get(EditorOption.unicodeHighlighting);257assert.deepStrictEqual(actual,258{259nonBasicASCII: 'inUntrustedWorkspace',260invisibleCharacters: true,261ambiguousCharacters: true,262includeComments: 'inUntrustedWorkspace',263includeStrings: 'inUntrustedWorkspace',264allowedCharacters: { 'x': true },265allowedLocales: { '_os': true, '_vscode': true }266}267);268config.dispose();269});270});271272suite('migrateOptions', () => {273274ensureNoDisposablesAreLeakedInTestSuite();275276function migrate(options: any): any {277migrateOptions(options);278return options;279}280281test('wordWrap', () => {282assert.deepStrictEqual(migrate({ wordWrap: true }), { wordWrap: 'on' });283assert.deepStrictEqual(migrate({ wordWrap: false }), { wordWrap: 'off' });284});285test('lineNumbers', () => {286assert.deepStrictEqual(migrate({ lineNumbers: true }), { lineNumbers: 'on' });287assert.deepStrictEqual(migrate({ lineNumbers: false }), { lineNumbers: 'off' });288});289test('autoClosingBrackets', () => {290assert.deepStrictEqual(migrate({ autoClosingBrackets: false }), { autoClosingBrackets: 'never', autoClosingQuotes: 'never', autoSurround: 'never' });291});292test('cursorBlinking', () => {293assert.deepStrictEqual(migrate({ cursorBlinking: 'visible' }), { cursorBlinking: 'solid' });294});295test('renderWhitespace', () => {296assert.deepStrictEqual(migrate({ renderWhitespace: true }), { renderWhitespace: 'boundary' });297assert.deepStrictEqual(migrate({ renderWhitespace: false }), { renderWhitespace: 'none' });298});299test('renderLineHighlight', () => {300assert.deepStrictEqual(migrate({ renderLineHighlight: true }), { renderLineHighlight: 'line' });301assert.deepStrictEqual(migrate({ renderLineHighlight: false }), { renderLineHighlight: 'none' });302});303test('acceptSuggestionOnEnter', () => {304assert.deepStrictEqual(migrate({ acceptSuggestionOnEnter: true }), { acceptSuggestionOnEnter: 'on' });305assert.deepStrictEqual(migrate({ acceptSuggestionOnEnter: false }), { acceptSuggestionOnEnter: 'off' });306});307test('tabCompletion', () => {308assert.deepStrictEqual(migrate({ tabCompletion: true }), { tabCompletion: 'onlySnippets' });309assert.deepStrictEqual(migrate({ tabCompletion: false }), { tabCompletion: 'off' });310});311test('suggest.filteredTypes', () => {312assert.deepStrictEqual(313migrate({314suggest: {315filteredTypes: {316method: false,317function: false,318constructor: false,319deprecated: false,320field: false,321variable: false,322class: false,323struct: false,324interface: false,325module: false,326property: false,327event: false,328operator: false,329unit: false,330value: false,331constant: false,332enum: false,333enumMember: false,334keyword: false,335text: false,336color: false,337file: false,338reference: false,339folder: false,340typeParameter: false,341snippet: false,342}343}344}), {345suggest: {346filteredTypes: undefined,347showMethods: false,348showFunctions: false,349showConstructors: false,350showDeprecated: false,351showFields: false,352showVariables: false,353showClasses: false,354showStructs: false,355showInterfaces: false,356showModules: false,357showProperties: false,358showEvents: false,359showOperators: false,360showUnits: false,361showValues: false,362showConstants: false,363showEnums: false,364showEnumMembers: false,365showKeywords: false,366showWords: false,367showColors: false,368showFiles: false,369showReferences: false,370showFolders: false,371showTypeParameters: false,372showSnippets: false,373}374});375});376test('quickSuggestions', () => {377assert.deepStrictEqual(migrate({ quickSuggestions: true }), { quickSuggestions: { comments: 'on', strings: 'on', other: 'on' } });378assert.deepStrictEqual(migrate({ quickSuggestions: false }), { quickSuggestions: { comments: 'off', strings: 'off', other: 'off' } });379assert.deepStrictEqual(migrate({ quickSuggestions: { comments: 'on', strings: 'off' } }), { quickSuggestions: { comments: 'on', strings: 'off' } });380});381test('hover', () => {382assert.deepStrictEqual(migrate({ hover: true }), { hover: { enabled: 'on' } });383assert.deepStrictEqual(migrate({ hover: false }), { hover: { enabled: 'off' } });384});385test('parameterHints', () => {386assert.deepStrictEqual(migrate({ parameterHints: true }), { parameterHints: { enabled: true } });387assert.deepStrictEqual(migrate({ parameterHints: false }), { parameterHints: { enabled: false } });388});389test('autoIndent', () => {390assert.deepStrictEqual(migrate({ autoIndent: true }), { autoIndent: 'full' });391assert.deepStrictEqual(migrate({ autoIndent: false }), { autoIndent: 'advanced' });392});393test('matchBrackets', () => {394assert.deepStrictEqual(migrate({ matchBrackets: true }), { matchBrackets: 'always' });395assert.deepStrictEqual(migrate({ matchBrackets: false }), { matchBrackets: 'never' });396});397test('renderIndentGuides, highlightActiveIndentGuide', () => {398assert.deepStrictEqual(migrate({ renderIndentGuides: true }), { renderIndentGuides: undefined, guides: { indentation: true } });399assert.deepStrictEqual(migrate({ renderIndentGuides: false }), { renderIndentGuides: undefined, guides: { indentation: false } });400assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: true }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: true } });401assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: false }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: false } });402});403404test('migration does not overwrite new setting', () => {405assert.deepStrictEqual(migrate({ renderIndentGuides: true, guides: { indentation: false } }), { renderIndentGuides: undefined, guides: { indentation: false } });406assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: true, guides: { highlightActiveIndentation: false } }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: false } });407});408});409410411