RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.14k stars 47 forks source link

No references provided by lsp provider for tex filetype, does not fall back to treesitter or regex #203

Closed cscherrNT closed 3 weeks ago

cscherrNT commented 4 weeks ago

Describe the bug I am currently writing a latex document. I use two language-servers for latex: ltex and texlab. None of them seem to provide illuminate with references. I'd like to use regex instead, but changing providers seems not to be possible.

My providers are set up like this, which works really well for regular programming:

providers = {
  'lsp', -- useless for tex but still used
  'treesitter',
  'regex',
},

Therefore, LSP is always priorized, even if regex would be more useful.

To Reproduce Steps to reproduce the behavior (include minimal init.vim or .vimrc):

  1. Set up ltex & texlab (not clear which causes this, or if both do together). A minimal example can be found further below
  2. Open a latex file (example provided further below)
  3. No references will be highlighted (there are none according to the lsp provider)
  4. Jumping between references with <A-n> is not possible

Output from :IlluminateDebug

buf_should_illuminate 12 true
config {
  case_insensitive_regex = false,
  delay = 200,
  filetype_overrides = {},
  filetypes_allowlist = {},
  filetypes_denylist = { "DiffviewFileHistory", "DiffviewFiles", "SidebarNvim", "fugitive", "git", "minifiles", "neo-tree", "NvimTree_1", "dashboard" },
  large_file_cutoff = 50000,
  min_count_to_highlight = 1,
  modes_allowlist = { "n", "no", "nt" },
  modes_denylist = {},
  providers = { "lsp", "treesitter", "regex" },
  providers_regex_syntax_allowlist = {},
  providers_regex_syntax_denylist = {},
  under_cursor = true
}
started true
provider table: 0x7f395b0557c0 lsp
`termguicolors` true

Expected behavior Either switch automatically to the next provider if no references are given from the language server, or add the possibility to change providers, so that users can make an autocommand to do so.

Additional context

As requested, here is a minimal `init.lua` that just installs illuminate and sets up texlab and ltex. With this, open a latex document. Illuminate will not have references. ```lua -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, { out, "WarningMsg" }, { "\nPress any key to exit..." }, }, true, {}) vim.fn.getchar() os.exit(1) end end vim.opt.rtp:prepend(lazypath) -- Setup lazy.nvim require("lazy").setup({ { { "RRethy/vim-illuminate", lazy = false, event = { "BufReadPost", "BufNewFile" }, opts = { -- providers: provider used to get references in the buffer, ordered by priority providers = { "lsp", -- useless for tex but still used "treesitter", "regex", }, large_file_cutoff = 50000, delay = 200, under_cursor = true, modes_allowlist = { "n", "no", "nt" }, }, }, { { "neovim/nvim-lspconfig", dependencies = { { "williamboman/mason.nvim", config = true }, "williamboman/mason-lspconfig.nvim", "WhoIsSethDaniel/mason-tool-installer.nvim", }, config = function() local servers = { texlab = {}, ltex = { use_spellfile = false, settings = { ltex = { checkFrequency = "save", language = "auto", enabled = { "bibtex", "tex", "latex", "markdown", }, }, }, }, } require("mason").setup() local ensure_installed = vim.tbl_keys(servers or {}) require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) local capabilities = vim.lsp.protocol.make_client_capabilities() require("mason-lspconfig").setup({ handlers = { function(server_name) local server = servers[server_name] or {} server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) require("lspconfig")[server_name].setup(server) end, }, }) end, }, }, }, }) ```

Example .tex file

\section{Test}

Word other word word word other
RRethy commented 3 weeks ago

None of them seem to provide illuminate with references

One of them must be reporting that it supports textDocument/documentHighlight which is why it is being used.

You can use filetype_overrides to override latex files.

cscherrNT commented 3 weeks ago

Ah, I see it now. Perhaps it would be helpful to add an override to the examples in the documentation? Thank you.