1- import type { TextEditor , Uri } from 'vscode' ;
2- import { window } from 'vscode' ;
1+ import type { Disposable , TextEditor , Uri } from 'vscode' ;
2+ import { window , workspace } from 'vscode' ;
33import type { AIFeedbackEvent , AIFeedbackUnhelpfulReasons , Source } from '../constants.telemetry' ;
44import type { Container } from '../container' ;
55import type { AIResultContext } from '../plus/ai/aiProviderService' ;
@@ -12,6 +12,7 @@ import type { Deferrable } from '../system/function/debounce';
1212import { debounce } from '../system/function/debounce' ;
1313import { filterMap , map } from '../system/iterable' ;
1414import { Logger } from '../system/logger' ;
15+ import { createDisposable } from '../system/unifiedDisposable' ;
1516import { ActiveEditorCommand } from './commandBase' ;
1617import { getCommandUri } from './commandBase.utils' ;
1718
@@ -45,6 +46,31 @@ export class AIFeedbackUnhelpfulCommand extends ActiveEditorCommand {
4546
4647type UnhelpfulResult = { reasons ?: AIFeedbackUnhelpfulReasons [ ] ; custom ?: string } ;
4748
49+ let _documentCloseTracker : Disposable | undefined ;
50+ const _markdownDocuments = new Map < string , AIResultContext > ( ) ;
51+ export function getMarkdownDocument ( documentUri : string ) : AIResultContext | undefined {
52+ return _markdownDocuments . get ( documentUri ) ;
53+ }
54+ export function setMarkdownDocument ( documentUri : string , context : AIResultContext , container : Container ) : void {
55+ _markdownDocuments . set ( documentUri , context ) ;
56+
57+ if ( ! _documentCloseTracker ) {
58+ _documentCloseTracker = workspace . onDidCloseTextDocument ( document => {
59+ deleteMarkdownDocument ( document . uri . toString ( ) ) ;
60+ } ) ;
61+ container . context . subscriptions . push (
62+ createDisposable ( ( ) => {
63+ _documentCloseTracker ?. dispose ( ) ;
64+ _documentCloseTracker = undefined ;
65+ _markdownDocuments . clear ( ) ;
66+ } ) ,
67+ ) ;
68+ }
69+ }
70+ function deleteMarkdownDocument ( documentUri : string ) : void {
71+ _markdownDocuments . delete ( documentUri ) ;
72+ }
73+
4874const uriResponses = new UriMap < AIFeedbackEvent [ 'sentiment' ] > ( ) ;
4975let _updateContextDebounced : Deferrable < ( ) => void > | undefined ;
5076
0 commit comments