Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/settingsSchema/vscode-node/settingsSchemaFeature.ts
13399 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 { Uri } from 'vscode';
7
import { IAuthenticationService } from '../../../platform/authentication/common/authentication';
8
import { globalConfigRegistry } from '../../../platform/configuration/common/configurationService';
9
import { JsonSchema } from '../../../platform/configuration/common/jsonSchema';
10
import { Disposable } from '../../../util/vs/base/common/lifecycle';
11
import { autorunWithStore, IReader, observableFromEvent } from '../../../util/vs/base/common/observable';
12
import { VirtualTextDocumentProvider } from '../../inlineEdits/vscode-node/utils/virtualTextDocumentProvider';
13
14
export class SettingsSchemaFeature extends Disposable {
15
private readonly _copilotToken = observableFromEvent(this, this._authenticationService.onDidAuthenticationChange, () => this._authenticationService.copilotToken);
16
private readonly _isInternal = this._copilotToken.map(t => !!(t?.isInternal));
17
18
constructor(
19
@IAuthenticationService private readonly _authenticationService: IAuthenticationService,
20
) {
21
super();
22
23
this._register(autorunWithStore((reader, store) => {
24
const p = store.add(new VirtualTextDocumentProvider('ccsettings'));
25
const doc = p.createDocumentForUri(Uri.parse('ccsettings://root/schema.json'));
26
const schema = this._getSchema(reader);
27
doc.setContent(JSON.stringify(schema));
28
}));
29
}
30
31
private _getSchema(reader: IReader): JsonSchema {
32
const props: Record<string, JsonSchema> = {};
33
34
if (!this._isInternal.read(reader)) {
35
return {};
36
} else {
37
// JSON Schema only for internal users!
38
for (const c of globalConfigRegistry.configs.values()) {
39
props[c.fullyQualifiedId] = { description: 'Recognized Advanced Setting.\nIgnore the warning "Unknown Configuration Setting", which cannot be surpressed.', ... (c.validator ? c.validator.toSchema() : {}) };
40
}
41
42
const schema: JsonSchema = {
43
type: 'object',
44
properties: props,
45
patternProperties: {
46
'github\.copilot(\.chat)?\.advanced\..*': {
47
deprecated: true,
48
description: 'Unknown advanced setting.\nIf you believe this is a supported setting, please file an issue so that it gets registered.',
49
}
50
}
51
};
52
return schema;
53
}
54
}
55
}
56
57