@theia/plugin-ext 1.29.0-next.4 → 1.29.0-next.9
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 +9 -3
- package/lib/common/plugin-api-rpc.d.ts.map +1 -1
- package/lib/common/plugin-api-rpc.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/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.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 +100 -62
- package/lib/plugin/preference-registry.js.map +1 -1
- package/lib/plugin/preference-registry.spec.js +163 -35
- package/lib/plugin/preference-registry.spec.js.map +1 -1
- package/lib/plugin/type-converters.d.ts +1 -0
- package/lib/plugin/type-converters.d.ts.map +1 -1
- package/lib/plugin/type-converters.js +9 -2
- package/lib/plugin/type-converters.js.map +1 -1
- package/lib/plugin/types-impl.d.ts +5 -0
- package/lib/plugin/types-impl.d.ts.map +1 -1
- package/lib/plugin/types-impl.js +17 -3
- 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 +12 -3
- package/src/main/browser/languages-main.ts +23 -1
- package/src/main/browser/preference-registry-main.ts +23 -14
- package/src/plugin/languages/evaluatable-expression.ts +47 -0
- 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 +203 -40
- package/src/plugin/preference-registry.ts +102 -71
- package/src/plugin/type-converters.ts +7 -0
- package/src/plugin/types-impl.ts +18 -0
- 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
|
@@ -66,6 +66,9 @@ import * as MonacoPath from '@theia/monaco-editor-core/esm/vs/base/common/path';
|
|
|
66
66
|
import { IRelativePattern } from '@theia/monaco-editor-core/esm/vs/base/common/glob';
|
|
67
67
|
import { EditorLanguageStatusService, LanguageStatus as EditorLanguageStatus } from '@theia/editor/lib/browser/language-status/editor-language-status-service';
|
|
68
68
|
import { LanguageSelector, RelativePattern } from '@theia/editor/lib/common/language-selector';
|
|
69
|
+
import { ILanguageFeaturesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/languageFeatures';
|
|
70
|
+
import { EvaluatableExpression, EvaluatableExpressionProvider } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
|
|
71
|
+
import { ITextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* @monaco-uplift The public API declares these functions as (languageId: string, service).
|
|
@@ -338,7 +341,26 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
|
|
|
338
341
|
return this.proxy.$provideHover(handle, model.uri, position, token);
|
|
339
342
|
}
|
|
340
343
|
|
|
341
|
-
$
|
|
344
|
+
$registerEvaluatableExpressionProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
|
|
345
|
+
const languageSelector = this.toLanguageSelector(selector);
|
|
346
|
+
const evaluatableExpressionProvider = this.createEvaluatableExpressionProvider(handle);
|
|
347
|
+
this.register(handle,
|
|
348
|
+
(StandaloneServices.get(ILanguageFeaturesService).evaluatableExpressionProvider.register as RegistrationFunction<EvaluatableExpressionProvider>)
|
|
349
|
+
(languageSelector, evaluatableExpressionProvider));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
protected createEvaluatableExpressionProvider(handle: number): EvaluatableExpressionProvider {
|
|
353
|
+
return {
|
|
354
|
+
provideEvaluatableExpression: (model, position, token) => this.provideEvaluatableExpression(handle, model, position, token)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
protected provideEvaluatableExpression(handle: number, model: ITextModel, position: monaco.Position,
|
|
359
|
+
token: monaco.CancellationToken): monaco.languages.ProviderResult<EvaluatableExpression | undefined> {
|
|
360
|
+
return this.proxy.$provideEvaluatableExpression(handle, model.uri, position, token);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
$registerDocumentHighlightProvider(handle: number, _pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
|
|
342
364
|
const languageSelector = this.toLanguageSelector(selector);
|
|
343
365
|
const documentHighlightProvider = this.createDocumentHighlightProvider(handle);
|
|
344
366
|
this.register(handle, (monaco.languages.registerDocumentHighlightProvider as RegistrationFunction<monaco.languages.DocumentHighlightProvider>)
|
|
@@ -70,11 +70,10 @@ export class PreferenceRegistryMainImpl implements PreferenceRegistryMain, Dispo
|
|
|
70
70
|
|
|
71
71
|
const roots = workspaceService.tryGetRoots();
|
|
72
72
|
const data = getPreferences(preferenceProviderProvider, roots);
|
|
73
|
-
const eventData
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
73
|
+
const eventData = Object.values(changes).map<PreferenceChangeExt>(({ scope, newValue, domain, preferenceName }) => {
|
|
74
|
+
const extScope = scope === PreferenceScope.User ? undefined : domain?.[0];
|
|
75
|
+
return { preferenceName, newValue, scope: extScope };
|
|
76
|
+
});
|
|
78
77
|
this.proxy.$acceptConfigurationChanged(data, eventData);
|
|
79
78
|
}));
|
|
80
79
|
}
|
|
@@ -84,17 +83,19 @@ export class PreferenceRegistryMainImpl implements PreferenceRegistryMain, Dispo
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
-
async $updateConfigurationOption(target: boolean | ConfigurationTarget | undefined, key: string, value: any, resource?: string): Promise<void> {
|
|
88
|
-
const scope = this.parseConfigurationTarget(target);
|
|
89
|
-
|
|
86
|
+
async $updateConfigurationOption(target: boolean | ConfigurationTarget | undefined, key: string, value: any, resource?: string, withLanguageOverride?: boolean): Promise<void> {
|
|
87
|
+
const scope = this.parseConfigurationTarget(target, resource);
|
|
88
|
+
const effectiveKey = this.getEffectiveKey(key, scope, withLanguageOverride, resource);
|
|
89
|
+
await this.preferenceService.set(effectiveKey, value, scope, resource);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
async $removeConfigurationOption(target: boolean | ConfigurationTarget | undefined, key: string, resource?: string): Promise<void> {
|
|
93
|
-
const scope = this.parseConfigurationTarget(target);
|
|
94
|
-
|
|
92
|
+
async $removeConfigurationOption(target: boolean | ConfigurationTarget | undefined, key: string, resource?: string, withLanguageOverride?: boolean): Promise<void> {
|
|
93
|
+
const scope = this.parseConfigurationTarget(target, resource);
|
|
94
|
+
const effectiveKey = this.getEffectiveKey(key, scope, withLanguageOverride, resource);
|
|
95
|
+
await this.preferenceService.set(effectiveKey, undefined, scope, resource);
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
private parseConfigurationTarget(target?: boolean | ConfigurationTarget): PreferenceScope
|
|
98
|
+
private parseConfigurationTarget(target?: boolean | ConfigurationTarget, resource?: string): PreferenceScope {
|
|
98
99
|
if (typeof target === 'boolean') {
|
|
99
100
|
return target ? PreferenceScope.User : PreferenceScope.Workspace;
|
|
100
101
|
}
|
|
@@ -106,9 +107,17 @@ export class PreferenceRegistryMainImpl implements PreferenceRegistryMain, Dispo
|
|
|
106
107
|
case ConfigurationTarget.WorkspaceFolder:
|
|
107
108
|
return PreferenceScope.Folder;
|
|
108
109
|
default:
|
|
109
|
-
|
|
110
|
-
return undefined;
|
|
110
|
+
return resource ? PreferenceScope.Folder : PreferenceScope.Workspace;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
// If the caller does not set `withLanguageOverride = true`, we have to check whether the setting exists with that override already.
|
|
115
|
+
protected getEffectiveKey(key: string, scope: PreferenceScope, withLanguageOverride?: boolean, resource?: string): string {
|
|
116
|
+
if (withLanguageOverride) { return key; }
|
|
117
|
+
const overridden = this.preferenceService.overriddenPreferenceName(key);
|
|
118
|
+
if (!overridden) { return key; }
|
|
119
|
+
const value = this.preferenceService.inspectInScope(key, scope, resource, withLanguageOverride);
|
|
120
|
+
return value === undefined ? overridden.preferenceName : key;
|
|
121
|
+
}
|
|
122
|
+
|
|
114
123
|
}
|
|
@@ -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
|
+
}
|
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,221 @@ 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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
});
|
|
90
113
|
});
|
|
91
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
|
+
},
|
|
236
|
+
};
|
|
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
|
+
});
|
|
254
|
+
});
|
|
92
255
|
});
|