@theia/plugin-ext 1.28.0 → 1.29.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/plugin-api-rpc-model.d.ts +7 -0
- package/lib/common/plugin-api-rpc-model.d.ts.map +1 -1
- package/lib/common/plugin-api-rpc-model.js.map +1 -1
- package/lib/common/plugin-api-rpc.d.ts +15 -9
- package/lib/common/plugin-api-rpc.d.ts.map +1 -1
- package/lib/common/plugin-api-rpc.js.map +1 -1
- package/lib/common/rpc-protocol.d.ts +1 -1
- package/lib/common/rpc-protocol.d.ts.map +1 -1
- package/lib/common/rpc-protocol.js +3 -3
- package/lib/common/rpc-protocol.js.map +1 -1
- package/lib/main/browser/languages-main.d.ts +6 -1
- package/lib/main/browser/languages-main.d.ts.map +1 -1
- package/lib/main/browser/languages-main.js +15 -1
- package/lib/main/browser/languages-main.js.map +1 -1
- package/lib/main/browser/preference-registry-main.d.ts +4 -3
- package/lib/main/browser/preference-registry-main.d.ts.map +1 -1
- package/lib/main/browser/preference-registry-main.js +26 -14
- package/lib/main/browser/preference-registry-main.js.map +1 -1
- package/lib/main/browser/view/tree-view-decorator-service.d.ts +1 -1
- package/lib/main/browser/view/tree-view-decorator-service.d.ts.map +1 -1
- package/lib/main/browser/view/tree-view-decorator-service.js +1 -1
- package/lib/main/browser/view/tree-view-decorator-service.js.map +1 -1
- package/lib/main/browser/workspace-main.d.ts.map +1 -1
- package/lib/main/browser/workspace-main.js +1 -4
- package/lib/main/browser/workspace-main.js.map +1 -1
- package/lib/plugin/languages/code-action.d.ts.map +1 -1
- package/lib/plugin/languages/code-action.js +8 -9
- package/lib/plugin/languages/code-action.js.map +1 -1
- package/lib/plugin/languages/document-highlight.d.ts.map +1 -1
- package/lib/plugin/languages/document-highlight.js +0 -1
- package/lib/plugin/languages/document-highlight.js.map +1 -1
- package/lib/plugin/languages/evaluatable-expression.d.ts +12 -0
- package/lib/plugin/languages/evaluatable-expression.d.ts.map +1 -0
- package/lib/plugin/languages/evaluatable-expression.js +41 -0
- package/lib/plugin/languages/evaluatable-expression.js.map +1 -0
- package/lib/plugin/languages/util.d.ts +2 -2
- package/lib/plugin/languages/util.d.ts.map +1 -1
- package/lib/plugin/languages/util.js +0 -2
- package/lib/plugin/languages/util.js.map +1 -1
- package/lib/plugin/languages.d.ts +3 -1
- package/lib/plugin/languages.d.ts.map +1 -1
- package/lib/plugin/languages.js +11 -0
- package/lib/plugin/languages.js.map +1 -1
- package/lib/plugin/plugin-context.d.ts.map +1 -1
- package/lib/plugin/plugin-context.js +4 -0
- package/lib/plugin/plugin-context.js.map +1 -1
- package/lib/plugin/plugin-storage.d.ts +1 -0
- package/lib/plugin/plugin-storage.d.ts.map +1 -1
- package/lib/plugin/plugin-storage.js +3 -0
- package/lib/plugin/plugin-storage.js.map +1 -1
- package/lib/plugin/preference-registry.d.ts +15 -2
- package/lib/plugin/preference-registry.d.ts.map +1 -1
- package/lib/plugin/preference-registry.js +105 -62
- package/lib/plugin/preference-registry.js.map +1 -1
- package/lib/plugin/preference-registry.spec.js +207 -35
- package/lib/plugin/preference-registry.spec.js.map +1 -1
- package/lib/plugin/type-converters.d.ts +7 -6
- package/lib/plugin/type-converters.d.ts.map +1 -1
- package/lib/plugin/type-converters.js +54 -55
- package/lib/plugin/type-converters.js.map +1 -1
- package/lib/plugin/types-impl.d.ts +8 -3
- package/lib/plugin/types-impl.d.ts.map +1 -1
- package/lib/plugin/types-impl.js +22 -10
- package/lib/plugin/types-impl.js.map +1 -1
- package/package.json +24 -24
- package/src/common/plugin-api-rpc-model.ts +10 -0
- package/src/common/plugin-api-rpc.ts +18 -9
- package/src/common/rpc-protocol.ts +5 -5
- package/src/main/browser/languages-main.ts +23 -1
- package/src/main/browser/preference-registry-main.ts +23 -14
- package/src/main/browser/view/tree-view-decorator-service.ts +2 -2
- package/src/main/browser/workspace-main.ts +1 -5
- package/src/plugin/languages/code-action.ts +9 -12
- package/src/plugin/languages/document-highlight.ts +1 -2
- package/src/plugin/languages/evaluatable-expression.ts +47 -0
- package/src/plugin/languages/util.ts +2 -4
- package/src/plugin/languages.ts +15 -0
- package/src/plugin/plugin-context.ts +6 -1
- package/src/plugin/plugin-storage.ts +4 -0
- package/src/plugin/preference-registry.spec.ts +247 -39
- package/src/plugin/preference-registry.ts +107 -71
- package/src/plugin/type-converters.ts +58 -59
- package/src/plugin/types-impl.ts +30 -14
- package/lib/plugin/preferences/configuration.d.ts +0 -35
- package/lib/plugin/preferences/configuration.d.ts.map +0 -1
- package/lib/plugin/preferences/configuration.js +0 -137
- package/lib/plugin/preferences/configuration.js.map +0 -1
- package/lib/plugin/preferences/configuration.spec.d.ts +0 -2
- package/lib/plugin/preferences/configuration.spec.d.ts.map +0 -1
- package/lib/plugin/preferences/configuration.spec.js +0 -178
- package/lib/plugin/preferences/configuration.spec.js.map +0 -1
- package/src/plugin/preferences/configuration.spec.ts +0 -292
- package/src/plugin/preferences/configuration.ts +0 -167
|
@@ -145,20 +145,17 @@ export class CodeActionAdapter {
|
|
|
145
145
|
return this.cacheId++;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return typeof (<theia.Command>smth).command === 'string';
|
|
148
|
+
private static _isCommand(arg: unknown): arg is theia.Command {
|
|
149
|
+
return !!arg && typeof arg === 'object' && typeof (arg as theia.Command).command === 'string';
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
&&
|
|
158
|
-
&&
|
|
159
|
-
&&
|
|
160
|
-
&& (typeof obj.positionColumn === 'number')
|
|
161
|
-
);
|
|
152
|
+
private static _isSelection(obj: unknown): obj is Selection {
|
|
153
|
+
const selection = obj as Selection;
|
|
154
|
+
return !!obj && typeof obj === 'object'
|
|
155
|
+
&& typeof selection.selectionStartLineNumber === 'number'
|
|
156
|
+
&& typeof selection.selectionStartColumn === 'number'
|
|
157
|
+
&& typeof selection.positionLineNumber === 'number'
|
|
158
|
+
&& typeof selection.positionColumn === 'number';
|
|
162
159
|
}
|
|
163
160
|
|
|
164
161
|
}
|
|
@@ -55,8 +55,7 @@ export class DocumentHighlightAdapter {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
private isDocumentHighlightArray(array: any): array is types.DocumentHighlight[] {
|
|
58
|
+
private isDocumentHighlightArray(array: unknown): array is types.DocumentHighlight[] {
|
|
60
59
|
return Array.isArray(array) && array.length > 0 && array[0] instanceof types.DocumentHighlight;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { URI } from '@theia/core/shared/vscode-uri';
|
|
18
|
+
import * as theia from '@theia/plugin';
|
|
19
|
+
import { Position } from '../../common/plugin-api-rpc';
|
|
20
|
+
import { EvaluatableExpression } from '../../common/plugin-api-rpc-model';
|
|
21
|
+
import { DocumentsExtImpl } from '../documents';
|
|
22
|
+
import * as Converter from '../type-converters';
|
|
23
|
+
|
|
24
|
+
export class EvaluatableExpressionAdapter {
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private readonly provider: theia.EvaluatableExpressionProvider,
|
|
28
|
+
private readonly documents: DocumentsExtImpl
|
|
29
|
+
) { }
|
|
30
|
+
|
|
31
|
+
async provideEvaluatableExpression(resource: URI, position: Position, token: theia.CancellationToken): Promise<EvaluatableExpression | undefined> {
|
|
32
|
+
const documentData = this.documents.getDocumentData(resource);
|
|
33
|
+
if (!documentData) {
|
|
34
|
+
return Promise.reject(new Error(`There is no document data for ${resource}`));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const document = documentData.document;
|
|
38
|
+
const pos = Converter.toPosition(position);
|
|
39
|
+
|
|
40
|
+
return Promise.resolve(this.provider.provideEvaluatableExpression(document, pos, token)).then(expression => {
|
|
41
|
+
if (!expression) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return Converter.fromEvaluatableExpression(expression);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -17,12 +17,10 @@
|
|
|
17
17
|
import * as theia from '@theia/plugin';
|
|
18
18
|
import * as types from '../types-impl';
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
export function isLocationArray(array: any): array is types.Location[] {
|
|
20
|
+
export function isLocationArray(array: unknown): array is types.Location[] {
|
|
22
21
|
return Array.isArray(array) && array.length > 0 && array[0] instanceof types.Location;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
export function isDefinitionLinkArray(array: any): array is theia.DefinitionLink[] {
|
|
24
|
+
export function isDefinitionLinkArray(array: unknown): array is theia.DefinitionLink[] {
|
|
27
25
|
return Array.isArray(array) && array.length > 0 && array[0].hasOwnProperty('targetUri') && array[0].hasOwnProperty('targetRange');
|
|
28
26
|
}
|
package/src/plugin/languages.ts
CHANGED
|
@@ -62,11 +62,13 @@ import {
|
|
|
62
62
|
CallHierarchyIncomingCall,
|
|
63
63
|
CallHierarchyOutgoingCall,
|
|
64
64
|
LinkedEditingRanges,
|
|
65
|
+
EvaluatableExpression
|
|
65
66
|
} from '../common/plugin-api-rpc-model';
|
|
66
67
|
import { CompletionAdapter } from './languages/completion';
|
|
67
68
|
import { Diagnostics } from './languages/diagnostics';
|
|
68
69
|
import { SignatureHelpAdapter } from './languages/signature';
|
|
69
70
|
import { HoverAdapter } from './languages/hover';
|
|
71
|
+
import { EvaluatableExpressionAdapter } from './languages/evaluatable-expression';
|
|
70
72
|
import { DocumentHighlightAdapter } from './languages/document-highlight';
|
|
71
73
|
import { DocumentFormattingAdapter } from './languages/document-formatting';
|
|
72
74
|
import { RangeFormattingAdapter } from './languages/range-formatting';
|
|
@@ -100,6 +102,7 @@ import { serializeEnterRules, serializeIndentation, serializeRegExp } from './la
|
|
|
100
102
|
type Adapter = CompletionAdapter |
|
|
101
103
|
SignatureHelpAdapter |
|
|
102
104
|
HoverAdapter |
|
|
105
|
+
EvaluatableExpressionAdapter |
|
|
103
106
|
DocumentHighlightAdapter |
|
|
104
107
|
DocumentFormattingAdapter |
|
|
105
108
|
RangeFormattingAdapter |
|
|
@@ -350,6 +353,18 @@ export class LanguagesExtImpl implements LanguagesExt {
|
|
|
350
353
|
}
|
|
351
354
|
// ### Hover Provider end
|
|
352
355
|
|
|
356
|
+
// ### EvaluatableExpression Provider begin
|
|
357
|
+
registerEvaluatableExpressionProvider(selector: theia.DocumentSelector, provider: theia.EvaluatableExpressionProvider, pluginInfo: PluginInfo): theia.Disposable {
|
|
358
|
+
const callId = this.addNewAdapter(new EvaluatableExpressionAdapter(provider, this.documents));
|
|
359
|
+
this.proxy.$registerEvaluatableExpressionProvider(callId, pluginInfo, this.transformDocumentSelector(selector));
|
|
360
|
+
return this.createDisposable(callId);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
$provideEvaluatableExpression(handle: number, resource: UriComponents, position: Position, token: theia.CancellationToken): Promise<EvaluatableExpression | undefined> {
|
|
364
|
+
return this.withAdapter(handle, EvaluatableExpressionAdapter, adapter => adapter.provideEvaluatableExpression(URI.revive(resource), position, token), undefined);
|
|
365
|
+
}
|
|
366
|
+
// ### EvaluatableExpression Provider end
|
|
367
|
+
|
|
353
368
|
// ### Document Highlight Provider begin
|
|
354
369
|
registerDocumentHighlightProvider(selector: theia.DocumentSelector, provider: theia.DocumentHighlightProvider, pluginInfo: PluginInfo): theia.Disposable {
|
|
355
370
|
const callId = this.addNewAdapter(new DocumentHighlightAdapter(provider, this.documents));
|
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
SignatureHelp,
|
|
79
79
|
SignatureHelpTriggerKind,
|
|
80
80
|
Hover,
|
|
81
|
+
EvaluatableExpression,
|
|
81
82
|
DocumentHighlightKind,
|
|
82
83
|
DocumentHighlight,
|
|
83
84
|
DocumentLink,
|
|
@@ -559,7 +560,7 @@ export function createAPIFactory(
|
|
|
559
560
|
extHostFileSystemEvent.getOnWillDeleteFileEvent(plugin)(listener, thisArg, disposables),
|
|
560
561
|
onWillRenameFiles: (listener: (e: theia.FileWillRenameEvent) => any, thisArg?: any, disposables?: theia.Disposable[]) =>
|
|
561
562
|
extHostFileSystemEvent.getOnWillRenameFileEvent(plugin)(listener, thisArg, disposables),
|
|
562
|
-
getConfiguration(section
|
|
563
|
+
getConfiguration(section, resource): theia.WorkspaceConfiguration {
|
|
563
564
|
return preferenceRegistryExt.getConfiguration(section, resource);
|
|
564
565
|
},
|
|
565
566
|
onDidChangeConfiguration(listener, thisArgs?, disposables?): theia.Disposable {
|
|
@@ -731,6 +732,9 @@ export function createAPIFactory(
|
|
|
731
732
|
registerHoverProvider(selector: theia.DocumentSelector, provider: theia.HoverProvider): theia.Disposable {
|
|
732
733
|
return languagesExt.registerHoverProvider(selector, provider, pluginToPluginInfo(plugin));
|
|
733
734
|
},
|
|
735
|
+
registerEvaluatableExpressionProvider(selector: theia.DocumentSelector, provider: theia.EvaluatableExpressionProvider): theia.Disposable {
|
|
736
|
+
return languagesExt.registerEvaluatableExpressionProvider(selector, provider, pluginToPluginInfo(plugin));
|
|
737
|
+
},
|
|
734
738
|
registerDocumentHighlightProvider(selector: theia.DocumentSelector, provider: theia.DocumentHighlightProvider): theia.Disposable {
|
|
735
739
|
return languagesExt.registerDocumentHighlightProvider(selector, provider, pluginToPluginInfo(plugin));
|
|
736
740
|
},
|
|
@@ -991,6 +995,7 @@ export function createAPIFactory(
|
|
|
991
995
|
SignatureHelp,
|
|
992
996
|
SignatureHelpTriggerKind,
|
|
993
997
|
Hover,
|
|
998
|
+
EvaluatableExpression,
|
|
994
999
|
DocumentHighlightKind,
|
|
995
1000
|
DocumentHighlight,
|
|
996
1001
|
DocumentLink,
|
|
@@ -38,6 +38,10 @@ export class Memento implements theia.Memento {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
keys(): string[] {
|
|
42
|
+
return Object.entries(this.cache).filter(([, value]) => value !== undefined).map(([key]) => key);
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
get<T>(key: string): T | undefined;
|
|
42
46
|
get<T>(key: string, defaultValue: T): T;
|
|
43
47
|
get<T>(key: string, defaultValue?: T): T | undefined {
|
|
@@ -14,16 +14,17 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import { PreferenceRegistryExtImpl } from './preference-registry';
|
|
17
|
+
import { PreferenceRegistryExtImpl, PreferenceScope } from './preference-registry';
|
|
18
18
|
import * as chai from 'chai';
|
|
19
19
|
import { WorkspaceExtImpl } from '../plugin/workspace';
|
|
20
20
|
import { ProxyIdentifier, RPCProtocol } from '../common/rpc-protocol';
|
|
21
|
+
import { URI } from './types-impl';
|
|
21
22
|
|
|
22
23
|
const expect = chai.expect;
|
|
23
24
|
|
|
24
25
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
26
|
describe('PreferenceRegistryExtImpl:', () => {
|
|
26
|
-
|
|
27
|
+
const workspaceRoot = URI.parse('/workspace-root');
|
|
27
28
|
let preferenceRegistryExtImpl: PreferenceRegistryExtImpl;
|
|
28
29
|
const getProxy = (proxyId: ProxyIdentifier<unknown>) => { };
|
|
29
30
|
const set = (identifier: ProxyIdentifier<unknown>, instance: unknown) => { };
|
|
@@ -34,59 +35,266 @@ describe('PreferenceRegistryExtImpl:', () => {
|
|
|
34
35
|
set,
|
|
35
36
|
dispose
|
|
36
37
|
} as RPCProtocol;
|
|
37
|
-
const mockWorkspace: WorkspaceExtImpl = {} as WorkspaceExtImpl;
|
|
38
|
+
const mockWorkspace: WorkspaceExtImpl = { workspaceFolders: [{ uri: workspaceRoot, name: 'workspace-root', index: 0 }] } as WorkspaceExtImpl;
|
|
38
39
|
|
|
39
40
|
beforeEach(() => {
|
|
40
41
|
preferenceRegistryExtImpl = new PreferenceRegistryExtImpl(mockRPC, mockWorkspace);
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
it('
|
|
44
|
-
const value:
|
|
44
|
+
it('should parse configuration data without overrides', () => {
|
|
45
|
+
const value: Record<string, any> = {
|
|
45
46
|
'my.key1.foo': 'value1',
|
|
46
47
|
'my.key1.bar': 'value2',
|
|
47
48
|
};
|
|
48
|
-
const result
|
|
49
|
-
expect(result.my).to.be.an('object');
|
|
50
|
-
expect(result.my.key1).to.be.an('object');
|
|
49
|
+
const result = preferenceRegistryExtImpl['parseConfigurationData'](value);
|
|
50
|
+
expect(result.contents.my).to.be.an('object');
|
|
51
|
+
expect(result.contents.my.key1).to.be.an('object');
|
|
51
52
|
|
|
52
|
-
expect(result.my.key1.foo).to.be.an('string');
|
|
53
|
-
expect(result.my.key1.foo).to.equal('value1');
|
|
53
|
+
expect(result.contents.my.key1.foo).to.be.an('string');
|
|
54
|
+
expect(result.contents.my.key1.foo).to.equal('value1');
|
|
54
55
|
|
|
55
|
-
expect(result.my.key1.bar).to.be.an('string');
|
|
56
|
-
expect(result.my.key1.bar).to.equal('value2');
|
|
56
|
+
expect(result.contents.my.key1.bar).to.be.an('string');
|
|
57
|
+
expect(result.contents.my.key1.bar).to.equal('value2');
|
|
58
|
+
expect(result.keys).deep.equal(['my.key1.foo', 'my.key1.bar']);
|
|
57
59
|
});
|
|
58
60
|
|
|
59
|
-
it('
|
|
60
|
-
const value:
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'a.__proto__.injectedParsedPrototype': true,
|
|
64
|
-
'__proto__': {},
|
|
61
|
+
it('should parse configuration with overrides', () => {
|
|
62
|
+
const value: Record<string, any> = {
|
|
63
|
+
'editor.tabSize': 2,
|
|
64
|
+
'[typescript].editor.tabSize': 4,
|
|
65
65
|
};
|
|
66
|
-
const result
|
|
67
|
-
expect(result.
|
|
68
|
-
|
|
69
|
-
expect(
|
|
70
|
-
|
|
71
|
-
expect(
|
|
72
|
-
const rawObject = {} as any;
|
|
73
|
-
expect(rawObject.injectedParsedPrototype).to.be.an('undefined');
|
|
66
|
+
const result = preferenceRegistryExtImpl['parseConfigurationData'](value);
|
|
67
|
+
expect(result.contents.editor.tabSize).to.equal(2);
|
|
68
|
+
const tsOverride = result.overrides[0];
|
|
69
|
+
expect(tsOverride.contents.editor.tabSize).to.equal(4);
|
|
70
|
+
expect(tsOverride.identifiers).deep.equal(['typescript']);
|
|
71
|
+
expect(tsOverride.keys).deep.equal(['editor.tabSize']);
|
|
74
72
|
});
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
describe('Prototype pollution', () => {
|
|
75
|
+
it('Ignores key `__proto__`', () => {
|
|
76
|
+
const value: Record<string, any> = {
|
|
77
|
+
'my.key1.foo': 'value1',
|
|
78
|
+
'__proto__.injectedParsedPrototype': true,
|
|
79
|
+
'a.__proto__.injectedParsedPrototype': true,
|
|
80
|
+
'__proto__': {},
|
|
81
|
+
'[typescript].someKey.foo': 'value',
|
|
82
|
+
'[typescript].__proto__.injectedParsedPrototype': true,
|
|
83
|
+
};
|
|
84
|
+
const result = preferenceRegistryExtImpl['parseConfigurationData'](value);
|
|
85
|
+
expect(result.contents.my).to.be.an('object');
|
|
86
|
+
expect(result.contents.__proto__).to.be.an('undefined');
|
|
87
|
+
expect(result.contents.my.key1.foo).to.equal('value1');
|
|
88
|
+
expect(result.overrides[0].contents.__proto__).to.be.an('undefined');
|
|
89
|
+
const prototypeObject = Object.prototype as any;
|
|
90
|
+
expect(prototypeObject.injectedParsedPrototype).to.be.an('undefined');
|
|
91
|
+
const rawObject = {} as any;
|
|
92
|
+
expect(rawObject.injectedParsedPrototype).to.be.an('undefined');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('Ignores key `constructor.prototype`', () => {
|
|
96
|
+
const value: Record<string, any> = {
|
|
97
|
+
'my.key1.foo': 'value1',
|
|
98
|
+
'a.constructor.prototype.injectedParsedConstructorPrototype': true,
|
|
99
|
+
'constructor.prototype.injectedParsedConstructorPrototype': true,
|
|
100
|
+
'[python].some.key.foo': 'value',
|
|
101
|
+
'[python].a.constructor.prototype.injectedParsedConsttructorPrototype': true
|
|
102
|
+
};
|
|
103
|
+
const result = preferenceRegistryExtImpl['parseConfigurationData'](value);
|
|
104
|
+
expect(result.contents.my).to.be.an('object');
|
|
105
|
+
expect(result.contents.__proto__).to.be.an('undefined');
|
|
106
|
+
expect(result.contents.my.key1.foo).to.equal('value1');
|
|
107
|
+
const prototypeObject = Object.prototype as any;
|
|
108
|
+
expect(prototypeObject.injectedParsedConstructorPrototype).to.be.an('undefined');
|
|
109
|
+
expect(result.overrides[0].contents.__proto__).to.be.an('undefined');
|
|
110
|
+
const rawObject = {} as any;
|
|
111
|
+
expect(rawObject.injectedParsedConstructorPrototype).to.be.an('undefined');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/* eslint-disable no-unused-expressions */
|
|
116
|
+
describe('toConfigurationChangeEvent', () => {
|
|
117
|
+
// E.g. deletion of a `tasks.json`.
|
|
118
|
+
it('Handles deletion of a section', () => {
|
|
119
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent']([{ newValue: undefined, preferenceName: 'whole-section' }]);
|
|
120
|
+
expect(affectsChecker.affectsConfiguration('whole-section')).to.be.true;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('Reports true of supersection if subsection changes', () => {
|
|
124
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent']([{ newValue: 'foo', preferenceName: 'whole-section.subsection.item' }]);
|
|
125
|
+
expect(affectsChecker.affectsConfiguration('whole-section')).to.be.true;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// This assumes that there should not exist a preference `section` and `section.*` as separate preferences.
|
|
129
|
+
// This is true in practice in all cases except `extensions` (i.e. extensions.json) and extensions.ignoreRecommendations etc.
|
|
130
|
+
// Given that, if a super-section changes (e.g. through deletion), all subsections will also be affected.
|
|
131
|
+
it('Reports true of a subsection if a supersection changes', () => {
|
|
132
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent']([{ newValue: 'bar', preferenceName: 'whole-section' }]);
|
|
133
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection')).to.be.true;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('Does not report true if a different subsection changes:', () => {
|
|
137
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent']([{ newValue: 'bar', preferenceName: 'whole-section.subsection.itemA' }]);
|
|
138
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection.itemB')).to.be.false;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('Reports that any URI is affected if change has no URI', () => {
|
|
142
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent']([{ newValue: 'bar', preferenceName: 'whole-section' }]);
|
|
143
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', URI.parse('/wherever'))).to.be.true;
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('Reports true if no URI is provided to check', () => {
|
|
147
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
148
|
+
[{ newValue: 'bar', preferenceName: 'whole-section', scope: 'file:///very/specific/path' }]
|
|
149
|
+
);
|
|
150
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection')).to.be.true;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('Reports false if the URIs dont match.', () => {
|
|
154
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
155
|
+
[{ newValue: 'bar', preferenceName: 'whole-section', scope: 'file:///very/specific/path' }]
|
|
156
|
+
);
|
|
157
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', URI.parse('/other/specific/path'))).to.be.false;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('Reports true if the URIs do match', () => {
|
|
161
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
162
|
+
[{ newValue: 'bar', preferenceName: 'whole-section', scope: 'file:///very/specific/path' }]
|
|
163
|
+
);
|
|
164
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', URI.parse('/very/specific/path'))).to.be.true;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('Reports true if the checked URI is a child of the affected path', () => {
|
|
168
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
169
|
+
[{ newValue: 'bar', preferenceName: 'whole-section', scope: 'file:///very/specific/path' }]
|
|
170
|
+
);
|
|
171
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', URI.parse('/very/specific/path/and/its/child'))).to.be.true;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('Reports false if the checked URI starts with the affected path but not at a directory break', () => {
|
|
175
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
176
|
+
[{ newValue: 'bar', preferenceName: 'whole-section', scope: 'file:///very/specific/path' }]
|
|
177
|
+
);
|
|
178
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', URI.parse('/very/specific/path-or-not/and/its/child'))).to.be.false;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('Extracts language override and returns false if change does not include language', () => {
|
|
182
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
183
|
+
[{ newValue: 'bar', preferenceName: 'whole-section', scope: 'file:///very/specific/path' }]
|
|
184
|
+
);
|
|
185
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', { languageId: 'typescript' })).to.be.false;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('Extracts language override and returns true if change does include language', () => {
|
|
189
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
190
|
+
[{ newValue: 'bar', preferenceName: '[typescript].whole-section', scope: 'file:///very/specific/path' }]
|
|
191
|
+
);
|
|
192
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', { languageId: 'typescript' })).to.be.true;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("Extracts language override and URI and returns false if the URI doesn't match", () => {
|
|
196
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
197
|
+
[{ newValue: 'bar', preferenceName: '[typescript].whole-section', scope: 'file:///very/specific/path' }]
|
|
198
|
+
);
|
|
199
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', { languageId: 'typescript', uri: URI.parse('/other/specific/path') })).to.be.false;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('Extracts language override and URI and returns true if both match', () => {
|
|
203
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
204
|
+
[{ newValue: 'bar', preferenceName: '[typescript].whole-section', scope: 'file:///very/specific/path' }]
|
|
205
|
+
);
|
|
206
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subsection', { languageId: 'typescript', uri: URI.parse('/very/specific/path') })).to.be.true;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('Reports true if no language override is provided and a language overriden preference changes', () => {
|
|
210
|
+
const affectsChecker = preferenceRegistryExtImpl['toConfigurationChangeEvent'](
|
|
211
|
+
[{ newValue: 'bar', preferenceName: '[typescript].whole-section.subitem', scope: 'file:///somewhat-specific-path' }]
|
|
212
|
+
);
|
|
213
|
+
expect(affectsChecker.affectsConfiguration('whole-section.subitem')).to.be.true;
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('Overrides', () => {
|
|
218
|
+
const values = {
|
|
219
|
+
[PreferenceScope.Default]: {
|
|
220
|
+
'editor.fontSize': 14,
|
|
221
|
+
'editor.tabSize': 2,
|
|
222
|
+
'editor.renderWhitespace': 'selection'
|
|
223
|
+
},
|
|
224
|
+
[PreferenceScope.User]: {
|
|
225
|
+
'editor.tabSize': 4,
|
|
226
|
+
},
|
|
227
|
+
[PreferenceScope.Workspace]: {
|
|
228
|
+
'editor.renderWhitespace': 'none',
|
|
229
|
+
'[python].editor.renderWhitespace': 'all',
|
|
230
|
+
},
|
|
231
|
+
[PreferenceScope.Folder]: {
|
|
232
|
+
[workspaceRoot.toString()]: {
|
|
233
|
+
'editor.fontSize': 12,
|
|
234
|
+
}
|
|
235
|
+
},
|
|
81
236
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
237
|
+
beforeEach(() => preferenceRegistryExtImpl.init(values));
|
|
238
|
+
it('Returns a scoped value when URI is provided', () => {
|
|
239
|
+
const valuesRetrieved = preferenceRegistryExtImpl.getConfiguration(undefined, workspaceRoot).get('editor') as Record<string, unknown>;
|
|
240
|
+
expect(valuesRetrieved.fontSize).equal(12);
|
|
241
|
+
});
|
|
242
|
+
it('Returns a lower-priority scope if the value is undefined in the URI-designated scope', () => {
|
|
243
|
+
const valuesRetrieved = preferenceRegistryExtImpl.getConfiguration(undefined, workspaceRoot).get('editor') as Record<string, unknown>;
|
|
244
|
+
expect(valuesRetrieved.renderWhitespace).equal('none');
|
|
245
|
+
});
|
|
246
|
+
it('Returns a language-overridden value if languageId is provided', () => {
|
|
247
|
+
const valuesRetrieved = preferenceRegistryExtImpl.getConfiguration(undefined, { uri: workspaceRoot, languageId: 'python' }).get('editor') as Record<string, unknown>;
|
|
248
|
+
expect(valuesRetrieved.renderWhitespace).equal('all');
|
|
249
|
+
});
|
|
250
|
+
it('Returns the default value if the language override is undefined', () => {
|
|
251
|
+
const valuesRetrieved = preferenceRegistryExtImpl.getConfiguration(undefined, { uri: workspaceRoot, languageId: 'python' }).get('editor') as Record<string, unknown>;
|
|
252
|
+
expect(valuesRetrieved.tabSize).equal(4);
|
|
253
|
+
});
|
|
90
254
|
});
|
|
91
255
|
|
|
256
|
+
describe('Proxy Behavior', () => {
|
|
257
|
+
const deepConfig = {
|
|
258
|
+
'python.linting.enabled': true,
|
|
259
|
+
'python.linting.flake8Args': [],
|
|
260
|
+
'python.linting.flake8CategorySeverity.E': 'Error',
|
|
261
|
+
'python.linting.flake8CategorySeverity.F': 'Error',
|
|
262
|
+
'python.linting.flake8CategorySeverity.W': 'Warning',
|
|
263
|
+
'python.linting.flake8Enabled': false,
|
|
264
|
+
'python.linting.flake8Path': 'flake8',
|
|
265
|
+
'python.linting.ignorePatterns': ['.vscode/*.py', '**/site-packages/**/*.py'],
|
|
266
|
+
'python.linting.lintOnSave': true,
|
|
267
|
+
'python.linting.maxNumberOfProblems': 100,
|
|
268
|
+
'python.linting.banditArgs': [],
|
|
269
|
+
'python.linting.banditEnabled': false,
|
|
270
|
+
'python.linting.banditPath': 'bandit',
|
|
271
|
+
'python.linting.mypyArgs': [
|
|
272
|
+
'--ignore-missing-imports',
|
|
273
|
+
'--follow-imports=silent',
|
|
274
|
+
'--show-column-numbers'
|
|
275
|
+
],
|
|
276
|
+
'python.linting.mypyCategorySeverity.error': 'Error',
|
|
277
|
+
'python.linting.mypyCategorySeverity.note': 'Information',
|
|
278
|
+
'python.linting.mypyEnabled': false,
|
|
279
|
+
'python.linting.mypyPath': 'mypy',
|
|
280
|
+
};
|
|
281
|
+
// https://github.com/eclipse-theia/theia/issues/11501
|
|
282
|
+
it("Doesn't violate proxy rules and return a proxy when the underlying object is expected.", () => {
|
|
283
|
+
preferenceRegistryExtImpl.init({
|
|
284
|
+
[PreferenceScope.Default]: deepConfig,
|
|
285
|
+
[PreferenceScope.User]: {},
|
|
286
|
+
[PreferenceScope.Workspace]: {},
|
|
287
|
+
[PreferenceScope.Folder]: {
|
|
288
|
+
[workspaceRoot.toString()]: {},
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
const pythonConfig = preferenceRegistryExtImpl.getConfiguration('python', workspaceRoot);
|
|
292
|
+
const lintConfig = pythonConfig.get<Record<string, unknown>>('linting')!;
|
|
293
|
+
const stringDictionary = Object.create(null);
|
|
294
|
+
Object.keys(lintConfig).forEach(key => {
|
|
295
|
+
stringDictionary[key] = lintConfig[key];
|
|
296
|
+
});
|
|
297
|
+
expect(Boolean('Made it this far without throwing an error')).to.be.true;
|
|
298
|
+
});
|
|
299
|
+
});
|
|
92
300
|
});
|