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

Prefix in prompt component counts towards completion? #52

Open
DrKGD opened this issue Feb 6, 2025 · 0 comments
Open

Prefix in prompt component counts towards completion? #52

DrKGD opened this issue Feb 6, 2025 · 0 comments

Comments

@DrKGD
Copy link

DrKGD commented Feb 6, 2025

Description

Prompt component works fine (I had some issues in the past where the component was not getting value updates, but probably thats on me), but I have a minor nitpick regarding the use of the prefix, as it is probably? counting (can't really confirm) towards completion (using blink.cmp), and ultimately breaks some of the sources, which then provides way different results than it should

"Some" prefixes are fine, such as spaces and :, thats my reasoning behind it, as blink.cmp treats them differently (they are probably ignored)

Repro

It is kinda hard to produce a mre as it is probably due to a conflict of two different plugins or some unknown shenanigans due to my massive configuration, but this is the easiest way I've found to reproduce the issue without altering my configuration too much

Define a test nui-component which optionally takes a prefix as parameter

function M.test(prefix)
  local n = require('nui-components')
  local renderer = n.create_renderer({
    width      = 80,
    height    = 3,
    position  = {
      col = "50%",
      row = 1,
    },
  })

  local body = function()
    return n.rows(
      n.prompt({
        autofocus    = true,
        autoresize  = false,
        size = { flex = 1 },

        window = {
          highlight = {
            FloatBorder = "NuiFloat",
            NormalFloat = "NuiText",
          }
        },

        prefix = prefix or " ",
        border_style = "rounded",
        border_label = {
          text = "Test",
          align = "left",
        },
      })
    )
  end

  renderer:render(body)
  renderer:focus()
end

Either configure blink.cmp to return specific completions for buftype/filetype or return all of them by default. For now, lets always use all of them, as ricing it isn't the purpose of the issue.

sources = {
default = {  'cmdline', 'lsp', 'path', 'buffer', 'ripgrep' },
-- ...
}

Ensure all the blink.cmp providers are configured as well AND that the completion is enabled in prompts

cmdline = {
	name = "CMD",
	module = "blink.cmp.sources.cmdline",
	score_offset = 95,
},

buffer = {
	name = "BUF",
	module = "blink.cmp.sources.buffer",
	score_offset = 95,
},

lsp = {
	name = "LSP",
	module = "blink.cmp.sources.lsp",
	score_offset = 90,
},

path = {
	name = "PATH",
	module = "blink.cmp.sources.path",
	score_offset = 25,
},

ripgrep = {
	module	= "blink-ripgrep",
	name		= "RIP",
	score_offset = 15,
}

Thus run M.test with either a prefix or not

Current Behavior

Observe how without a prefix the prompt works just fine and also provides completion for the "blink.cmdline" source

uqXHOJuL9zm7RgJt.mp4

With set prefix, the completion isn't working properly anymore (here using "prefix" as prefix), returning different results

8cjRxAfiq4exOCaC.mp4

Expected Behavior

The prefix is completly ignored towards text completion and the correct results are displayed instead

Been loving using this lib to produce my own ui,
Thanks!

NuiComponents version

main (latest) caecfe2

Neovim version

NVIM v0.11.0-dev-1613+ga66f6add29 Build type: RelWithDebInfo LuaJIT 2.1.1736781742 Run "nvim -V1 -v" for more info

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

No branches or pull requests

1 participant