Duo Chat in VS Code: `/explain` without selecting code should be improved
Checklist
-
I'm using the latest version of the extension (see the latest version in the right column of this page) - Extension version: 3.99
- GitLab version: latest version, using self managed set up
Summary
On Mac, using VS Code workflow 3.99
When a user has a file open but is not highlighting any code, and they perform /explain
, the file should be explained OR an explanation to highlight should be returned.
Steps to reproduce
- Open a file with code from a supported language
/explain
What is the current bug behavior?
Response:
Unfortunately there is no code provided between the <selected_code> tags for me to explain. If the user provides a code snippet, I can try to explain what it does. Some things that would help me explain the code are:
What programming language it is written in (Python, JavaScript, etc)
Any context about what the code is trying to accomplish
Where the code snippet comes from - is it part of a larger program?
Are there any specific parts of the code that need more explanation?
Without seeing the actual code, I can only provide general tips on how I would approach explaining it. I would look at the overall logic flow, explain the purpose of key variables and functions, point out any notable syntax or patterns, and try to summarize what the code is intended to do. Code examples formatted as markdown code blocks would help illustrate my explanation. Please provide a code snippet within the <selected_code> tags for me to explain!
What is the expected correct behavior?
File to be explained OR Unfortunately there is no code provided between the <selected_code> tags for me to explain.
to be reworded to explain to the user to highlight some code.
Proposed solution
I think it makes the most sense to relay the information that can be found in docs, instead of the error that is sent back. The following should happen in the IDEs:
IF questionFormatIs(/explain <text>
OR /explain <some selected code>
OR /explain <text> <some selected code>
OR
/refactor <text>
OR /refactor <some selected code in vs-code>
OR /refactor <text> <some selected code>
OR
/tests <text>
OR /tests <some selected code in vs-code>
OR /tests <text> <some selected code>
OR
<text>
OR <text> <some selected code>
)
Continue normal chat answer generation,
ELSE
Respond with `Your request does not seems to contain code to {explain|refactor|generate tests for}. To {explain code|refactor code|generate tests for code} select the lines of code in your editor and then type the command {/explain|/refactor|/tests} in the chat. You may add additional instructions after this comment. If you have no code to select, you can also simply add the code after the command.`
Known issues with this solution
Users may write <text>
or /explain <text>
or /refactor <text>
or /tests <text>
but the text does not contain code to explain. Our validation will not catch these cases, and the chat will continue to respond Unfortunately there is no code selected between the <selected_code> tags that I can explain. I would be happy to explain any code the user provides between those tags using markdown formatting to display any code blocks. Please provide a code snippet within the tags and I will do my best to explain what it does.
The solution would be to change the chat prompts to make the chat come up with a more helpful response. This is more effort than the simple validation. We decided against this, as in the majority of cases where slash commands are used they are used without additional text. If users don't select code then they will learn that this is how the chat works and know it also when they use the slash command with additional text.
Open question
Do we implement this validation in the client or in the backend?