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: vim.ui.input override doesn't respect opts.highlight #1023

Open
4 tasks done
diniamo opened this issue Dec 25, 2024 · 0 comments
Open
4 tasks done

bug: vim.ui.input override doesn't respect opts.highlight #1023

diniamo opened this issue Dec 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@diniamo
Copy link

diniamo commented Dec 25, 2024

Did you check docs and existing issues?

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

Neovim version (nvim -v)

0.10.2

Operating system/version

Nixos 25.05

Describe the bug

The vim.ui.input override of noice.nvim calls the highlight function passed to it, but doesn't actually apply the highlights.

Steps To Reproduce

  1. Call vim.ui.input with a highlight function
  2. Type something that should be highlighted

Expected Behavior

The text in the input field is properly highlighted

Repro

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "folke/noice.nvim",
    dependencies = {
      "MunifTanjim/nui.nvim",
      "rcarriga/nvim-notify",
    },
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here
vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])
require("noice").setup()

vim.keymap.set("n", "<space>", function()
  vim.ui.input({ prompt = "Enter lua code: ", highlight = function(input)
    local parser = vim.treesitter.get_string_parser(input, "lua")

    local tree = parser:parse()[1]
    local query = vim.treesitter.query.get("lua", "highlights")

    -- This isn't complete, but will do for our purposes
    local highlights = {}
    for id, node in query:iter_captures(tree:root(), input) do
      local _, cstart, _, cend = node:range()
      local hl = { cstart, cend, "@" .. query.captures[id] }

      if cstart >= #input then
        goto skip
      end

      for i, inner in ipairs(highlights) do
        if inner[1] < cend and inner[2] > cstart then
          highlights[i] = hl
          goto skip
        end
      end

      table.insert(highlights, hl)

      ::skip::
    end
    return highlights
  end }, function() end)
end)
@diniamo diniamo added the bug Something isn't working label Dec 25, 2024
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
Development

No branches or pull requests

1 participant