folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.25k stars 344 forks source link

bug: Completion doesn't trigger if abbreviation of `:Lazy` command is used #1758

Open LunarLambda opened 6 days ago

LunarLambda commented 6 days ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.11.0-dev-825+gd831392b1

Operating system/version

Arch Linux

Describe the bug

Identical bug as https://github.com/folke/trouble.nvim/issues/580, but when typing :La <tab>, or :Laz <tab>, instead of an error completion simply does not trigger at all, even though :La<cr> does open Lazy. Completion only works with :Lazy <tab>.

Steps To Reproduce

Type :Laz <tab>

Expected Behavior

Completion should work even if an abbreviated prefix of the command is used.

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
  },
})
b0ae989c commented 5 days ago

Can not reproduce. Are you sure your <Tab> key is not remapped to something else? You can check it via :imap <Tab>.

LunarLambda commented 5 days ago

Shouldn't be, it reproduced on that version of Neovim with the latest master of lazy.nvim with the repro.lua suggested by the issue template. Plus imap is for insert mode, not command line mode, iirc.

max397574 commented 5 days ago

are you sure this is a lazy bug and not upstream?

@b0ae989c he should use :cmap if at all I think you didn't see the space after the :La you don't get completions for e.g. clear, show, debug, etc

LunarLambda commented 5 days ago

It's not an upstream bug. See the trouble.nvim bug I linked in the issue, where the same thing occurs, except the completion code inside of trouble throws an error instead of doing nothing, like here.

dpetka2001 commented 3 days ago

It's the parse command

https://github.com/folke/lazy.nvim/blob/460e1cd8f24e364d54543a4b0e83f6f4ec1f65fb/lua/lazy/view/commands.lua#L147-L156

It expects to find Lazy as the first argument, which then removes it from parts and expands on the sub-commands. If we change on line 149 to be a pattern of Lazy, so for example if parts[1]:find("Laz?y?"), then it seems to work as OP wanted.

Not sure if I'm missing something with the pattern I chose. Maybe someone else can come up with a better pattern? Theoretically the pattern above would also match "Lay", but there's no such command and I didn't observe any inconsistencies when typing La <tab> or Laz <tab>.

LunarLambda commented 3 days ago

You can split it on whitespace and then do vim.startswith("Lazy", command). By reversing the argument order you're basically asking if command is a prefix of Lazy

It's already doing the split so just vim.startswith("Lazy", parts[1]) would do it.

dpetka2001 commented 3 days ago

@LunarLambda

Similarly for Trouble I believe you could do here

https://github.com/folke/trouble.nvim/blob/6efc446226679fda0547c0fd6a7892fd5f5b15d8/lua/trouble/command.lua#L10-L12

line = line:sub(1, col):match("Tr%w*%s*(.*)$")

to allow for Trouble abbreviations.

PS: I'm not experienced in programming and neither with lazy.nvim or Trouble codebases, hence I'm hesitant to create PR. I'm just leaving it here for you and Folke to see. Maybe there's a better way to do it and I'm missing something else that might create a conflict.