diff --git a/README.md b/README.md index 28b0258..6bd82c9 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Install the plugin with your preferred plugin manager: > [!NOTE] > -> http.nvim uses a Tree-sitter grammar that is not yet included in nvim-treesitter. `setup()` replaces the default `http` grammar with [this](https://github.com/rstcruzo/tree-sitter-http2) one. This grammar provides features that aren't available in the default grammar. +> http.nvim uses a Tree-sitter grammar that is not yet included in nvim-treesitter. When loading this plugin the default `http` grammar is replaced with [this](https://github.com/rstcruzo/tree-sitter-http2) one. This grammar provides features that aren't available in the default grammar. > [!NOTE] > diff --git a/doc/http.nvim.txt b/doc/http.nvim.txt index d13a3b4..118acee 100644 --- a/doc/http.nvim.txt +++ b/doc/http.nvim.txt @@ -37,7 +37,7 @@ Install the plugin with your preferred plugin manager: } < - Note: http.nvim uses a Tree-sitter grammar that is not yet included in nvim-treesitter. `setup()` replaces the default `http` grammar with this: . This grammar provides features that aren't available in the default grammar. + Note: http.nvim uses a Tree-sitter grammar that is not yet included in nvim-treesitter. When loading this plugin the default `http` grammar is replaced with this: . This grammar provides features that aren't available in the default grammar. CONFIGURATION *http.nvim-configuration* diff --git a/lua/http-nvim/init.lua b/lua/http-nvim/init.lua index 4dece6e..f016a07 100644 --- a/lua/http-nvim/init.lua +++ b/lua/http-nvim/init.lua @@ -291,29 +291,6 @@ vim.api.nvim_create_user_command("Http", http_cmd, { local M = {} -M.init = function() - local parser_config = - require("nvim-treesitter.parsers").get_parser_configs() - parser_config.http2 = { - install_info = { - url = "https://github.com/rstcruzo/tree-sitter-http2", - branch = "main", - files = { "src/parser.c" }, - }, - filetype = "http", - } - - vim.treesitter.language.register("http2", "http") - - vim.filetype.add({ - extension = { - http = "http", - }, - }) -end - -M.init() - ---@param opts? http.Opts M.setup = function(opts) config.setup(opts) diff --git a/lua/http-nvim/queries.lua b/lua/http-nvim/queries.lua index 334fef2..b10530f 100644 --- a/lua/http-nvim/queries.lua +++ b/lua/http-nvim/queries.lua @@ -1,5 +1,29 @@ local M = {} +local function init_parser() + local parser_config = + require("nvim-treesitter.parsers").get_parser_configs() + parser_config.http2 = { + install_info = { + url = "https://github.com/rstcruzo/tree-sitter-http2", + branch = "main", + files = { "src/parser.c" }, + }, + filetype = "http", + } + + vim.treesitter.language.register("http2", "http") + + vim.filetype.add({ + extension = { + http = "http", + }, + }) +end + +-- Initializing the parser here to avoid errors when using any of these queries. +init_parser() + -- TODO: Change parser name from http2 to something else. M.requests_query = vim.treesitter.query.parse( "http2",