Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/contrib/agentFeedback/browser/agentFeedbackOverviewRulerContribution.ts
13401 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 { Disposable } from '../../../../base/common/lifecycle.js';
7
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
8
import { IEditorContribution, IEditorDecorationsCollection } from '../../../../editor/common/editorCommon.js';
9
import { EditorContributionInstantiation, registerEditorContribution } from '../../../../editor/browser/editorExtensions.js';
10
import { overviewRulerInfo } from '../../../../editor/common/core/editorColorRegistry.js';
11
import { OverviewRulerLane } from '../../../../editor/common/model.js';
12
import { themeColorFromId } from '../../../../platform/theme/common/themeService.js';
13
import { registerColor } from '../../../../platform/theme/common/colorRegistry.js';
14
import { localize } from '../../../../nls.js';
15
import { URI } from '../../../../base/common/uri.js';
16
import { IAgentFeedbackService } from './agentFeedbackService.js';
17
import { IChatEditingService } from '../../../../workbench/contrib/chat/common/editing/chatEditingService.js';
18
import { getSessionForResource } from './agentFeedbackEditorUtils.js';
19
import { ISessionsManagementService } from '../../../services/sessions/common/sessionsManagement.js';
20
21
const overviewRulerAgentFeedbackForeground = registerColor(
22
'editorOverviewRuler.agentFeedbackForeground',
23
overviewRulerInfo,
24
localize('editorOverviewRuler.agentFeedbackForeground', 'Editor overview ruler decoration color for agent feedback. This color should be opaque.')
25
);
26
27
export class AgentFeedbackOverviewRulerContribution extends Disposable implements IEditorContribution {
28
29
static readonly ID = 'agentFeedback.overviewRulerContribution';
30
31
private readonly _decorations: IEditorDecorationsCollection;
32
private _sessionResource: URI | undefined;
33
34
constructor(
35
private readonly _editor: ICodeEditor,
36
@IAgentFeedbackService private readonly _agentFeedbackService: IAgentFeedbackService,
37
@IChatEditingService private readonly _chatEditingService: IChatEditingService,
38
@ISessionsManagementService private readonly _sessionsManagementService: ISessionsManagementService,
39
) {
40
super();
41
42
this._decorations = this._editor.createDecorationsCollection();
43
44
this._store.add(this._agentFeedbackService.onDidChangeFeedback(() => this._updateDecorations()));
45
this._store.add(this._editor.onDidChangeModel(() => {
46
this._resolveSession();
47
this._updateDecorations();
48
}));
49
50
this._resolveSession();
51
this._updateDecorations();
52
}
53
54
private _resolveSession(): void {
55
const model = this._editor.getModel();
56
if (!model) {
57
this._sessionResource = undefined;
58
return;
59
}
60
this._sessionResource = getSessionForResource(model.uri, this._chatEditingService, this._sessionsManagementService);
61
}
62
63
private _updateDecorations(): void {
64
if (!this._sessionResource) {
65
this._decorations.clear();
66
return;
67
}
68
69
const model = this._editor.getModel();
70
if (!model) {
71
this._decorations.clear();
72
return;
73
}
74
75
const feedbackItems = this._agentFeedbackService.getFeedback(this._sessionResource);
76
const modelUri = model.uri.toString();
77
78
this._decorations.set(
79
feedbackItems
80
.filter(item => item.resourceUri.toString() === modelUri)
81
.map(item => ({
82
range: item.range,
83
options: {
84
description: 'agent-feedback-overview-ruler',
85
overviewRuler: {
86
color: themeColorFromId(overviewRulerAgentFeedbackForeground),
87
position: OverviewRulerLane.Center,
88
}
89
}
90
}))
91
);
92
}
93
94
override dispose(): void {
95
this._decorations.clear();
96
super.dispose();
97
}
98
}
99
100
registerEditorContribution(AgentFeedbackOverviewRulerContribution.ID, AgentFeedbackOverviewRulerContribution, EditorContributionInstantiation.Eventually);
101
102