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' ;
3
3
import type { AIFeedbackEvent , AIFeedbackUnhelpfulReasons , Source } from '../constants.telemetry' ;
4
4
import type { Container } from '../container' ;
5
5
import type { AIResultContext } from '../plus/ai/aiProviderService' ;
@@ -12,6 +12,7 @@ import type { Deferrable } from '../system/function/debounce';
12
12
import { debounce } from '../system/function/debounce' ;
13
13
import { filterMap , map } from '../system/iterable' ;
14
14
import { Logger } from '../system/logger' ;
15
+ import { createDisposable } from '../system/unifiedDisposable' ;
15
16
import { ActiveEditorCommand } from './commandBase' ;
16
17
import { getCommandUri } from './commandBase.utils' ;
17
18
@@ -45,6 +46,31 @@ export class AIFeedbackUnhelpfulCommand extends ActiveEditorCommand {
45
46
46
47
type UnhelpfulResult = { reasons ?: AIFeedbackUnhelpfulReasons [ ] ; custom ?: string } ;
47
48
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
+
48
74
const uriResponses = new UriMap < AIFeedbackEvent [ 'sentiment' ] > ( ) ;
49
75
let _updateContextDebounced : Deferrable < ( ) => void > | undefined ;
50
76
0 commit comments