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

Cmdline completions #323

Merged
merged 8 commits into from
Dec 12, 2024
Merged

Cmdline completions #323

merged 8 commits into from
Dec 12, 2024

Conversation

Saghen
Copy link
Owner

@Saghen Saghen commented Nov 12, 2024

Adds a new cmdline source based on https://github.com/hrsh7th/cmp-cmdline and sources.cmdline for configuring cmdline sources

Closes #138

image

@Saghen Saghen marked this pull request as draft November 12, 2024 16:49
@lopi-py
Copy link
Contributor

lopi-py commented Nov 13, 2024

What's the purpose of x.enabled_providers?

sources = {
  editor/cmdline = {
    enabled_providers = { "cmdline" },
  },
},

and not something like (I think this is more ergonomic)

sources = {
  editor/cmdline = { "cmdline" },
},

This might be a more personal preference, but I think its okay to have completion instead of editor

@Saghen
Copy link
Owner Author

Saghen commented Nov 14, 2024

Motivation was I wanted to leave space for mode specific properties, but I might end up doing that a bit differently.

Tbh I don't like either editor or completion, open to ideas for that. Maybe default global or normal

@ratheesh
Copy link

Thanks for this feature.
I see that the cmdline completions are implemented in popup menu style.
Can we have an option to show the completion candidates in the horizontal style(on the status line) like the one in wilder.nvim

@Saghen
Copy link
Owner Author

Saghen commented Nov 14, 2024

@ratheesh That's out of scope for this PR but eventually the plugin will be extensible enough that you could write this yourself if you like

@Saghen Saghen mentioned this pull request Nov 26, 2024
Saghen added a commit that referenced this pull request Nov 27, 2024
Sweeping refactor of the codebase touching just about everything: reworked config with validation, trigger, new list component for managing state, stateless windows, etc. This will set us up for cmdline completions (#323), sources v3 (keywords, async, fallback tree, ...), and documentation. After which, we can hopefully release v1
@Saghen Saghen force-pushed the cmdline-completions branch from 62f8222 to b20184f Compare December 11, 2024 21:24
@Saghen Saghen marked this pull request as ready for review December 11, 2024 21:26
@Saghen Saghen changed the title Cmdline completions Command completions Dec 11, 2024
@Saghen
Copy link
Owner Author

Saghen commented Dec 11, 2024

@folke I've added an API require('blink.cmp').set_cmdline_position(function_or_array) so that noice.nvim (and others) can tell blink.cmp where to place the window. It'd probably make sense to set this on CmdlineEnter

For now, users can do this themselves via:

completion.menu.cmdline_position = function()
  local screenpos = require('noice.api').get_cmdline_position().screenpos
  return { screenpos.row - 1, screenpos.col - 1 }
end

@Saghen Saghen changed the title Command completions Cmdline completions Dec 11, 2024
@folke
Copy link
Contributor

folke commented Dec 11, 2024

@Saghen I'm willing to add something for this, but it's probably easier if you add it in blink directly?

You can just check for package.loaded.noice. If that's not nil, then get the screenpos like you do now.
If I would have to do it, noice probably is loaded before blink, so then I need to always check for every cmdline render, or do some magic with package.preload...

That api, just returns a copy of a table, so there's no processing of any kind involved.

@Saghen
Copy link
Owner Author

Saghen commented Dec 11, 2024

@folke My thinking was plugin authors could integrate with blink without having to make a PR. And it lowers the maintenance burden on blink's side, on new plugins or when a supported plugin has breaking changes. But I'm open to putting this in blink directly if you think that's best. Btw, not sure if this is what you mean, but you could probably set just on CmdlineEnter, not on every render

@folke
Copy link
Contributor

folke commented Dec 11, 2024

I made it easier. Noice now sets vim.g.ui_cmdline_pos whenever the cmdline is opened.
This way you don't need to use any noice APIs.
Ideally there should be some sort of standard for this sort of thing for vim.ui_attach so plugins can easily cooperate.

The screen position is (1-0)-indexed like cursors.

This would make it also easier for other plugins that want to integrate with blink. They just need to set that global.

@Saghen
Copy link
Owner Author

Saghen commented Dec 12, 2024

That's even better, thank you!

@Saghen Saghen merged commit 414d615 into main Dec 12, 2024
2 checks passed
@Saghen Saghen deleted the cmdline-completions branch December 12, 2024 15:42
@folke
Copy link
Contributor

folke commented Dec 12, 2024

Looks like noice's cmdline pos was actually (1-1)-indexed, so I just fixed that.

I also wanted the global to be number[], but instead I made it {row:number, col:number}.
And Neovim does not allow both string and integer indices.

Can you make a small update to your code to support both formats and then let me know, so I can switch to the
number indexed way?

Otherwise blink/noice would break for users.

Ty!

@folke
Copy link
Contributor

folke commented Dec 12, 2024

Also, really cool the new cmdline completions!

@Saghen
Copy link
Owner Author

Saghen commented Dec 12, 2024

Can you make a small update to your code to support both formats and then let me know, so I can switch to the
number indexed way?

I've switched it to use the new number[] although I didn't keep support for the old .col/row since I haven't made a release with this code yet

@folke
Copy link
Contributor

folke commented Dec 12, 2024

Great, also changed on the noice side. ty!

@fabiomcosta
Copy link

fabiomcosta commented Dec 21, 2024

is it possible to keep expanding "%" to the current file path when pressing tab?
This is currently not working and I'm having a hard time understanding how to fix that through a config change

Repro steps:

  • open cmdline
  • type e % then tab
  • % should be replaced by the path of the current file, but it doesn't

I tried changing keymap.preset to different values and none work.

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.

Command mode completion
5 participants