Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeHandler.ts
4780 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 { MarkdownString } from '../../../../../base/common/htmlContent.js';
7
import { IJSONSchema, TypeFromJsonSchema } from '../../../../../base/common/jsonSchema.js';
8
import { ThemeIcon } from '../../../../../base/common/themables.js';
9
import { localize } from '../../../../../nls.js';
10
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
11
import { ILogService } from '../../../../../platform/log/common/log.js';
12
import { Registry } from '../../../../../platform/registry/common/platform.js';
13
import { IWorkbenchContribution } from '../../../../common/contributions.js';
14
import { checkProposedApiEnabled } from '../../../../services/extensions/common/extensions.js';
15
import * as extensionsRegistry from '../../../../services/extensions/common/extensionsRegistry.js';
16
import { ChatViewsWelcomeExtensions, IChatViewsWelcomeContributionRegistry, IChatViewsWelcomeDescriptor } from './chatViewsWelcome.js';
17
18
19
const chatViewsWelcomeJsonSchema = {
20
type: 'object',
21
additionalProperties: false,
22
required: ['icon', 'title', 'contents', 'when'],
23
properties: {
24
icon: {
25
type: 'string',
26
description: localize('chatViewsWelcome.icon', 'The icon for the welcome message.'),
27
},
28
title: {
29
type: 'string',
30
description: localize('chatViewsWelcome.title', 'The title of the welcome message.'),
31
},
32
content: {
33
type: 'string',
34
description: localize('chatViewsWelcome.content', 'The content of the welcome message. The first command link will be rendered as a button.'),
35
},
36
when: {
37
type: 'string',
38
description: localize('chatViewsWelcome.when', 'Condition when the welcome message is shown.'),
39
}
40
}
41
} as const satisfies IJSONSchema;
42
43
type IRawChatViewsWelcomeContribution = TypeFromJsonSchema<typeof chatViewsWelcomeJsonSchema>;
44
45
const chatViewsWelcomeExtensionPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint<IRawChatViewsWelcomeContribution[]>({
46
extensionPoint: 'chatViewsWelcome',
47
jsonSchema: {
48
description: localize('vscode.extension.contributes.chatViewsWelcome', 'Contributes a welcome message to a chat view'),
49
type: 'array',
50
items: chatViewsWelcomeJsonSchema,
51
},
52
});
53
54
export class ChatViewsWelcomeHandler implements IWorkbenchContribution {
55
56
static readonly ID = 'workbench.contrib.chatViewsWelcomeHandler';
57
58
constructor(
59
@ILogService private readonly logService: ILogService,
60
) {
61
chatViewsWelcomeExtensionPoint.setHandler((extensions, delta) => {
62
for (const extension of delta.added) {
63
for (const providerDescriptor of extension.value) {
64
checkProposedApiEnabled(extension.description, 'chatParticipantPrivate');
65
66
const when = ContextKeyExpr.deserialize(providerDescriptor.when);
67
if (!when) {
68
this.logService.error(`Could not deserialize 'when' clause for chatViewsWelcome contribution: ${providerDescriptor.when}`);
69
continue;
70
}
71
72
const descriptor: IChatViewsWelcomeDescriptor = {
73
...providerDescriptor,
74
when,
75
icon: ThemeIcon.fromString(providerDescriptor.icon),
76
content: new MarkdownString(providerDescriptor.content, { isTrusted: true }), // private API with command links
77
};
78
Registry.as<IChatViewsWelcomeContributionRegistry>(ChatViewsWelcomeExtensions.ChatViewsWelcomeRegistry).register(descriptor);
79
}
80
}
81
});
82
}
83
}
84
85