Path: blob/main/src/vs/workbench/contrib/chat/browser/chatOptions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Color } from '../../../../base/common/color.js';6import { Emitter } from '../../../../base/common/event.js';7import { Disposable } from '../../../../base/common/lifecycle.js';8import { IBracketPairColorizationOptions, IEditorOptions } from '../../../../editor/common/config/editorOptions.js';9import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';10import { IThemeService } from '../../../../platform/theme/common/themeService.js';11import { IViewDescriptorService } from '../../../common/views.js';1213export interface IChatConfiguration {14editor: {15readonly fontSize: number;16readonly fontFamily: string;17readonly lineHeight: number;18readonly fontWeight: string;19readonly wordWrap: 'off' | 'on';20};21}2223export interface IChatEditorConfiguration {24readonly foreground: Color | undefined;25readonly inputEditor: IChatInputEditorOptions;26readonly resultEditor: IChatResultEditorOptions;27}2829export interface IChatInputEditorOptions {30readonly backgroundColor: Color | undefined;31readonly accessibilitySupport: string;32}3334export interface IChatResultEditorOptions {35readonly fontSize: number;36readonly fontFamily: string | undefined;37readonly lineHeight: number;38readonly fontWeight: string;39readonly backgroundColor: Color | undefined;40readonly bracketPairColorization: IBracketPairColorizationOptions;41readonly fontLigatures: boolean | string | undefined;42readonly wordWrap: 'off' | 'on';4344// Bring these back if we make the editors editable45// readonly cursorBlinking: string;46// readonly accessibilitySupport: string;47}484950export class ChatEditorOptions extends Disposable {51private static readonly lineHeightEm = 1.4;5253private readonly _onDidChange = this._register(new Emitter<void>());54readonly onDidChange = this._onDidChange.event;5556private _config!: IChatEditorConfiguration;57public get configuration(): IChatEditorConfiguration {58return this._config;59}6061private static readonly relevantSettingIds = [62'chat.editor.lineHeight',63'chat.editor.fontSize',64'chat.editor.fontFamily',65'chat.editor.fontWeight',66'chat.editor.wordWrap',67'editor.cursorBlinking',68'editor.fontLigatures',69'editor.accessibilitySupport',70'editor.bracketPairColorization.enabled',71'editor.bracketPairColorization.independentColorPoolPerBracketType',72];7374constructor(75viewId: string | undefined,76private readonly foreground: string,77private readonly inputEditorBackgroundColor: string,78private readonly resultEditorBackgroundColor: string,79@IConfigurationService private readonly configurationService: IConfigurationService,80@IThemeService private readonly themeService: IThemeService,81@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService82) {83super();8485this._register(this.themeService.onDidColorThemeChange(e => this.update()));86this._register(this.viewDescriptorService.onDidChangeLocation(e => {87if (e.views.some(v => v.id === viewId)) {88this.update();89}90}));91this._register(this.configurationService.onDidChangeConfiguration(e => {92if (ChatEditorOptions.relevantSettingIds.some(id => e.affectsConfiguration(id))) {93this.update();94}95}));96this.update();97}9899private update() {100const editorConfig = this.configurationService.getValue<IEditorOptions>('editor');101102// TODO shouldn't the setting keys be more specific?103const chatEditorConfig = this.configurationService.getValue<IChatConfiguration>('chat')?.editor;104const accessibilitySupport = this.configurationService.getValue<'auto' | 'off' | 'on'>('editor.accessibilitySupport');105this._config = {106foreground: this.themeService.getColorTheme().getColor(this.foreground),107inputEditor: {108backgroundColor: this.themeService.getColorTheme().getColor(this.inputEditorBackgroundColor),109accessibilitySupport,110},111resultEditor: {112backgroundColor: this.themeService.getColorTheme().getColor(this.resultEditorBackgroundColor),113fontSize: chatEditorConfig.fontSize,114fontFamily: chatEditorConfig.fontFamily === 'default' ? editorConfig.fontFamily : chatEditorConfig.fontFamily,115fontWeight: chatEditorConfig.fontWeight,116lineHeight: chatEditorConfig.lineHeight ? chatEditorConfig.lineHeight : ChatEditorOptions.lineHeightEm * chatEditorConfig.fontSize,117bracketPairColorization: {118enabled: this.configurationService.getValue<boolean>('editor.bracketPairColorization.enabled'),119independentColorPoolPerBracketType: this.configurationService.getValue<boolean>('editor.bracketPairColorization.independentColorPoolPerBracketType'),120},121wordWrap: chatEditorConfig.wordWrap,122fontLigatures: editorConfig.fontLigatures,123}124125};126this._onDidChange.fire();127}128}129130131