Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/preferences.tsx
13405 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 { BasePromptElementProps, PromptElement, PromptReference, PromptSizing } from '@vscode/prompt-tsx';
7
import { ConfigKey, IConfigurationService } from '../../../../platform/configuration/common/configurationService';
8
import { IVSCodeExtensionContext } from '../../../../platform/extContext/common/extensionContext';
9
import { IFileSystemService } from '../../../../platform/filesystem/common/fileSystemService';
10
import { URI } from '../../../../util/vs/base/common/uri';
11
import { Tag } from '../base/tag';
12
13
export interface UserPreferencesProps extends BasePromptElementProps { }
14
15
export class UserPreferences extends PromptElement<UserPreferencesProps> {
16
constructor(
17
props: UserPreferencesProps,
18
@IFileSystemService private readonly fileSystemService: IFileSystemService,
19
@IConfigurationService private readonly configurationService: IConfigurationService,
20
@IVSCodeExtensionContext private readonly extensionContext: IVSCodeExtensionContext
21
) {
22
super(props);
23
}
24
override async render(state: void, sizing: PromptSizing) {
25
if (!this.configurationService.getConfig(ConfigKey.Advanced.EnableUserPreferences)) {
26
return undefined;
27
}
28
29
try {
30
const uri = URI.joinPath(this.extensionContext.globalStorageUri, 'copilotUserPreferences.md');
31
const fileContents = await this.fileSystemService.readFile(uri);
32
return (<>
33
<Tag name='instructions'>
34
<references value={[new PromptReference(uri)]} />
35
{new TextDecoder().decode(fileContents)}
36
</Tag>
37
38
</>);
39
} catch (ex) {
40
return undefined;
41
}
42
43
}
44
}
45
46