@@ -48,10 +48,16 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
48
48
attachedFolders : FileContext [ ] ;
49
49
version : number ;
50
50
} > ( ) ;
51
+ private hasUserManualReference = false ;
51
52
onDidContextFilesChangeEvent = this . onDidContextFilesChangeEmitter . event ;
52
53
53
54
private addFileToList ( file : FileContext , list : FileContext [ ] , maxLimit : number ) {
54
- const existingIndex = list . findIndex ( ( f ) => f . uri . toString ( ) === file . uri . toString ( ) ) ;
55
+ const existingIndex = list . findIndex (
56
+ ( f ) =>
57
+ f . uri . toString ( ) === file . uri . toString ( ) &&
58
+ f . selection ?. [ 0 ] === file . selection ?. [ 0 ] &&
59
+ f . selection ?. [ 1 ] === file . selection ?. [ 1 ] ,
60
+ ) ;
55
61
if ( existingIndex > - 1 ) {
56
62
list . splice ( existingIndex , 1 ) ;
57
63
}
@@ -85,6 +91,7 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
85
91
86
92
if ( isManual ) {
87
93
this . docModelManager . createModelReference ( uri ) ;
94
+ this . hasUserManualReference = true ;
88
95
}
89
96
90
97
this . addFileToList ( file , targetList , maxLimit ) ;
@@ -109,6 +116,7 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
109
116
cleanFileContext ( ) {
110
117
this . attachedFiles = [ ] ;
111
118
this . attachedFolders = [ ] ;
119
+ this . hasUserManualReference = false ;
112
120
this . notifyContextChange ( ) ;
113
121
}
114
122
@@ -127,6 +135,11 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
127
135
if ( index > - 1 ) {
128
136
targetList . splice ( index , 1 ) ;
129
137
}
138
+ if ( isManual ) {
139
+ if ( this . attachedFiles . length === 0 ) {
140
+ this . hasUserManualReference = false ;
141
+ }
142
+ }
130
143
this . notifyContextChange ( ) ;
131
144
}
132
145
@@ -176,14 +189,17 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
176
189
event . payload . selections [ 0 ] . positionLineNumber ,
177
190
] . sort ( ) as [ number , number ] ;
178
191
179
- if ( selection [ 0 ] === selection [ 1 ] ) {
180
- this . addFileToContext ( event . payload . editorUri , undefined , false ) ;
181
- } else {
182
- this . addFileToContext (
183
- event . payload . editorUri ,
184
- selection . sort ( ( a , b ) => a - b ) ,
185
- false ,
186
- ) ;
192
+ if ( ! this . hasUserManualReference ) {
193
+ // 当没有用户手动引用时,才自动收集
194
+ if ( selection [ 0 ] === selection [ 1 ] ) {
195
+ this . addFileToContext ( event . payload . editorUri , undefined , false ) ;
196
+ } else {
197
+ this . addFileToContext (
198
+ event . payload . editorUri ,
199
+ selection . sort ( ( a , b ) => a - b ) ,
200
+ false ,
201
+ ) ;
202
+ }
187
203
}
188
204
}
189
205
} ) ,
@@ -275,9 +291,7 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
275
291
}
276
292
277
293
return {
278
- content : ref . instance . getText (
279
- file . selection && new Range ( file . selection [ 0 ] , Infinity , file . selection [ 1 ] , Infinity ) ,
280
- ) ,
294
+ content : ref . instance . getText ( file . selection && new Range ( file . selection [ 0 ] , 0 , file . selection [ 1 ] , Infinity ) ) ,
281
295
lineErrors : this . getFileErrors ( file . uri ) ,
282
296
path : workspaceRoot . relative ( file . uri ) ! . toString ( ) ,
283
297
language : ref . instance . languageId ! ,
0 commit comments