Path: blob/main/src/vs/sessions/contrib/agentFeedback/browser/agentFeedbackOverviewRulerContribution.ts
13401 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 { Disposable } from '../../../../base/common/lifecycle.js';6import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';7import { IEditorContribution, IEditorDecorationsCollection } from '../../../../editor/common/editorCommon.js';8import { EditorContributionInstantiation, registerEditorContribution } from '../../../../editor/browser/editorExtensions.js';9import { overviewRulerInfo } from '../../../../editor/common/core/editorColorRegistry.js';10import { OverviewRulerLane } from '../../../../editor/common/model.js';11import { themeColorFromId } from '../../../../platform/theme/common/themeService.js';12import { registerColor } from '../../../../platform/theme/common/colorRegistry.js';13import { localize } from '../../../../nls.js';14import { URI } from '../../../../base/common/uri.js';15import { IAgentFeedbackService } from './agentFeedbackService.js';16import { IChatEditingService } from '../../../../workbench/contrib/chat/common/editing/chatEditingService.js';17import { getSessionForResource } from './agentFeedbackEditorUtils.js';18import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';1920const overviewRulerAgentFeedbackForeground = registerColor(21'editorOverviewRuler.agentFeedbackForeground',22overviewRulerInfo,23localize('editorOverviewRuler.agentFeedbackForeground', 'Editor overview ruler decoration color for agent feedback. This color should be opaque.')24);2526export class AgentFeedbackOverviewRulerContribution extends Disposable implements IEditorContribution {2728static readonly ID = 'agentFeedback.overviewRulerContribution';2930private readonly _decorations: IEditorDecorationsCollection;31private _sessionResource: URI | undefined;3233constructor(34private readonly _editor: ICodeEditor,35@IAgentFeedbackService private readonly _agentFeedbackService: IAgentFeedbackService,36@IChatEditingService private readonly _chatEditingService: IChatEditingService,37@ISessionsManagementService private readonly _sessionsManagementService: ISessionsManagementService,38) {39super();4041this._decorations = this._editor.createDecorationsCollection();4243this._store.add(this._agentFeedbackService.onDidChangeFeedback(() => this._updateDecorations()));44this._store.add(this._editor.onDidChangeModel(() => {45this._resolveSession();46this._updateDecorations();47}));4849this._resolveSession();50this._updateDecorations();51}5253private _resolveSession(): void {54const model = this._editor.getModel();55if (!model) {56this._sessionResource = undefined;57return;58}59this._sessionResource = getSessionForResource(model.uri, this._chatEditingService, this._sessionsManagementService);60}6162private _updateDecorations(): void {63if (!this._sessionResource) {64this._decorations.clear();65return;66}6768const model = this._editor.getModel();69if (!model) {70this._decorations.clear();71return;72}7374const feedbackItems = this._agentFeedbackService.getFeedback(this._sessionResource);75const modelUri = model.uri.toString();7677this._decorations.set(78feedbackItems79.filter(item => item.resourceUri.toString() === modelUri)80.map(item => ({81range: item.range,82options: {83description: 'agent-feedback-overview-ruler',84overviewRuler: {85color: themeColorFromId(overviewRulerAgentFeedbackForeground),86position: OverviewRulerLane.Center,87}88}89}))90);91}9293override dispose(): void {94this._decorations.clear();95super.dispose();96}97}9899registerEditorContribution(AgentFeedbackOverviewRulerContribution.ID, AgentFeedbackOverviewRulerContribution, EditorContributionInstantiation.Eventually);100101102