Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve parser lang when different from filetype #14

Closed
wants to merge 1 commit into from
Closed

Resolve parser lang when different from filetype #14

wants to merge 1 commit into from

Conversation

Gelio
Copy link

@Gelio Gelio commented Jun 11, 2022

Use nvim-treesitter API to resolve the parser language when it is different than the buffer's filetype.

This happens for tsx files whose filetype is typescriptreact but the Treesitter parser language is tsx. The mapping of filetypes and parser languages is stored in nvim-treesitter.

PR #4 fixed that problem before. It seems that the solution stopped working over time.

Closes #17

Before (on master)

Peek.2022-06-11.11-02.mp4
E5108: Error executing lua ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:25: no parser for
 'typescriptreact' language, see :help treesitter-parsers
stack traceback:
        [C]: in function 'error'
        ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:25: in function 'require_language'
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:39: in function '_create_parser'
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:98: in function 'get_parser'
        ...nvim/site/pack/packer/start/nvim-treehopper/lua/tsht.lua:53: in function 'nodes'
        [string ":lua"]:1: in main chunk
Press ENTER or type command to continue

After

Peek.2022-06-11.11-01.mp4

Use nvim-treesitter API to resolve the parser language when it is
different than the buffer's `filetype`.

This happens for `tsx` files whose `filetype` is `typescriptreact` but
the Treesitter parser language is `tsx`. The mapping of filetypes and
parser languages is stored in nvim-treesitter [0].

PR #4 fixed that problem before. It seems that the solution stopped
working over time.

[0]: https://github.com/nvim-treesitter/nvim-treesitter/blob/32e364ea3c99aafcce2ce735fe091618f623d889/lua/nvim-treesitter/parsers.lua#L4-L21
@mfussenegger
Copy link
Owner

Sorry but I don't want this plugin to depend on nvim-treesitter. It should only depend on treesitter APIs that are part of neovim core.

@Gelio
Copy link
Author

Gelio commented Jun 11, 2022

That's surprising to me. nvim-treesitter seems like a standard plugin to use alongside the built-in treesitter APIs, even for installing plugins. I'm genuinely curious why you would rather this plugin not depend on nvim-treesitter.

Regardless, do you have a suggestion how to fix the problem with the parser language being different that filetypes without requiring nvim-treesitter? This is the problem that this PR solves.

@mfussenegger
Copy link
Owner

mfussenegger commented Jun 23, 2022

That's surprising to me. nvim-treesitter seems like a standard plugin to use alongside the built-in treesitter APIs, even for installing plugins. I'm genuinely curious why you would rather this plugin not depend on nvim-treesitter.

Part of the intention of nvim-treesitter was to have a faster moving playground to experiment with the treesittter and additional APIs before they go into core. But the goal is to have everything necessary to create plugins like this without nvim-treesitter. If necessary components are missing these should eventually make it into core. There is already work ongoing in this direction (e.g. neovim/neovim#18232). As a neovim core contributor myself part I'd rather help in that regard and keep my plugins free of nvim-treesitter. It's not that there is anything wrong with nvim-treesitter itself, it's that this helps inform what might be needed in neovim core itself.

Regardless, do you have a suggestion how to fix the problem with the parser language being different that filetypes without requiring nvim-treesitter?

Not yet, I'll have to take a closer look at why it broke (or ever worked)

@Gelio
Copy link
Author

Gelio commented Jun 23, 2022

I see, thanks for a thorough explanation. I believe I understand why you want to keep away from using nvim-treesitter in this plugin. I'll wait for your suggestions on how to tackle this problem in a different way, other than hardcoding the mapping of those special filetype -> parser names.

@mfussenegger
Copy link
Owner

See #30

@Gelio Gelio deleted the resolve-parser-lang branch February 22, 2023 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No parser for typescriptreact language (when treesitter parser name is different from filetype)
2 participants