-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fixed unwantted selecting behavior for send-to-chat #4515
base: main
Are you sure you want to change the base?
Fixed unwantted selecting behavior for send-to-chat #4515
Conversation
✅ Deploy Preview for continuedev canceled.
|
Hmm, this entirely bypasses the code in
But I think that code does have a point - if you select with shift-downarrow, it's easy to get a selection that includes the first line without the whitespace, and the rest of the lines with the whitespace: In that case, we don't want to send to the model:
Probably that code needs to be fancier - to check if the text at the beginning of the first line is all whitespace and only then adjust the first line boundary to be the start of the line. |
a913098
to
9ca0f55
Compare
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 looks good to me now, but I think there are a few changes additional changes that could be done to tighten up the code and make it more readable.
extensions/vscode/src/commands.ts
Outdated
@@ -150,6 +183,10 @@ function getRangeInFileWithContents( | |||
async function addHighlightedCodeToContext( | |||
webviewProtocol: VsCodeWebviewProtocol | undefined, | |||
) { | |||
const editor = vscode.window.activeTextEditor; | |||
if (!editor) { | |||
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.
This doesn't look necessary - getRangeInFileWithContents() already handles that.
extensions/vscode/src/commands.ts
Outdated
const beginningOfSelectionStartLine = new vscode.Position( | ||
selection.start.line, | ||
0, | ||
); |
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.
There's a little compression we can do here:
const beginningOfSelectionStartLine = selection.start.with(undefined, 0);
extensions/vscode/src/commands.ts
Outdated
beginningOfSelectionStartLine, | ||
selection.start, | ||
); | ||
const contextBeforeSelectionStart = document.getText( |
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.
I think this is just "text" not "context". I also think it would be clearer not to have the rangeBeforeSelectionStart variable and just create the range inline.
extensions/vscode/src/commands.ts
Outdated
selectionRange = new vscode.Range( | ||
new vscode.Position(selection.start.line, 0), | ||
selection.end, | ||
); |
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.
Writing it this way makes it not clear that we're just adjusting the start position of selectionRange -range also has a with()
-
selectionRange = selectionRange.with({ start: beginningOfSelectionStartLine });
would be clearer.
9ca0f55
to
24ebc7a
Compare
Looks good to me now! |
The original behavior selects the entire first line even though it's only partially selected in the editor. This fix is to get rid of the extra selection from the first line and only send the exact part that gets selected in the editor to the chat section. However, there is an exception that if the context before the start of the selection contains only whitespace, we want to include the wihitespace into the selection because it's the indentation. Granite-Code/granite-code#43
24ebc7a
to
67957e2
Compare
Description
The original behavior selects the entire first line even though it's only partially selected in the editor. This fix is to get rid of the extra selection from the first line and only send the exact part that gets selected in the editor to the chat section. Granite-Code/granite-code#43
Testing instructions
Partially select the first line and then Cmd-L, check if code snippet appearing in the chat section display the exact part you select in the editor.