-
Notifications
You must be signed in to change notification settings - Fork 29
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
Change the parser repo to an installable plugin and update queries/injections #13
base: master
Are you sure you want to change the base?
Conversation
First, makes this repo installable via plugin manager. In addition it already takes care of most setup for the user: - file type detection - parser registration - injections queries Second, it defines `helm` as a language that uses the gotmpl language, but with different injection queries. This allows the standard gotmpl language to use simple text for its text nodes and only injects `yaml` as a language in `helm` templates. The injections are also set to combined, to fix some highlighting issues. Third, it increases the priority of gotmpl highlight queries, so that the gotmpl highlights are always visible above the highlights of any injection language.
Looking nice 😄 Using this minimal config: https://github.com/qvalentin/helm-ls/blob/feat-tree-sitter-nivm-plugin/examples/nvim/init.lua I get the following error:
Running |
The installation of the parsers is a bit of a weak point at the moment. I'm not entirely happy with it either. Usually it worked for me by just reloading the helm file ( I couldn't find any easy nvim-treesitter API, that allows installing a configured parser. If you have a hint how this could work, I can update the plugin. |
This fixes installation problems and allows the user to pick which additional languages to install and configure.
@qvalentin I think I fixed it. I had one last error until the end, but that was because I also added the ability for the user to only pick a subset of the additional languages to install. |
Maybe we should add instructions on how to migrate from having the grammar installed manually. And also how to make a clean reinstall.
restart nvim (twice for helm to work). While the minimal config is working pretty good now, for my person config (which is based on AstoNvim I had to change how lazy loads the plugin 😕 : event = { "BufReadPre", "BufNewFile", "BufEnter" } is working. I was expecting ft = { "helm", "gotmpl" } EDIT 2: A file inside the folder ftdetect would be needed for this to work (see vim-helm) Do you know any other grammar that can be installed with a nvim plugin? Maybe we can look into how they implemented things. |
@@ -0,0 +1 @@ | |||
; inherits: gotmpl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can add helm specific functions here later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, that's a good idea. Do you have some in mind that you want to specifically highlight beyond their gotmpl highlighting?
local parser_config = require("nvim-treesitter.parsers").get_parser_configs() | ||
|
||
--- @param additional_langs string[] | ||
local function configure_filetype(additional_langs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functions seems to be generic, but then it contains details for the helm filetype. Maybe we should just make one configure_helm_filetype
function instead, which is called, when additional_langs contains "helm". Or known_additional_langs
could also contain the patterns of the known languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is just a misleading name. I named it after vim.filetype
. Basically this means "configure filetype detection". Should I just rename the function to configure_filetype_detection
?
Agreed, I will have a look at adding migration instructions. I also discovered that this plugin will cause errors when just running What is possible is to simply use the same parser for multiple filetypes, but As for lazy loading I'm not sure that's a good idea. I don't lazy load this Lastly, no I don't know of any other parser that can be loaded as a plugin. |
Wouldn't it be better if we tried to add the parser to https://github.com/nvim-treesitter/nvim-treesitter? Following this example PR should be easy. |
I never looked into adding a parser to the official repo, but sure that's also a solution. Though it would only be the parser then. We'd have to still provide stuff like the commentstring to either core or ourselves as a separate plugin. |
Hi @kmoschcau, sorry for being a little bit inactive on this. I thought of another solution and opened up #15, please check it out. |
We need to discuss what we want to do with this PR and the repo as a whole. Queries now live in the treesitter repo, but the parser still comes from here. Also stuff like the filetype detection and comment string are still in here. The latter two would be candidates for PRs on neovim core I believe. |
The parsers are now part of nvim-treesitter core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure if we should turn this repo into a nvim plugin.
For helm you could just use https://github.com/towolf/vim-helm/tree/master and for gotemplate maybe https://github.com/fatih/vim-go/tree/master?
([ | ||
(field) | ||
(field_identifier) | ||
] @variable.member (#set! priority 105)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can now move the priorities to the nivm-treesitter repo and delete the queries here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a PR for the queries in nvim-treesitter.
end | ||
|
||
M.setup = function(options) | ||
local additional_langs = options.additional_langs or { "helm" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we just just add the helm filetype always and remove the whole config option to keep things simple.
|
||
## Installation | ||
|
||
Install with your favorite package manager. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be more like:
- get filetype detection working (you can install this repo as a plugin)
- Install the grammar you need with
:TSInstall (gotmpl|helm)
@qvalentin I think with the queries moved over, we can probably close the PR. You are right, this repo should focus on the parser. The only thing really left in this PR would be file type detection and other plugins are better suited for that. |
Please check out #20 |
First, makes this repo installable via plugin manager. In addition it already takes care of most setup for the user:
Second, it defines
helm
as a language that uses the gotmpl language, but with different injection queries. This allows the standard gotmpl language to use simple text for its text nodes and only injectsyaml
as a language inhelm
templates. The injections are also set to combined, to fix some highlighting issues.Third, it increases the priority of gotmpl highlight queries, so that the gotmpl highlights are always visible above the highlights of any injection language.