Skip to content

[bug & fix] TreeSitter Missing luadoc to Provide Correct Highlight for Lua's @diagnostic Comment #799

Closed
@Saplyn

Description

@Saplyn

Describe the bug

treesitter/highlighter will complain about Error executing lua ... on ---@diagnostic disable-next-line: duplicate-set-field and other similar doc comments.

To Reproduce

  1. Find a fresh computer that have never installed neovim, e.g. a ubuntu virtual machine (for best reproduction)
  2. Install neovim v0.9.4 via sudo snap install nvim --classic
  3. Install kickstart.nvim by flowing the instruction
  4. Open neovim, wait for plugins to install, and navigate to one of the @diagnostic doc comment
  5. Observe treesitter/highlighter complain about "Error executing lua"

Desktop

  • OS: Ubuntu 22.04 jammy
  • Terminal: zsh 5.8.1 (gnome-shell)

Neovim Version

NVIM v0.9.4
Build type: RelWithDebInfo
LuaJIT 2.1.1692716794
Compilation: /usr/bin/cc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -W
missing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/build/nvim/parts/nvim
/build/.deps/usr/include/luajit-2.1 -I/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/build/build/src/nvim/auto -I/build/nvim/parts/nvim/build/build/include -I/build/nvim/p
arts/nvim/build/build/cmake.config -I/build/nvim/parts/nvim/build/src -I/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/bui
ld/.deps/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include -I/build/nvim/parts/nvim/build/.deps/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Possible Fix

Add luadoc to the ensure_installed table (or list maybe?) of nvim-treesitter, inspired by this discourse post, and worked for me.

Specifically, the following steps helped:

  1. Add 'luadoc', to the ensure_installed
  2. Restart nvim, wait for it to finish install
  3. Then restart nvim again, navigate to one of the @diagnostic doc comment
  4. No more complains, yeah

For instance, change this line of code:

-- /init.lua 792~796
    build = ':TSUpdate',
    opts = {
--    ensure_installed = { 'bash', 'c', 'html', 'lua', 'markdown', 'vim', 'vimdoc' },
      ensure_installed = { 'bash', 'c', 'html', 'lua', 'luadoc', 'markdown', 'vim', 'vimdoc' },
      -- Autoinstall languages that are not installed
      auto_install = true,

Misc

Might be a bit irrelevant but, shall this be an issue or a pull request? Sorry but this is my first time actually have a solution to a potential problem of other's project. And if this kind of things should be a pull request, will it be suitable for me to directly open a pull request without opening an issue in the future (if I encounter the same situation again)?

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