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

Visual selection #734

Closed
chewcw opened this issue Jan 27, 2025 · 3 comments
Closed

Visual selection #734

chewcw opened this issue Jan 27, 2025 · 3 comments

Comments

@chewcw
Copy link

chewcw commented Jan 27, 2025

I have a keymap in visual mode to open the chat, and I need to put the visual selection to the context of the chat.

  vim.keymap.set('v', '<leader>ccd', function()
    local input = 'Explain the keyword',
    require('CopilotChat').ask(input, { selection = require('CopilotChat.select').visual })
  end)

For example I have this line of text Lorem Ipsum is simply dummy text of the printing and typesetting industry. and I highlight the dummy word and open the chat using the keymap I created earlier.

Problem:
The context is the entire line.

Expectation:
I would expect the context of the chat should be dummy.

@Infonautica
Copy link

I confirm the issue, chat uses the whole buffer instead of visual selection. These are the mappings i've tried:

Default one (according to the docs):

vim.keymap.set("v", "<leader>cg", function()
	local input = vim.fn.input("Quick Chat: ")
	if input ~= "" then
		copilot_chat.ask(input)
	end
end, { desc = "Copilot Quick Chat" })

Explicit:

vim.keymap.set("v", "<leader>cg", function()
	local input = vim.fn.input("Quick Chat: ")
	if input ~= "" then
		copilot_chat.ask(input, {
			selection = function(source)
				local copilot_chat_select = require("CopilotChat.select")
				return copilot_chat_select.visual(source) or copilot_chat_select.buffer(source)
			end,
		})
	end
end, { desc = "Copilot Quick Chat" })

@deathbeam
Copy link
Collaborator

deathbeam commented Jan 29, 2025

This is intentional for simplicity and because in different visual modes the col part of < > marks isnt really set (also AI do not rly likes to play nice when trying to replace stuff in middle of lines).

As you can see in your own PR the change is adding pretty annoying complexity with storing the mode as well, I would rather keep this as is as I think grabbing stuff from middle of lines is most of the time not super useful anyway compared to hassle of supporting it.

@chewcw
Copy link
Author

chewcw commented Jan 30, 2025

@deathbeam

I see, I briefly checked the other similar plugin provider they do the similar thing, maybe I have a more niche requirement here as I just wanted the selection to be populated to the context and don't mean to ask AI to replace anything 😝.

But instead of visual selection I think maybe the doc can be more explicit about what it does, maybe visual_line is more appropriate? I don't know. But I have my question answered, I will close this issue.

@chewcw chewcw closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants