Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatOptions.ts
3296 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 { Color } from '../../../../base/common/color.js';
7
import { Emitter } from '../../../../base/common/event.js';
8
import { Disposable } from '../../../../base/common/lifecycle.js';
9
import { IBracketPairColorizationOptions, IEditorOptions } from '../../../../editor/common/config/editorOptions.js';
10
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
11
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
12
import { IViewDescriptorService } from '../../../common/views.js';
13
14
export interface IChatConfiguration {
15
editor: {
16
readonly fontSize: number;
17
readonly fontFamily: string;
18
readonly lineHeight: number;
19
readonly fontWeight: string;
20
readonly wordWrap: 'off' | 'on';
21
};
22
}
23
24
export interface IChatEditorConfiguration {
25
readonly foreground: Color | undefined;
26
readonly inputEditor: IChatInputEditorOptions;
27
readonly resultEditor: IChatResultEditorOptions;
28
}
29
30
export interface IChatInputEditorOptions {
31
readonly backgroundColor: Color | undefined;
32
readonly accessibilitySupport: string;
33
}
34
35
export interface IChatResultEditorOptions {
36
readonly fontSize: number;
37
readonly fontFamily: string | undefined;
38
readonly lineHeight: number;
39
readonly fontWeight: string;
40
readonly backgroundColor: Color | undefined;
41
readonly bracketPairColorization: IBracketPairColorizationOptions;
42
readonly fontLigatures: boolean | string | undefined;
43
readonly wordWrap: 'off' | 'on';
44
45
// Bring these back if we make the editors editable
46
// readonly cursorBlinking: string;
47
// readonly accessibilitySupport: string;
48
}
49
50
51
export class ChatEditorOptions extends Disposable {
52
private static readonly lineHeightEm = 1.4;
53
54
private readonly _onDidChange = this._register(new Emitter<void>());
55
readonly onDidChange = this._onDidChange.event;
56
57
private _config!: IChatEditorConfiguration;
58
public get configuration(): IChatEditorConfiguration {
59
return this._config;
60
}
61
62
private static readonly relevantSettingIds = [
63
'chat.editor.lineHeight',
64
'chat.editor.fontSize',
65
'chat.editor.fontFamily',
66
'chat.editor.fontWeight',
67
'chat.editor.wordWrap',
68
'editor.cursorBlinking',
69
'editor.fontLigatures',
70
'editor.accessibilitySupport',
71
'editor.bracketPairColorization.enabled',
72
'editor.bracketPairColorization.independentColorPoolPerBracketType',
73
];
74
75
constructor(
76
viewId: string | undefined,
77
private readonly foreground: string,
78
private readonly inputEditorBackgroundColor: string,
79
private readonly resultEditorBackgroundColor: string,
80
@IConfigurationService private readonly configurationService: IConfigurationService,
81
@IThemeService private readonly themeService: IThemeService,
82
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService
83
) {
84
super();
85
86
this._register(this.themeService.onDidColorThemeChange(e => this.update()));
87
this._register(this.viewDescriptorService.onDidChangeLocation(e => {
88
if (e.views.some(v => v.id === viewId)) {
89
this.update();
90
}
91
}));
92
this._register(this.configurationService.onDidChangeConfiguration(e => {
93
if (ChatEditorOptions.relevantSettingIds.some(id => e.affectsConfiguration(id))) {
94
this.update();
95
}
96
}));
97
this.update();
98
}
99
100
private update() {
101
const editorConfig = this.configurationService.getValue<IEditorOptions>('editor');
102
103
// TODO shouldn't the setting keys be more specific?
104
const chatEditorConfig = this.configurationService.getValue<IChatConfiguration>('chat')?.editor;
105
const accessibilitySupport = this.configurationService.getValue<'auto' | 'off' | 'on'>('editor.accessibilitySupport');
106
this._config = {
107
foreground: this.themeService.getColorTheme().getColor(this.foreground),
108
inputEditor: {
109
backgroundColor: this.themeService.getColorTheme().getColor(this.inputEditorBackgroundColor),
110
accessibilitySupport,
111
},
112
resultEditor: {
113
backgroundColor: this.themeService.getColorTheme().getColor(this.resultEditorBackgroundColor),
114
fontSize: chatEditorConfig.fontSize,
115
fontFamily: chatEditorConfig.fontFamily === 'default' ? editorConfig.fontFamily : chatEditorConfig.fontFamily,
116
fontWeight: chatEditorConfig.fontWeight,
117
lineHeight: chatEditorConfig.lineHeight ? chatEditorConfig.lineHeight : ChatEditorOptions.lineHeightEm * chatEditorConfig.fontSize,
118
bracketPairColorization: {
119
enabled: this.configurationService.getValue<boolean>('editor.bracketPairColorization.enabled'),
120
independentColorPoolPerBracketType: this.configurationService.getValue<boolean>('editor.bracketPairColorization.independentColorPoolPerBracketType'),
121
},
122
wordWrap: chatEditorConfig.wordWrap,
123
fontLigatures: editorConfig.fontLigatures,
124
}
125
126
};
127
this._onDidChange.fire();
128
}
129
}
130
131