Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/test/browser/config/editorConfiguration.test.ts
5240 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
8
import { IEnvConfiguration } from '../../../browser/config/editorConfiguration.js';
9
import { migrateOptions } from '../../../browser/config/migrateOptions.js';
10
import { ConfigurationChangedEvent, EditorOption, IEditorHoverOptions, IQuickSuggestionsOptions } from '../../../common/config/editorOptions.js';
11
import { EditorZoom } from '../../../common/config/editorZoom.js';
12
import { TestConfiguration } from './testConfiguration.js';
13
import { AccessibilitySupport } from '../../../../platform/accessibility/common/accessibility.js';
14
15
suite('Common Editor Config', () => {
16
17
ensureNoDisposablesAreLeakedInTestSuite();
18
19
test('Zoom Level', () => {
20
21
//Zoom levels are defined to go between -5, 20 inclusive
22
const zoom = EditorZoom;
23
24
zoom.setZoomLevel(0);
25
assert.strictEqual(zoom.getZoomLevel(), 0);
26
27
zoom.setZoomLevel(-0);
28
assert.strictEqual(zoom.getZoomLevel(), 0);
29
30
zoom.setZoomLevel(5);
31
assert.strictEqual(zoom.getZoomLevel(), 5);
32
33
zoom.setZoomLevel(-1);
34
assert.strictEqual(zoom.getZoomLevel(), -1);
35
36
zoom.setZoomLevel(9);
37
assert.strictEqual(zoom.getZoomLevel(), 9);
38
39
zoom.setZoomLevel(-9);
40
assert.strictEqual(zoom.getZoomLevel(), -5);
41
42
zoom.setZoomLevel(20);
43
assert.strictEqual(zoom.getZoomLevel(), 20);
44
45
zoom.setZoomLevel(-10);
46
assert.strictEqual(zoom.getZoomLevel(), -5);
47
48
zoom.setZoomLevel(9.1);
49
assert.strictEqual(zoom.getZoomLevel(), 9.1);
50
51
zoom.setZoomLevel(-9.1);
52
assert.strictEqual(zoom.getZoomLevel(), -5);
53
54
zoom.setZoomLevel(Infinity);
55
assert.strictEqual(zoom.getZoomLevel(), 20);
56
57
zoom.setZoomLevel(Number.NEGATIVE_INFINITY);
58
assert.strictEqual(zoom.getZoomLevel(), -5);
59
});
60
61
class TestWrappingConfiguration extends TestConfiguration {
62
protected override _readEnvConfiguration(): IEnvConfiguration {
63
return {
64
extraEditorClassName: '',
65
outerWidth: 1000,
66
outerHeight: 100,
67
emptySelectionClipboard: true,
68
pixelRatio: 1,
69
accessibilitySupport: AccessibilitySupport.Unknown,
70
editContextSupported: true,
71
};
72
}
73
}
74
75
function assertWrapping(config: TestConfiguration, isViewportWrapping: boolean, wrappingColumn: number): void {
76
const options = config.options;
77
const wrappingInfo = options.get(EditorOption.wrappingInfo);
78
assert.strictEqual(wrappingInfo.isViewportWrapping, isViewportWrapping);
79
assert.strictEqual(wrappingInfo.wrappingColumn, wrappingColumn);
80
}
81
82
test('wordWrap default', () => {
83
const config = new TestWrappingConfiguration({});
84
assertWrapping(config, false, -1);
85
config.dispose();
86
});
87
88
test('wordWrap compat false', () => {
89
const config = new TestWrappingConfiguration({
90
// eslint-disable-next-line local/code-no-any-casts
91
wordWrap: <any>false
92
});
93
assertWrapping(config, false, -1);
94
config.dispose();
95
});
96
97
test('wordWrap compat true', () => {
98
const config = new TestWrappingConfiguration({
99
// eslint-disable-next-line local/code-no-any-casts
100
wordWrap: <any>true
101
});
102
assertWrapping(config, true, 80);
103
config.dispose();
104
});
105
106
test('wordWrap on', () => {
107
const config = new TestWrappingConfiguration({
108
wordWrap: 'on'
109
});
110
assertWrapping(config, true, 80);
111
config.dispose();
112
});
113
114
test('wordWrap on without minimap', () => {
115
const config = new TestWrappingConfiguration({
116
wordWrap: 'on',
117
minimap: {
118
enabled: false
119
}
120
});
121
assertWrapping(config, true, 88);
122
config.dispose();
123
});
124
125
test('wordWrap on does not use wordWrapColumn', () => {
126
const config = new TestWrappingConfiguration({
127
wordWrap: 'on',
128
wordWrapColumn: 10
129
});
130
assertWrapping(config, true, 80);
131
config.dispose();
132
});
133
134
test('wordWrap off', () => {
135
const config = new TestWrappingConfiguration({
136
wordWrap: 'off'
137
});
138
assertWrapping(config, false, -1);
139
config.dispose();
140
});
141
142
test('wordWrap off does not use wordWrapColumn', () => {
143
const config = new TestWrappingConfiguration({
144
wordWrap: 'off',
145
wordWrapColumn: 10
146
});
147
assertWrapping(config, false, -1);
148
config.dispose();
149
});
150
151
test('wordWrap wordWrapColumn uses default wordWrapColumn', () => {
152
const config = new TestWrappingConfiguration({
153
wordWrap: 'wordWrapColumn'
154
});
155
assertWrapping(config, false, 80);
156
config.dispose();
157
});
158
159
test('wordWrap wordWrapColumn uses wordWrapColumn', () => {
160
const config = new TestWrappingConfiguration({
161
wordWrap: 'wordWrapColumn',
162
wordWrapColumn: 100
163
});
164
assertWrapping(config, false, 100);
165
config.dispose();
166
});
167
168
test('wordWrap wordWrapColumn validates wordWrapColumn', () => {
169
const config = new TestWrappingConfiguration({
170
wordWrap: 'wordWrapColumn',
171
wordWrapColumn: -1
172
});
173
assertWrapping(config, false, 1);
174
config.dispose();
175
});
176
177
test('wordWrap bounded uses default wordWrapColumn', () => {
178
const config = new TestWrappingConfiguration({
179
wordWrap: 'bounded'
180
});
181
assertWrapping(config, true, 80);
182
config.dispose();
183
});
184
185
test('wordWrap bounded uses wordWrapColumn', () => {
186
const config = new TestWrappingConfiguration({
187
wordWrap: 'bounded',
188
wordWrapColumn: 40
189
});
190
assertWrapping(config, true, 40);
191
config.dispose();
192
});
193
194
test('wordWrap bounded validates wordWrapColumn', () => {
195
const config = new TestWrappingConfiguration({
196
wordWrap: 'bounded',
197
wordWrapColumn: -1
198
});
199
assertWrapping(config, true, 1);
200
config.dispose();
201
});
202
203
test('issue #53152: Cannot assign to read only property \'enabled\' of object', () => {
204
const hoverOptions: IEditorHoverOptions = {};
205
Object.defineProperty(hoverOptions, 'enabled', {
206
writable: false,
207
value: 'on'
208
});
209
const config = new TestConfiguration({ hover: hoverOptions });
210
211
assert.strictEqual(config.options.get(EditorOption.hover).enabled, 'on');
212
config.updateOptions({ hover: { enabled: 'off' } });
213
assert.strictEqual(config.options.get(EditorOption.hover).enabled, 'off');
214
215
config.dispose();
216
});
217
218
test('does not emit event when nothing changes', () => {
219
const config = new TestConfiguration({ glyphMargin: true, roundedSelection: false });
220
let event: ConfigurationChangedEvent | null = null;
221
const disposable = config.onDidChange(e => event = e);
222
assert.strictEqual(config.options.get(EditorOption.glyphMargin), true);
223
224
config.updateOptions({ glyphMargin: true });
225
config.updateOptions({ roundedSelection: false });
226
assert.strictEqual(event, null);
227
config.dispose();
228
disposable.dispose();
229
});
230
231
test('issue #94931: Unable to open source file', () => {
232
const config = new TestConfiguration({ quickSuggestions: null! });
233
const actual = <Readonly<Required<IQuickSuggestionsOptions>>>config.options.get(EditorOption.quickSuggestions);
234
assert.deepStrictEqual(actual, {
235
other: 'on',
236
comments: 'off',
237
strings: 'off'
238
});
239
config.dispose();
240
});
241
242
test('issue #102920: Can\'t snap or split view with JSON files', () => {
243
const config = new TestConfiguration({ quickSuggestions: null! });
244
config.updateOptions({ quickSuggestions: { strings: true } });
245
const actual = <Readonly<Required<IQuickSuggestionsOptions>>>config.options.get(EditorOption.quickSuggestions);
246
assert.deepStrictEqual(actual, {
247
other: 'on',
248
comments: 'off',
249
strings: 'on'
250
});
251
config.dispose();
252
});
253
254
test('issue #151926: Untyped editor options apply', () => {
255
const config = new TestConfiguration({});
256
config.updateOptions({ unicodeHighlight: { allowedCharacters: { 'x': true } } });
257
const actual = config.options.get(EditorOption.unicodeHighlighting);
258
assert.deepStrictEqual(actual,
259
{
260
nonBasicASCII: 'inUntrustedWorkspace',
261
invisibleCharacters: true,
262
ambiguousCharacters: true,
263
includeComments: 'inUntrustedWorkspace',
264
includeStrings: 'inUntrustedWorkspace',
265
allowedCharacters: { 'x': true },
266
allowedLocales: { '_os': true, '_vscode': true }
267
}
268
);
269
config.dispose();
270
});
271
});
272
273
suite('migrateOptions', () => {
274
275
ensureNoDisposablesAreLeakedInTestSuite();
276
277
function migrate(options: any): any {
278
migrateOptions(options);
279
return options;
280
}
281
282
test('wordWrap', () => {
283
assert.deepStrictEqual(migrate({ wordWrap: true }), { wordWrap: 'on' });
284
assert.deepStrictEqual(migrate({ wordWrap: false }), { wordWrap: 'off' });
285
});
286
test('lineNumbers', () => {
287
assert.deepStrictEqual(migrate({ lineNumbers: true }), { lineNumbers: 'on' });
288
assert.deepStrictEqual(migrate({ lineNumbers: false }), { lineNumbers: 'off' });
289
});
290
test('autoClosingBrackets', () => {
291
assert.deepStrictEqual(migrate({ autoClosingBrackets: false }), { autoClosingBrackets: 'never', autoClosingQuotes: 'never', autoSurround: 'never' });
292
});
293
test('cursorBlinking', () => {
294
assert.deepStrictEqual(migrate({ cursorBlinking: 'visible' }), { cursorBlinking: 'solid' });
295
});
296
test('renderWhitespace', () => {
297
assert.deepStrictEqual(migrate({ renderWhitespace: true }), { renderWhitespace: 'boundary' });
298
assert.deepStrictEqual(migrate({ renderWhitespace: false }), { renderWhitespace: 'none' });
299
});
300
test('renderLineHighlight', () => {
301
assert.deepStrictEqual(migrate({ renderLineHighlight: true }), { renderLineHighlight: 'line' });
302
assert.deepStrictEqual(migrate({ renderLineHighlight: false }), { renderLineHighlight: 'none' });
303
});
304
test('acceptSuggestionOnEnter', () => {
305
assert.deepStrictEqual(migrate({ acceptSuggestionOnEnter: true }), { acceptSuggestionOnEnter: 'on' });
306
assert.deepStrictEqual(migrate({ acceptSuggestionOnEnter: false }), { acceptSuggestionOnEnter: 'off' });
307
});
308
test('tabCompletion', () => {
309
assert.deepStrictEqual(migrate({ tabCompletion: true }), { tabCompletion: 'onlySnippets' });
310
assert.deepStrictEqual(migrate({ tabCompletion: false }), { tabCompletion: 'off' });
311
});
312
test('suggest.filteredTypes', () => {
313
assert.deepStrictEqual(
314
migrate({
315
suggest: {
316
filteredTypes: {
317
method: false,
318
function: false,
319
constructor: false,
320
deprecated: false,
321
field: false,
322
variable: false,
323
class: false,
324
struct: false,
325
interface: false,
326
module: false,
327
property: false,
328
event: false,
329
operator: false,
330
unit: false,
331
value: false,
332
constant: false,
333
enum: false,
334
enumMember: false,
335
keyword: false,
336
text: false,
337
color: false,
338
file: false,
339
reference: false,
340
folder: false,
341
typeParameter: false,
342
snippet: false,
343
}
344
}
345
}), {
346
suggest: {
347
filteredTypes: undefined,
348
showMethods: false,
349
showFunctions: false,
350
showConstructors: false,
351
showDeprecated: false,
352
showFields: false,
353
showVariables: false,
354
showClasses: false,
355
showStructs: false,
356
showInterfaces: false,
357
showModules: false,
358
showProperties: false,
359
showEvents: false,
360
showOperators: false,
361
showUnits: false,
362
showValues: false,
363
showConstants: false,
364
showEnums: false,
365
showEnumMembers: false,
366
showKeywords: false,
367
showWords: false,
368
showColors: false,
369
showFiles: false,
370
showReferences: false,
371
showFolders: false,
372
showTypeParameters: false,
373
showSnippets: false,
374
}
375
});
376
});
377
test('quickSuggestions', () => {
378
assert.deepStrictEqual(migrate({ quickSuggestions: true }), { quickSuggestions: { comments: 'on', strings: 'on', other: 'on' } });
379
assert.deepStrictEqual(migrate({ quickSuggestions: false }), { quickSuggestions: { comments: 'off', strings: 'off', other: 'off' } });
380
assert.deepStrictEqual(migrate({ quickSuggestions: { comments: 'on', strings: 'off' } }), { quickSuggestions: { comments: 'on', strings: 'off' } });
381
});
382
test('hover', () => {
383
assert.deepStrictEqual(migrate({ hover: true }), { hover: { enabled: 'on' } });
384
assert.deepStrictEqual(migrate({ hover: false }), { hover: { enabled: 'off' } });
385
});
386
test('parameterHints', () => {
387
assert.deepStrictEqual(migrate({ parameterHints: true }), { parameterHints: { enabled: true } });
388
assert.deepStrictEqual(migrate({ parameterHints: false }), { parameterHints: { enabled: false } });
389
});
390
test('autoIndent', () => {
391
assert.deepStrictEqual(migrate({ autoIndent: true }), { autoIndent: 'full' });
392
assert.deepStrictEqual(migrate({ autoIndent: false }), { autoIndent: 'advanced' });
393
});
394
test('matchBrackets', () => {
395
assert.deepStrictEqual(migrate({ matchBrackets: true }), { matchBrackets: 'always' });
396
assert.deepStrictEqual(migrate({ matchBrackets: false }), { matchBrackets: 'never' });
397
});
398
test('renderIndentGuides, highlightActiveIndentGuide', () => {
399
assert.deepStrictEqual(migrate({ renderIndentGuides: true }), { renderIndentGuides: undefined, guides: { indentation: true } });
400
assert.deepStrictEqual(migrate({ renderIndentGuides: false }), { renderIndentGuides: undefined, guides: { indentation: false } });
401
assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: true }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: true } });
402
assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: false }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: false } });
403
});
404
405
test('migration does not overwrite new setting', () => {
406
assert.deepStrictEqual(migrate({ renderIndentGuides: true, guides: { indentation: false } }), { renderIndentGuides: undefined, guides: { indentation: false } });
407
assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: true, guides: { highlightActiveIndentation: false } }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: false } });
408
});
409
});
410
411