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
3296 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
wordWrap: <any>false
91
});
92
assertWrapping(config, false, -1);
93
config.dispose();
94
});
95
96
test('wordWrap compat true', () => {
97
const config = new TestWrappingConfiguration({
98
wordWrap: <any>true
99
});
100
assertWrapping(config, true, 80);
101
config.dispose();
102
});
103
104
test('wordWrap on', () => {
105
const config = new TestWrappingConfiguration({
106
wordWrap: 'on'
107
});
108
assertWrapping(config, true, 80);
109
config.dispose();
110
});
111
112
test('wordWrap on without minimap', () => {
113
const config = new TestWrappingConfiguration({
114
wordWrap: 'on',
115
minimap: {
116
enabled: false
117
}
118
});
119
assertWrapping(config, true, 88);
120
config.dispose();
121
});
122
123
test('wordWrap on does not use wordWrapColumn', () => {
124
const config = new TestWrappingConfiguration({
125
wordWrap: 'on',
126
wordWrapColumn: 10
127
});
128
assertWrapping(config, true, 80);
129
config.dispose();
130
});
131
132
test('wordWrap off', () => {
133
const config = new TestWrappingConfiguration({
134
wordWrap: 'off'
135
});
136
assertWrapping(config, false, -1);
137
config.dispose();
138
});
139
140
test('wordWrap off does not use wordWrapColumn', () => {
141
const config = new TestWrappingConfiguration({
142
wordWrap: 'off',
143
wordWrapColumn: 10
144
});
145
assertWrapping(config, false, -1);
146
config.dispose();
147
});
148
149
test('wordWrap wordWrapColumn uses default wordWrapColumn', () => {
150
const config = new TestWrappingConfiguration({
151
wordWrap: 'wordWrapColumn'
152
});
153
assertWrapping(config, false, 80);
154
config.dispose();
155
});
156
157
test('wordWrap wordWrapColumn uses wordWrapColumn', () => {
158
const config = new TestWrappingConfiguration({
159
wordWrap: 'wordWrapColumn',
160
wordWrapColumn: 100
161
});
162
assertWrapping(config, false, 100);
163
config.dispose();
164
});
165
166
test('wordWrap wordWrapColumn validates wordWrapColumn', () => {
167
const config = new TestWrappingConfiguration({
168
wordWrap: 'wordWrapColumn',
169
wordWrapColumn: -1
170
});
171
assertWrapping(config, false, 1);
172
config.dispose();
173
});
174
175
test('wordWrap bounded uses default wordWrapColumn', () => {
176
const config = new TestWrappingConfiguration({
177
wordWrap: 'bounded'
178
});
179
assertWrapping(config, true, 80);
180
config.dispose();
181
});
182
183
test('wordWrap bounded uses wordWrapColumn', () => {
184
const config = new TestWrappingConfiguration({
185
wordWrap: 'bounded',
186
wordWrapColumn: 40
187
});
188
assertWrapping(config, true, 40);
189
config.dispose();
190
});
191
192
test('wordWrap bounded validates wordWrapColumn', () => {
193
const config = new TestWrappingConfiguration({
194
wordWrap: 'bounded',
195
wordWrapColumn: -1
196
});
197
assertWrapping(config, true, 1);
198
config.dispose();
199
});
200
201
test('issue #53152: Cannot assign to read only property \'enabled\' of object', () => {
202
const hoverOptions: IEditorHoverOptions = {};
203
Object.defineProperty(hoverOptions, 'enabled', {
204
writable: false,
205
value: true
206
});
207
const config = new TestConfiguration({ hover: hoverOptions });
208
209
assert.strictEqual(config.options.get(EditorOption.hover).enabled, true);
210
config.updateOptions({ hover: { enabled: false } });
211
assert.strictEqual(config.options.get(EditorOption.hover).enabled, false);
212
213
config.dispose();
214
});
215
216
test('does not emit event when nothing changes', () => {
217
const config = new TestConfiguration({ glyphMargin: true, roundedSelection: false });
218
let event: ConfigurationChangedEvent | null = null;
219
const disposable = config.onDidChange(e => event = e);
220
assert.strictEqual(config.options.get(EditorOption.glyphMargin), true);
221
222
config.updateOptions({ glyphMargin: true });
223
config.updateOptions({ roundedSelection: false });
224
assert.strictEqual(event, null);
225
config.dispose();
226
disposable.dispose();
227
});
228
229
test('issue #94931: Unable to open source file', () => {
230
const config = new TestConfiguration({ quickSuggestions: null! });
231
const actual = <Readonly<Required<IQuickSuggestionsOptions>>>config.options.get(EditorOption.quickSuggestions);
232
assert.deepStrictEqual(actual, {
233
other: 'on',
234
comments: 'off',
235
strings: 'off'
236
});
237
config.dispose();
238
});
239
240
test('issue #102920: Can\'t snap or split view with JSON files', () => {
241
const config = new TestConfiguration({ quickSuggestions: null! });
242
config.updateOptions({ quickSuggestions: { strings: true } });
243
const actual = <Readonly<Required<IQuickSuggestionsOptions>>>config.options.get(EditorOption.quickSuggestions);
244
assert.deepStrictEqual(actual, {
245
other: 'on',
246
comments: 'off',
247
strings: 'on'
248
});
249
config.dispose();
250
});
251
252
test('issue #151926: Untyped editor options apply', () => {
253
const config = new TestConfiguration({});
254
config.updateOptions({ unicodeHighlight: { allowedCharacters: { 'x': true } } });
255
const actual = config.options.get(EditorOption.unicodeHighlighting);
256
assert.deepStrictEqual(actual,
257
{
258
nonBasicASCII: "inUntrustedWorkspace",
259
invisibleCharacters: true,
260
ambiguousCharacters: true,
261
includeComments: "inUntrustedWorkspace",
262
includeStrings: "inUntrustedWorkspace",
263
allowedCharacters: { "x": true },
264
allowedLocales: { "_os": true, "_vscode": true }
265
}
266
);
267
config.dispose();
268
});
269
});
270
271
suite('migrateOptions', () => {
272
273
ensureNoDisposablesAreLeakedInTestSuite();
274
275
function migrate(options: any): any {
276
migrateOptions(options);
277
return options;
278
}
279
280
test('wordWrap', () => {
281
assert.deepStrictEqual(migrate({ wordWrap: true }), { wordWrap: 'on' });
282
assert.deepStrictEqual(migrate({ wordWrap: false }), { wordWrap: 'off' });
283
});
284
test('lineNumbers', () => {
285
assert.deepStrictEqual(migrate({ lineNumbers: true }), { lineNumbers: 'on' });
286
assert.deepStrictEqual(migrate({ lineNumbers: false }), { lineNumbers: 'off' });
287
});
288
test('autoClosingBrackets', () => {
289
assert.deepStrictEqual(migrate({ autoClosingBrackets: false }), { autoClosingBrackets: 'never', autoClosingQuotes: 'never', autoSurround: 'never' });
290
});
291
test('cursorBlinking', () => {
292
assert.deepStrictEqual(migrate({ cursorBlinking: 'visible' }), { cursorBlinking: 'solid' });
293
});
294
test('renderWhitespace', () => {
295
assert.deepStrictEqual(migrate({ renderWhitespace: true }), { renderWhitespace: 'boundary' });
296
assert.deepStrictEqual(migrate({ renderWhitespace: false }), { renderWhitespace: 'none' });
297
});
298
test('renderLineHighlight', () => {
299
assert.deepStrictEqual(migrate({ renderLineHighlight: true }), { renderLineHighlight: 'line' });
300
assert.deepStrictEqual(migrate({ renderLineHighlight: false }), { renderLineHighlight: 'none' });
301
});
302
test('acceptSuggestionOnEnter', () => {
303
assert.deepStrictEqual(migrate({ acceptSuggestionOnEnter: true }), { acceptSuggestionOnEnter: 'on' });
304
assert.deepStrictEqual(migrate({ acceptSuggestionOnEnter: false }), { acceptSuggestionOnEnter: 'off' });
305
});
306
test('tabCompletion', () => {
307
assert.deepStrictEqual(migrate({ tabCompletion: true }), { tabCompletion: 'onlySnippets' });
308
assert.deepStrictEqual(migrate({ tabCompletion: false }), { tabCompletion: 'off' });
309
});
310
test('suggest.filteredTypes', () => {
311
assert.deepStrictEqual(
312
migrate({
313
suggest: {
314
filteredTypes: {
315
method: false,
316
function: false,
317
constructor: false,
318
deprecated: false,
319
field: false,
320
variable: false,
321
class: false,
322
struct: false,
323
interface: false,
324
module: false,
325
property: false,
326
event: false,
327
operator: false,
328
unit: false,
329
value: false,
330
constant: false,
331
enum: false,
332
enumMember: false,
333
keyword: false,
334
text: false,
335
color: false,
336
file: false,
337
reference: false,
338
folder: false,
339
typeParameter: false,
340
snippet: false,
341
}
342
}
343
}), {
344
suggest: {
345
filteredTypes: undefined,
346
showMethods: false,
347
showFunctions: false,
348
showConstructors: false,
349
showDeprecated: false,
350
showFields: false,
351
showVariables: false,
352
showClasses: false,
353
showStructs: false,
354
showInterfaces: false,
355
showModules: false,
356
showProperties: false,
357
showEvents: false,
358
showOperators: false,
359
showUnits: false,
360
showValues: false,
361
showConstants: false,
362
showEnums: false,
363
showEnumMembers: false,
364
showKeywords: false,
365
showWords: false,
366
showColors: false,
367
showFiles: false,
368
showReferences: false,
369
showFolders: false,
370
showTypeParameters: false,
371
showSnippets: false,
372
}
373
});
374
});
375
test('quickSuggestions', () => {
376
assert.deepStrictEqual(migrate({ quickSuggestions: true }), { quickSuggestions: { comments: 'on', strings: 'on', other: 'on' } });
377
assert.deepStrictEqual(migrate({ quickSuggestions: false }), { quickSuggestions: { comments: 'off', strings: 'off', other: 'off' } });
378
assert.deepStrictEqual(migrate({ quickSuggestions: { comments: 'on', strings: 'off' } }), { quickSuggestions: { comments: 'on', strings: 'off' } });
379
});
380
test('hover', () => {
381
assert.deepStrictEqual(migrate({ hover: true }), { hover: { enabled: true } });
382
assert.deepStrictEqual(migrate({ hover: false }), { hover: { enabled: false } });
383
});
384
test('parameterHints', () => {
385
assert.deepStrictEqual(migrate({ parameterHints: true }), { parameterHints: { enabled: true } });
386
assert.deepStrictEqual(migrate({ parameterHints: false }), { parameterHints: { enabled: false } });
387
});
388
test('autoIndent', () => {
389
assert.deepStrictEqual(migrate({ autoIndent: true }), { autoIndent: 'full' });
390
assert.deepStrictEqual(migrate({ autoIndent: false }), { autoIndent: 'advanced' });
391
});
392
test('matchBrackets', () => {
393
assert.deepStrictEqual(migrate({ matchBrackets: true }), { matchBrackets: 'always' });
394
assert.deepStrictEqual(migrate({ matchBrackets: false }), { matchBrackets: 'never' });
395
});
396
test('renderIndentGuides, highlightActiveIndentGuide', () => {
397
assert.deepStrictEqual(migrate({ renderIndentGuides: true }), { renderIndentGuides: undefined, guides: { indentation: true } });
398
assert.deepStrictEqual(migrate({ renderIndentGuides: false }), { renderIndentGuides: undefined, guides: { indentation: false } });
399
assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: true }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: true } });
400
assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: false }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: false } });
401
});
402
403
test('migration does not overwrite new setting', () => {
404
assert.deepStrictEqual(migrate({ renderIndentGuides: true, guides: { indentation: false } }), { renderIndentGuides: undefined, guides: { indentation: false } });
405
assert.deepStrictEqual(migrate({ highlightActiveIndentGuide: true, guides: { highlightActiveIndentation: false } }), { highlightActiveIndentGuide: undefined, guides: { highlightActiveIndentation: false } });
406
});
407
});
408
409