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
Context: Update code template for selection #4123
Conversation
@@ -48,29 +49,17 @@ export function populateTerminalOutputContextTemplate(output: string): string { | |||
return COMMAND_OUTPUT_TEMPLATE + output | |||
} | |||
|
|||
const SELECTED_CODE_CONTEXT_TEMPLATE = ps`My selected {languageName} code from file \`{filePath}\`: | |||
<selected> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced this with triple backticks because this doesn't work well with HTML code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes sense! We don't want to add a lot of magic especially when no enhanced context is used but I feel like having text selected should intuitively be added.
Maybe an alternative could be that we show UI in the chat message when text is added to quickly add the range to the input if people feel strongly we shouldn't do that?
public static fromDisplayPathLineRange(uri: vscode.Uri, range?: RangeData) { | ||
const pathToDisplay = range ? displayPathWithLines(uri, range) : displayPath(uri) | ||
return internal_createPromptString(pathToDisplay, [uri]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
if (await contextFiltersProvider.isUriIgnored(document.uri)) { | ||
return [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
@@ -28,7 +28,7 @@ | |||
} | |||
}, | |||
"countDirFiles": { | |||
"prompt": "How many file context have I shared with you?", | |||
"prompt": "How many file context have I shared with you? Reply single number. Skip preamble.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to keep the output minimal so we don't have to keep updating the test for a response with word changes
CONTEXT: https://sourcegraph.slack.com/archives/C04MSD3DP5L/p1715260595763899
This PR updates the code template we are using for selected code to include line numbers after the file path, aiming to fix the issue where Cody would answer the questions using the wrong section of code if the user mentions line number in their question:
Changes
getContextFileFromSelection
function inselection.ts
to retrieve the user's current selection as a context itemSimpleChatPanelProvider
to callgetContextFileFromSelection
and include the selection context inuserContextFiles
populateCurrentSelectedCodeContextTemplate
intemplates.ts
to accept an optionalrange
parameter and usedisplayPathWithLines
to include the selected line range in the file pathdisplayPathWithLines
function indisplayPath.ts
to format the file path with the selected line rangePromptString
to includefromDisplayPathLineRange
method for creating prompt strings with line rangesDefaultPrompter
and remove theIPrompter
interfacerenderContextItem
inutils.ts
to handle different context item sources and use appropriate templatesgetContextItemDisplayPath
function inutils.ts
to get the display path for a context itemTest plan
Manual Test: updated code template
To test the code template change:
what does the code in line 50-58 do?
Example: highlight SimpleChatPanelProvider.ts?L475-568 and ask Cody about L482-485.
The code in the given lines is:
Before
Updated
Since I haven't heard back from the team, I have reverted my change on adding editor selection as context: https://sourcegraph.slack.com/archives/C05AGQYD528/p1715373199246709
The changes listed below are no longer relevant and can be ignored. Just keep it for record purpose :)
Updated to include editor selection automatically for chat even if enhanced context is disabled, as this seems to be the expected behavior for new users, but I'm happy to remove it if the team disagrees. Currently, Cody is not able to answer questions about your editor selection if you disable enhanced context:
Goals
Manual Test 2: add editor selection as context with enhanced context disabled
To test the change on adding editor selection as context:
Before