hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.9k stars 394 forks source link

feat: add option for view to follow cursor #1727

Closed mcauley-penney closed 6 months ago

mcauley-penney commented 11 months ago

Creates an option to allow the custom entries view to follow the user's cursor as they type.

To enable, set

require("cmp").setup({
  view = {
    entries = {
      follow_cursor = true
    }
  }
})

Original custom view source at https://github.com/lvimuser/nvim-cmp/commit/7569056388417d887baf2e959e18a767bcfe84f1

Closes #1660

Shougo commented 11 months ago

CI seems failed.

mcauley-penney commented 11 months ago

CI seems failed.

If I'm reading the commit history correctly, that test has been failing since August 10th, so over two months. That gives me the impression that the error doesn't come from these two commits. If you believe it does and not from earlier commits, I'd like some help identifying where they come from.

Shougo commented 11 months ago

If I'm reading the commit history correctly, that test has been failing since August 10th, so over two months. That gives me the impression that the error doesn't come from these two commits. If you believe it does and not from earlier commits, I'd like some help identifying where they come from.

Oh....

So CI fix commit is needed.

mcauley-penney commented 11 months ago

Just to be clear, you'd like a CI fix in this PR? I'd argue that that's outside of the scope of this particular PR, but I'm open to trying to fix it.

Shougo commented 11 months ago

Just to be clear, you'd like a CI fix in this PR? I'd argue that that's outside of the scope of this particular PR, but I'm open to trying to fix it.

I think it should be another PR.

mcauley-penney commented 11 months ago

Okay, I can try. I am new to this code base, but I'd be open to trying to fix it and contributing to other things too. I am busy until Thursday morning. After that, I can take a look at that CI problem.

Edit: I'm working on this in #1729

Shougo commented 11 months ago

can you rebase the PR? The CI seems fixed.

mcauley-penney commented 11 months ago

@Shougo done. Thank you for orchestrating this

Edit: if this is set to be merged, I will produce documentation for it.

mcauley-penney commented 6 months ago

@hrsh7th I've seen comments saying that you are feeling cautious about integrating new features because it will increase your maintenance burden, and you are busy. I would be happy to take ownership of this feature and its resulting issues if this PR were merged, similar to how Neovim itself has owners for new features.

Shougo commented 6 months ago

The screenshot may help to understand the feature works.

mcauley-penney commented 6 months ago

No problem at all, I'd be happy to provide some GIFs. To recap, the purpose of this PR is to allow the pmenu to follow the cursor as the user types. This feature is opt-in, and the current behavior remains the default.

Current Behavior

Normally, the pmenu does not follow the user:

cmp-nocursor-customwin

Additional Behavior

Using the custom window: cmp-cursor-customwin

Using the native window: cmp-cursor-nativewin

I have been using this since I made this PR, and I personally like it a lot. Some users may like this feature because it is like VSCode's autocomplete. Again, it is opt-in, so no one has to use it if they don't want to but it gives people another option.

hrsh7th commented 6 months ago

IMO, it should be custom_entries_view only feature.

The native menu is a bit complicated, so I would like to exclude it from the list and annotate docs.

mcauley-penney commented 6 months ago

@hrsh7th I have updated the PR so that the native menu is excluded and the docs do not mention it. Please let me know if there are any other changes you would like me to make.

hrsh7th commented 6 months ago

LGTM. Thank you.

mcauley-penney commented 6 months ago

I've addressed my docs error as well as some other issues in the view docs in #1868

nyngwang commented 6 months ago

IMO, it should be custom_entries_view only feature.

What does this mean? Say I want to try the new option by this PR, then what should I do to ensure that it's only used with custom_entries_view?


OK, I found the answer. I should keep the name = 'custom' here and avoid the pointed out entries = 'native' when using with this new option:

https://github.com/hrsh7th/nvim-cmp/blob/ce16de5665c766f39c271705b17fff06f7bcb84f/lua/cmp/config/default.lua#L96-L105

mcauley-penney commented 6 months ago

This option will not do anything when used with name = 'native'. You don't necessarily have to avoid it because it just won't do anything.

That comment was left for me and was instructing me to make it so that the native view cannot use this option.