-
Notifications
You must be signed in to change notification settings - Fork 448
feat: improve LLM context service enhance logic #4527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
9cbf8e9
bbe9031
3e0c66c
6807973
ef93e42
91eff91
90cf1d5
d88160f
e9b42d9
b78e787
a3edb91
c4c255e
1664b45
b6cc5cb
12a9683
22e2db2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,10 +48,16 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer | |||||||||
| attachedFolders: FileContext[]; | ||||||||||
| version: number; | ||||||||||
| }>(); | ||||||||||
| private hasUserManualReference = false; | ||||||||||
| onDidContextFilesChangeEvent = this.onDidContextFilesChangeEmitter.event; | ||||||||||
|
|
||||||||||
| private addFileToList(file: FileContext, list: FileContext[], maxLimit: number) { | ||||||||||
| const existingIndex = list.findIndex((f) => f.uri.toString() === file.uri.toString()); | ||||||||||
| const existingIndex = list.findIndex( | ||||||||||
| (f) => | ||||||||||
| f.uri.toString() === file.uri.toString() && | ||||||||||
| f.selection?.[0] === file.selection?.[0] && | ||||||||||
| f.selection?.[1] === file.selection?.[1], | ||||||||||
| ); | ||||||||||
| if (existingIndex > -1) { | ||||||||||
| list.splice(existingIndex, 1); | ||||||||||
| } | ||||||||||
|
|
@@ -79,6 +85,10 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer | |||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (isManual) { | ||||||||||
| this.hasUserManualReference = true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||
| const file = { uri, selection }; | ||||||||||
| const targetList = isManual ? this.attachedFiles : this.recentlyViewFiles; | ||||||||||
| const maxLimit = isManual ? this.maxAttachFilesLimit : this.maxViewFilesLimit; | ||||||||||
|
|
@@ -109,6 +119,7 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer | |||||||||
| cleanFileContext() { | ||||||||||
| this.attachedFiles = []; | ||||||||||
| this.attachedFolders = []; | ||||||||||
| this.hasUserManualReference = false; | ||||||||||
| this.notifyContextChange(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -176,14 +187,17 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer | |||||||||
| event.payload.selections[0].positionLineNumber, | ||||||||||
| ].sort() as [number, number]; | ||||||||||
|
|
||||||||||
| if (selection[0] === selection[1]) { | ||||||||||
| this.addFileToContext(event.payload.editorUri, undefined, false); | ||||||||||
| } else { | ||||||||||
| this.addFileToContext( | ||||||||||
| event.payload.editorUri, | ||||||||||
| selection.sort((a, b) => a - b), | ||||||||||
| false, | ||||||||||
| ); | ||||||||||
| if (!this.hasUserManualReference) { | ||||||||||
| // 当没有用户手动引用时,才自动收集 | ||||||||||
| if (selection[0] === selection[1]) { | ||||||||||
| this.addFileToContext(event.payload.editorUri, undefined, false); | ||||||||||
| } else { | ||||||||||
| this.addFileToContext( | ||||||||||
| event.payload.editorUri, | ||||||||||
| selection.sort((a, b) => a - b), | ||||||||||
| false, | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||
| } | ||||||||||
| }), | ||||||||||
|
|
@@ -276,7 +290,7 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer | |||||||||
|
|
||||||||||
| return { | ||||||||||
| content: ref.instance.getText( | ||||||||||
| file.selection && new Range(file.selection[0], Infinity, file.selection[1], Infinity), | ||||||||||
| file.selection && new Range(file.selection[0], 0, file.selection[1] + 1, Infinity), | ||||||||||
| ), | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Monaco 的列号从 1 开始,传入 - file.selection && new Range(file.selection[0], 0, file.selection[1] + 1, Infinity),
+ file.selection && new Range(file.selection[0], 1, file.selection[1], Infinity),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents (early access) |
||||||||||
| lineErrors: this.getFileErrors(file.uri), | ||||||||||
| path: workspaceRoot.relative(file.uri)!.toString(), | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.