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

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

Closed
4 tasks done
LunarLambda opened this issue Sep 24, 2024 · 7 comments · Fixed by #1760 or #1730
Closed
4 tasks done

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

LunarLambda opened this issue Sep 24, 2024 · 7 comments · Fixed by #1760 or #1730
Labels
bug Something isn't working

Comments

@LunarLambda
Copy link
Contributor

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.11.0-dev-825+gd831392b1

Operating system/version

Arch Linux

Describe the bug

Identical bug as folke/trouble.nvim#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
  },
})
@LunarLambda LunarLambda added the bug Something isn't working label Sep 24, 2024
@b0ae989c
Copy link

b0ae989c commented Sep 24, 2024

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

@LunarLambda
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

It's the parse command

function M.parse(args)
local parts = vim.split(vim.trim(args), "%s+")
if parts[1]:find("Lazy") then
table.remove(parts, 1)
end
if args:sub(-1) == " " then
parts[#parts + 1] = ""
end
return table.remove(parts, 1) or "", parts
end

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
Copy link
Contributor Author

LunarLambda commented Sep 26, 2024

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.

LunarLambda added a commit to LunarLambda/lazy.nvim that referenced this issue Sep 27, 2024
Problem: Command completion doesn't work if the command name isn't
written in full

Solution: Use vim.startswith to check if the command is a prefix of
'Lazy'

Fixes folke#1758
@dpetka2001
Copy link
Contributor

dpetka2001 commented Sep 27, 2024

@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.

LunarLambda added a commit to LunarLambda/lazy.nvim that referenced this issue Sep 27, 2024
Problem: Command completion doesn't work if the command name isn't
written in full

Solution: Use vim.startswith to check if the command is a prefix of
'Lazy'

Fixes folke#1758
folke pushed a commit that referenced this issue Oct 2, 2024
Problem: Command completion doesn't work if the command name isn't
written in full

Solution: Use vim.startswith to check if the command is a prefix of
'Lazy'

Fixes #1758
folke pushed a commit that referenced this issue Nov 11, 2024
🤖 I have created a release *beep* *boop*
---


##
[11.14.2](v11.14.1...v11.14.2)
(2024-11-10)


### Bug Fixes

* **bootstrap:** single forward slash. Fixes
[#1747](#1747)
([aca30f6](aca30f6))
* **completion:** check if command string is a prefix of Lazy
([#1760](#1760))
([e9fd76e](e9fd76e)),
closes [#1758](#1758)
* **docs:** always update helptags for local plugins
([60cf258](60cf258))
* **luarocks:** try to install from root manifest
([#1687](#1687))
([591ef40](591ef40))
* **rocks:** add lib64 plugin directory to package.cpath
([#1717](#1717))
([80da254](80da254))
* **rockspec:** allow binary lua files. Fixes
[#1800](#1800)
([408449a](408449a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants