nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.36k stars 823 forks source link

Custom highlights (java file) not applied in preview window #2767

Open idelice opened 10 months ago

idelice commented 10 months ago

Description

I have applied some custom highlight in my lazy.lua file using LazyVim, but they are not applied to the preview window using Telescope. Here's my `/config/options/ file:

local highlight_definitions = {
  ["JavaVarHighlight"] = { fg = keyword },

  ["@lsp.type.annotation.java"] = { fg = yellowAnnotation },
  ["@lsp.type.class.java"] = { fg = light },
  ["@lsp.type.interface.java"] = { fg = light },
  ["@lsp.type.property.java"] = { fg = purple },
  ["@lsp.type.enum.java"] = { fg = light },
  ["@lsp.type.enumMember.java"] = { fg = light },
  ["@lsp.type.namespace.java"] = { fg = light },
  ["@lsp.type.parameter.java"] = { fg = light },
  ["@lsp.type.method.java"] = { fg = light },
  ["@lsp.type.variable.java"] = { fg = light },
  ["@lsp.type.keyword.java"] = { fg = keyword },
  ["@lsp.typemod.parameter.declaration.java"] = { fg = light },
  ["@lsp.typemod.variable.declaration.java"] = { fg = light },
  ["@lsp.typemod.class.importDeclaration.java"] = { fg = light },
  ["@lsp.typemod.method.declaration.java"] = { fg = methodName },
  ["@lsp.typemod.enumMember.static.java"] = { fg = purple },

  ["@type.java"] = { fg = keyword },
  ["@type.qualifier.java"] = { fg = keyword },
  ["@type.builtin.java"] = { fg = keyword },

  ["@punctuation.bracket.java"] = { fg = light },
  ["@punctuation.delimiter.java"] = { fg = light },

  ["@keyword.java"] = { fg = keyword },
  ["@keyword.operator.java"] = { fg = keyword },
  ["@keyword.return.java"] = { fg = keyword },

  ["@variable.builtin.java"] = { fg = keyword },
  ["@constant.builtin.java"] = { fg = keyword },

  ["@operator.java"] = { fg = light },
  ["@string.escape.java"] = { fg = keyword },
  ["@method.call.java"] = { bold = false },
  ["@method.java"] = { bold = false },
  ["@conditional.java"] = { fg = keyword },
  ["@exception.java"] = { fg = keyword },
  ["@include.java"] = { fg = keyword },
  ["@boolean.java"] = { fg = keyword },
  ["@number.java"] = { fg = integerBlue },
  ["@repeat.java"] = { fg = keyword },
  ["@string.java"] = { fg = stringGreen },
  ["@attribute.java"] = { fg = yellowAnnotation },
}

local function apply_my_highlights()
  print("Applying highlights")  -- Debug

  for group, settings in pairs(highlight_definitions) do
    local highlight_cmd = "hi " .. group
    for setting, value in pairs(settings) do
      if setting == "fg" then
        setting = "guifg"
      elseif setting == "bg" then
        setting = "guibg"
      elseif setting == "bold" then
        setting = value and "gui=bold" or "gui=NONE"
        highlight_cmd = highlight_cmd .. " " .. setting
        goto continue
      end
      highlight_cmd = highlight_cmd .. " " .. setting .. "=" .. value
      ::continue::
    end
    vim.cmd(highlight_cmd)
  end
end

apply_my_highlights()

Neovim version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.1/share/nvim"

Operating system and version

macOs 13.4.1 (c) (22F770820d)

Telescope version / branch / rev

latest

checkhealth telescope

telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.7.0

===== Installed extensions ===== ~

Telescope Extension: `changed_files` ~
- No healthcheck provided

Telescope Extension: `env` ~
- No healthcheck provided

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Telescope Extension: `harpoon` ~
- No healthcheck provided

Telescope Extension: `live_grep_args` ~
- No healthcheck provided

Telescope Extension: `make` ~
- No healthcheck provided

Telescope Extension: `media_files` ~
- No healthcheck provided

Telescope Extension: `neoclip` ~
- No healthcheck provided

Telescope Extension: `notify` ~
- No healthcheck provided

Telescope Extension: `projects` ~
- No healthcheck provided

Telescope Extension: `undo` ~
- No healthcheck provided

Steps to reproduce

  1. Use LazyVim distro
  2. update config/options with what I have provided
  3. install jdtls
  4. open java file
  5. open telescope and look at preview window

Expected behavior

I expect my custom highlights are applied in the preview window

Actual behavior

Default highlights are applied

Minimal config

n/a
jamestrew commented 10 months ago

Can you provide a minimal config showcasing this is actually a telescope issue? I can't really afford to debug everyone's config. And the snippet provided isn't even something I can directly copy-paste into my config.

idelice commented 10 months ago

What I'm missing is configurating telescope to apply the custom highlights that I've applied.

Can you show me a quick example on how to apply highlights using telescope builtin preview config?

jamestrew commented 10 months ago

I think generally people just stick with colorschemes or colorscheme builders for more custom stuff. Theoretically, your code looks fine to me at first glance but it's hard to say why telescope's buffer previewer isn't respecting it without more context behind the rest of your config.

Here's a minimal config I've created to replicate what I think you're looking to accomplish. I'm using lua instead of java since I don't have a treesitter parser for java. You can play around with the color but it looks like telescope is respecting the custom color so I suspect the issue is with your configuration rather than telescope. Unfortunately, I can't help you much there without more context.

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",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-web-devicons",
    },
    config = function()
      require("telescope").setup()
    end,
  },
  {
    "nvim-treesitter/nvim-treesitter",
    config = function()
      require("nvim-treesitter.configs").setup({
        highlight = {
          enable = true,
        },
      })
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.opt.termguicolors = true
vim.cmd.colorscheme("habamax")
vim.cmd("hi @variable.lua guifg=red")