Skip to content

feat(suggestion): operate accept when is_visible#258

Merged
AntoineGS merged 3 commits intozbirenbaum:masterfrom
LUSEDOU:master
Apr 5, 2025
Merged

feat(suggestion): operate accept when is_visible#258
AntoineGS merged 3 commits intozbirenbaum:masterfrom
LUSEDOU:master

Conversation

@LUSEDOU
Copy link
Copy Markdown
Contributor

@LUSEDOU LUSEDOU commented Dec 30, 2023

Same as #192 but applied to keymap.accept

@LUSEDOU
Copy link
Copy Markdown
Contributor Author

LUSEDOU commented Dec 30, 2023

If this PR is accepted, could I apply it to the other keymaps?

@MunifTanjim

This comment was marked as resolved.

@antonk52
Copy link
Copy Markdown

@zbirenbaum apologies for a direct ping and thanks for your work!

Can we merge this? It removes a need for users to look up things to use tab to accept suggestions. This makes the setup experience notably smoother.

@AntoineGS
Copy link
Copy Markdown
Collaborator

I'd like to test this to merge it but I can't figure out what it is solving (sorry!)
Could you walk me through the steps this will change?

@antonk52
Copy link
Copy Markdown

antonk52 commented Mar 21, 2025

this PR makes sure that the keymap used to accept suggestion is still fed to neovim if there is no completion. This is useful when you want to use for completion.

Currently if you use

require('copilot').setup({
    suggestion = {
        keymap = {
            accept = '<tab>',
        },
    },
})

You will be able to use to accept completions, but you won't be able to indent code when there's no suggested completion.

To work around this currently you have to do extra steps such as

require('copilot').setup({
    suggestion = {
        keymap = {
            accept = false,
        },
    },
})

vim.keymap.set('i', '<tab>', function()
    if require('copilot.suggestion').is_visible() then
        require('copilot.suggestion').accept()
        return '<Ignore>'
    end
    return '<tab>'
end, { expr = true, noremap = true })

This PR makes the first example work with out needing to make a custom keymap for it work.

@AntoineGS
Copy link
Copy Markdown
Collaborator

Thank you I understand now :)
It potentially comes in conflict with another change that was merged recently which triggers the suggestion if not active, so I will see how we can integrate both. As of now a configuration comes to mind.

@ikiet
Copy link
Copy Markdown

ikiet commented Apr 4, 2025

Yes, this is what I was looking for

@AntoineGS
Copy link
Copy Markdown
Collaborator

I will update the PR to match the new refactor and integrate this change (with a configuration) shortly

@AntoineGS AntoineGS merged commit 0e0630c into zbirenbaum:master Apr 5, 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

Successfully merging this pull request may close these issues.

5 participants