Skip to content

Prefix in prompt component counts towards completion? #52

Open
@DrKGD

Description

@DrKGD

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions