Skip to content
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

Use correct file sources instead of always showing 'embeddings' in chat context #2408

Merged
merged 12 commits into from
Jan 8, 2024
2 changes: 2 additions & 0 deletions lib/shared/src/codebase-context/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Message } from '../sourcegraph-api'
// user: context file provided by the user explicitly via chat input
// keyword: the context file returned from local keyword search
// editor: context file retrieved from the current editor
// search: context file returned by symf search
// selection: selected code from the current editor
// terminal: output from shell terminal
export type ContextFileSource =
Expand All @@ -16,6 +17,7 @@ export type ContextFileSource =
| 'keyword'
| 'editor'
| 'filename'
| 'search'
| 'unified'
| 'selection'
| 'terminal'
Expand Down
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a

### Fixed

- Chat no longer shows "embeddings" as the source for all automatically included context files [issues/2244](https://github.com/sourcegraph/cody/issues/2244)/[pull/2408](https://github.com/sourcegraph/cody/pull/2408)
- Display the source and range of enhanced context correctly in UI. [pull/2542](https://github.com/sourcegraph/cody/pull/2542)
- Context from directory for commands and custom commands now shows up correctly under enhanced context. [issues/2548](https://github.com/sourcegraph/cody/issues/2548)/[pull/2542](https://github.com/sourcegraph/cody/pull/2542)
- @-mentioning the same file a second time in chat no longer duplicates the filename prefix [issues/2243](https://github.com/sourcegraph/cody/issues/2243)/[pull/2474](https://github.com/sourcegraph/cody/pull/2474)
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/chat/chat-view/SimpleChatPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export class SimpleChatPanelProvider implements vscode.Disposable {
const displayText = userContextFiles?.length
? createDisplayTextWithFileLinks(userContextFiles, inputText)
: command
? createDisplayTextWithFileSelection(inputText, await this.editor.getActiveTextEditorSmartSelection())
? createDisplayTextWithFileSelection(inputText, this.editor.getActiveTextEditorSelectionOrEntireFile())
: inputText
// The text we will use to send to LLM
const promptText = command ? [command.prompt, command.additionalInput].join(' ')?.trim() : inputText
Expand Down Expand Up @@ -1270,6 +1270,7 @@ class ContextProvider implements IContextProvider {
return {
uri: displayUri,
range,
source: 'search',
text,
}
})
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/chat/chat-view/chat-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ describe('unwrap context snippets', () => {
contextItem: {
uri: vscode.Uri.file('test.ts'),
range: new vscode.Range(0, 1, 2, 3),
source: 'editor',
text: '// This is code context',
},
},
{
contextItem: {
uri: vscode.Uri.file('doc.md'),
range: new vscode.Range(0, 1, 2, 3),
source: 'editor',
text: 'This is markdown context',
},
},
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/chat/chat-view/chat-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export function contextMessageToContextItem(contextMessage: ContextMessage): Con
uri:
contextMessage.file.uri ||
legacyContextFileUri(contextMessage.file.fileName, activeEditorSelectionRangeToRange(range)),
source: contextMessage.file.source,
range: range && new vscode.Range(range.start.line, range.start.character, range.end.line, range.end.character),
}
}
Expand Down Expand Up @@ -211,7 +212,7 @@ export function contextItemsToContextFiles(items: ContextItem[]): ContextFile[]
}
contextFiles.push({
uri: item.uri,
fileName: createVSCodeRelativePath(item.uri),
fileName: createVSCodeRelativePath(item.uri) || relFsPath,
source: item.source || 'embeddings',
range: rangeToActiveTextEditorSelectionRange(item.range),
content: item.text,
Expand Down
Loading