sourcegraph / cody

AI that knows your entire codebase
https://cody.dev
Apache License 2.0
2.24k stars 213 forks source link

chat: always use range if there is an active selection #4658

Closed keegancsmith closed 1 week ago

keegancsmith commented 1 week ago

For the auto-updating "Current File" context we only made it a "Current Selection" if the selection was multi-line. I am unsure why we had this behaviour, this seems more correct.

I came across this while looking into https://linear.app/sourcegraph/issue/CODY-2276/buggy-line-range-logic-for-open-files-in-new-chat

Test Plan: loads of testing with selecting. See video.

https://github.com/sourcegraph/cody/assets/187831/01ad21d0-6e14-4dfa-a2d2-9485f2cea51b

keegancsmith commented 1 week ago

The reasoning for treating a single-line selection as meaning "use whole file context" is that it's really unlikely you just want a single line of context. But I can see that this is confusing, so this change is fine and makes sense.

I thought that might be the case for multiline. In my case I would very rarely have code accidentally highlighted, so thought this was the better principle. But I am a sample size of one, so if you think we should keep the current behaviour I get that too.

keegancsmith commented 1 week ago

Alright on the linear issue Tim gives this change a thumbs up. So gonna merge :)

toolmantim commented 1 week ago

The reasoning for treating a single-line selection as meaning "use whole file context" is that it's really unlikely you just want a single line of context.

@sqs multiple times I've just selected a part of a line and gone to ask "is there a shorthand for this?" in chat and it didn't work… that was why I originally raised it

toolmantim commented 1 week ago

@sqs I'm curious why you think that's unlikely in general though!