MeanderingProgrammer / render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
1.73k stars 38 forks source link

bug: `Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:107: no parser for 'fstab' language, see :help treesitter-parsers` #101

Closed xfzv closed 3 months ago

xfzv commented 3 months ago

Neovim version (nvim -v)

NVIM v0.11.0-dev-504+gaa853f362-dirty
Build type: Release
LuaJIT 2.1.1716656478

Operating system

Linux

Terminal emulator / GUI

kitty 0.35.2

Describe the bug

I have a markdown file with a code block containing # vim: ft=fstab (which is a valid file type). This triggers the following error when opening said markdown file with markdown.nvim enabled:

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:107: no parser for 'fstab' language, see :help treesitter-parsers
stack traceback:
    [C]: in function 'error'
    /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:107: in function 'add'
    /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:111: in function 'new'
    /usr/share/nvim/runtime/lua/vim/treesitter.lua:41: in function '_create_parser'
    /usr/share/nvim/runtime/lua/vim/treesitter.lua:108: in function 'get_parser'
    ...share/nvim/lazy/markdown.nvim/lua/render-markdown/ui.lua:119: in function 'parse_buffer'
    ...share/nvim/lazy/markdown.nvim/lua/render-markdown/ui.lua:74: in function 'render'
    ...share/nvim/lazy/markdown.nvim/lua/render-markdown/ui.lua:39: in function <...share/nvim/lazy/markdown.nvim/lua/render-markdown/ui.lua:33>

To reproduce:

  1. Add # vim: ft=fstab (also occurs with # vim: ft=zzz for example) in a code block of a new markdown file
  2. Open the markdown file with markdown.nvim enabled
  3. The error is triggered

Expected behavior

No error.

Healthcheck output

==============================================================================
render-markdown: require("render-markdown.health").check()

markdown.nvim [neovim version] ~
- OK Version >= 0.10

markdown.nvim [configuration] ~
- OK valid

markdown.nvim [nvim-treesitter] ~
- OK installed
- OK markdown: parser installed
- OK markdown: highlight enabled
- OK markdown_inline: parser installed
- OK markdown_inline: highlight enabled
- WARNING latex: parser not installed
  - ADVICE:
    - Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

markdown.nvim [executables] ~
- WARNING latex2text: not installed
  - ADVICE:
    - Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

markdown.nvim [conflicts] ~
- OK headlines: not installed
- OK obsidian: not installed

Plugin configuration

return {
  "MeanderingProgrammer/markdown.nvim",
  ft = "markdown",
  opts = {},
}

Confirmations

Additional information

No response

MeanderingProgrammer commented 3 months ago

Since the filetype gets overridden to fstab and there is no parser defined by treesitter for this filetype I wouldn't expect it to work. This type of setup creates 2 FileType events, the first one for markdown causes this plugin to attempt to parse the file. However when we later attempt to get the parser, treesitter only picks up the fstab filetype and fails.

I have pushed a fix to avoid errors in these cases: https://github.com/MeanderingProgrammer/markdown.nvim/commit/ddb454792dd85c0f6039ec14006aecaee67e782d.

So at least it won't break but it also won't do any rendering, effectively becomes a no-op. If you want this plugin to render fstab as it would markdown you'll need to add the following somewhere in your config:

vim.treesitter.language.register('markdown', 'fstab')

Which tells treesitter to parse fstab files as if they were markdown. Similar for all other filetypes you want to treat as markdown. This will change the highlighting behavior for all of these filetypes.

xfzv commented 3 months ago

Thank you for the detailed explanation!