nvim-treesitter
nvim-treesitter copied to clipboard
`markdown_fenced_languages` not used in Markdown
Before reporting
- [X] I have updated my neovim version to latest master
- [X] I have updated my plugin to the latest version
- [X] I have run
:TSUpdate - [X] I have read the troubleshooting section
Describe the bug
With:
let g:markdown_fenced_languages = [
\ 'bash=sh', 'javascript', 'js=javascript', 'json=javascript', 'typescript',
\ 'ts=typescript', 'php', 'html', 'css', 'rust', 'sql']
```ts
should enable code highlighting the same as:
```typescript
but ts has no highlighting, as if it were just:
```
I can now delete the whole markdown_fenced_languages section. I always thought it was a waste of space, but it would be nice to alias ts=typescript by default as it seems common.
To Reproduce
```ts
should enable code highlighting the same as:
```typescript
Expected behavior
No response
Output of :checkhealth nvim-treesitter
nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
- WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK: `node` found v16.8.0 (only needed for :TSInstallFromGrammar)
- OK: `git` executable found.
- OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)
- OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.
## Parser/Features H L F I J
- markdown ✓ . . . ✓
- css ✓ . ✓ ✓ ✓
- javascript ✓ ✓ ✓ ✓ ✓
- typescript ✓ ✓ ✓ ✓ ✓
- c ✓ ✓ ✓ ✓ ✓
- json ✓ ✓ ✓ ✓ .
- vim ✓ ✓ . . ✓
- jsdoc ✓ . . . .
- rust ✓ ✓ ✓ ✓ ✓
- lua ✓ ✓ ✓ ✓ ✓
- bash ✓ ✓ ✓ . ✓
- jsonc ✓ ✓ ✓ ✓ ✓
- html ✓ ✓ ✓ ✓ ✓
- tsx ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
Output of nvim --version
NVIM v0.6.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az65-618
Additional context
No response
One suggestion was to do https://github.com/nvim-treesitter/nvim-treesitter/pull/1240 . In my opinion too complicated: we only need a configurable mapping abbreviation -> ft . I think a good solution would be if nvim core would use https://github.com/neovim/neovim/pull/16600 for injections.
https://github.com/neovim/neovim/pull/16600#event-5836959427 has been merged and could be used to support this feature.
Hopefully this is not too off-topic, but I wonder why this option (i.e. markdown_fenced_languages) is needed in the first place? Shouldn't nvim be able to figure out the language of the fenced code block and apply the proper syntax highlighting if possible automatically? Is there a downside of adding all supported languages in markdown_fenced_languages by default?
markdown_fenced_languages is not used and from my opinion it shouldn't be used. The new filetype Lua module is a promising option which might be soon able to tell the filetype from an abbreviation like the extension thanks to recent refactorings and un-vimifcation from contributors like @clason . Then, something like this might be possible in future: https://github.com/neovim/neovim/pull/15723, but implemented in a proper way.
I would also accept PRs with temporal solutions that would vendor one of the extension list in core or plenary to make the markdown filetype detection more complete.
I just stumbled upon this and thought it's an issue with the markdown parser so opened an issue there: https://github.com/MDeiml/tree-sitter-markdown/issues/42 but got sent here instead. I have no idea about the inner workings, but it seems weird that vim handles highlighting of code files just fine no matter whether I set the filetype to bash or sh but then doesn't handle the same thing in markdown?
@theHamsta Hi bro if I omit markdown_fenced_languages would it mean that all filetypes are detected automatically? At current HEAD of nvim.
@nyngwang You won't know until you try