From ebcbfcda06bbb2cf6671f1e28185837943ea3b81 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 17:36:39 +0200 Subject: [PATCH 01/14] feat!: move to `tree-sitter-norg3` --- .../core/integrations/treesitter/module.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index e87361719..e4a939e29 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -119,10 +119,10 @@ module.config.public = { parser_configs = { -- Configuration for the mainline norg parser. norg = { - url = "https://github.com/nvim-neorg/tree-sitter-norg", + url = "https://github.com/nvim-neorg/tree-sitter-norg3", files = { "src/parser.c", "src/scanner.cc" }, branch = "main", - revision = "6348056b999f06c2c7f43bb0a5aa7cfde5302712", + revision = "e1552a9039366cf8fc5230669acc91860e3c3842", }, -- Configuration for the metadata parser (used to parse the contents -- of `@document.meta` blocks). @@ -138,11 +138,13 @@ module.config.public = { ---@class core.integrations.treesitter module.public = { parser_path = nil, + --- Gives back an instance of `nvim-treesitter.ts_utils` ---@return table #`nvim-treesitter.ts_utils` get_ts_utils = function() return module.private.ts_utils end, + --- Jumps to the next match of a query in the current buffer ---@param query_string string Query with `@next-segment` captures goto_next_query_match = function(query_string) @@ -176,6 +178,7 @@ module.public = { ::continue:: end end, + --- Jumps to the previous match of a query in the current buffer ---@param query_string string Query with `@next-segment` captures goto_previous_query_match = function(query_string) @@ -213,6 +216,7 @@ module.public = { module.private.ts_utils.goto_node(final_node) end end, + --- Gets all nodes of a given type from the AST ---@param type string #The type of node to filter out ---@param opts? table #A table of two options: `buf` and `ft`, for the buffer and format to use respectively. @@ -254,6 +258,7 @@ module.public = { return result end, + --- Executes function callback on each child node of the root ---@param callback function ---@param ts_tree #Optional syntax tree @@ -266,6 +271,7 @@ module.public = { callback(child) end end, + --- Executes callback on each child recursive ---@param callback function Executes with each node as parameter, can return false to stop recursion ---@param ts_tree #Optional syntax tree @@ -285,6 +291,7 @@ module.public = { descend(root) end, + get_node_text = function(node, source) source = source or 0 @@ -306,6 +313,7 @@ module.public = { return table.concat(lines, "\n") end, + --- Returns the first node of given type if present ---@param type string #The type of node to search for ---@param buf number #The buffer to search in @@ -332,6 +340,7 @@ module.public = { return iterate(tree:root()) end) end, + --- Recursively attempts to locate a node of a given type ---@param type string #The type of node to look for ---@param opts table #A table of two options: `buf` and `ft`, for the buffer and format respectively @@ -382,6 +391,7 @@ module.public = { return result end, + --- Given a node this function will break down the AST elements and return the corresponding text for certain nodes -- @Param tag_node (userdata/treesitter node) - a node of type tag/carryover_tag get_tag_info = function(tag_node) @@ -452,6 +462,7 @@ module.public = { ["end"] = { row = end_row, column = end_column }, } end, + --- Gets the range of a given node ---@param node userdata #The node to get the range of ---@return table #A table of `row_start`, `column_start`, `row_end` and `column_end` values @@ -481,6 +492,7 @@ module.public = { column_end = ce, } end, + --- Extracts the document root from the current document or from the string ---@param src number|string The number of the buffer to extract or string with code (can be nil) ---@param filetype string? #The filetype of the buffer or the string with code @@ -503,6 +515,7 @@ module.public = { return tree:root() end, + --- Attempts to find a parent of a node recursively ---@param node userdata #The node to start at ---@param types table|string #If `types` is a table, this function will attempt to match any of the types present in the table. @@ -522,6 +535,7 @@ module.public = { _node = _node:parent() end end, + --- Retrieves the first node at a specific line ---@param buf number #The buffer to search in (0 for current) ---@param line number #The line number (0-indexed) to get the node from @@ -665,6 +679,7 @@ module.public = { return result end, + --- Parses a query and automatically executes it for Norg ---@param query_string string #The query string ---@param callback function #The callback to execute with all the value returned by iter_captures From 31f6cfb9264fd248f46cfa92c998cb0fa9aa31c3 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 18:32:27 +0200 Subject: [PATCH 02/14] chore(treesitter): bump revision --- lua/neorg/modules/core/integrations/treesitter/module.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index e4a939e29..f1bf4a4a7 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -122,7 +122,7 @@ module.config.public = { url = "https://github.com/nvim-neorg/tree-sitter-norg3", files = { "src/parser.c", "src/scanner.cc" }, branch = "main", - revision = "e1552a9039366cf8fc5230669acc91860e3c3842", + revision = "a56093d3fad28a14157383ba5b754d199868c51f", }, -- Configuration for the metadata parser (used to parse the contents -- of `@document.meta` blocks). From 03c8db64b48ba1567fb028e92c542dbf6cb24fdb Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 18:34:35 +0200 Subject: [PATCH 03/14] refactor!: remove all hacks related to MacOS installation --- .../core/integrations/treesitter/module.lua | 54 +------------------ 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index f1bf4a4a7..bcd111413 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -704,47 +704,6 @@ module.public = { end, } --- this fixes the problem of installing neorg ts parsers on macOS without resorting to using gcc -local function install_norg_ts() - if vim.fn.has("macunix") == 1 then - -- https://github.com/nvim-neorg/tree-sitter-norg/issues/7 - -- (we have to force clang to c++11 mode on macOS manually) - - local shell = require("nvim-treesitter.shell_command_selectors") - local install = require("nvim-treesitter.install") - - -- save the original functions - local select_executable = shell.select_executable - local compilers = install.compilers - - -- temporarily patch treesitter install logic - local cc = "clang++ -std=c++11" - ---@diagnostic disable-next-line: duplicate-set-field - shell.select_executable = function(executables) - return vim.tbl_filter(function(c) ---@param c string - return c ~= vim.NIL and (vim.fn.executable(c) == 1 or c == cc) - end, executables)[1] - end - install.compilers = { cc } - - -- install norg parsers - local ok, err = pcall(function() - install.commands.TSInstallSync["run!"]("norg") - end) - - -- no matter what, restore the defaults back - shell.select_executable = select_executable - install.compilers = compilers - - -- if an error occurred during install, propagate it up - if not ok then - error(err) - end - else - vim.cmd([[ TSInstall! norg ]]) - end -end - module.on_event = function(event) if event.split_type[1] == "core.keybinds" then if event.split_type[2] == "core.integrations.treesitter.next.heading" then @@ -757,17 +716,8 @@ module.on_event = function(event) module.public.goto_previous_query_match(module.private.link_query) end elseif event.split_type[2] == "sync-parsers" then - local ok = pcall(install_norg_ts) - - if not ok then - utils.notify( - [[Unable to install norg parser. -]], - vim.log.levels.WARN - ) - end - - pcall(vim.cmd, "TSInstall! norg_meta") + pcall(vim.cmd, [[TSInstall! norg]]) + pcall(vim.cmd, [[TSInstall! norg_meta]]) end end From faa878e3e53a721417a4cf38cd75abeb9cc94f5f Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 19:05:57 +0200 Subject: [PATCH 04/14] chore: bump treesitter version --- lua/neorg/modules/core/integrations/treesitter/module.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index bcd111413..d440141e0 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -122,7 +122,7 @@ module.config.public = { url = "https://github.com/nvim-neorg/tree-sitter-norg3", files = { "src/parser.c", "src/scanner.cc" }, branch = "main", - revision = "a56093d3fad28a14157383ba5b754d199868c51f", + revision = "e0a43c1a89bc98c49383fbab9c89a5a097b9fe23", }, -- Configuration for the metadata parser (used to parse the contents -- of `@document.meta` blocks). From df493eeaa3a69345e4c3a8cc84f1730be881027e Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 19:15:31 +0200 Subject: [PATCH 05/14] refactor(highlights.scm): refactor ranged tags to work with new parser --- queries/norg/highlights.scm | 54 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/queries/norg/highlights.scm b/queries/norg/highlights.scm index 8f4a76d1d..2242c74fe 100644 --- a/queries/norg/highlights.scm +++ b/queries/norg/highlights.scm @@ -1,38 +1,32 @@ -(ranged_verbatim_tag - ("_prefix") @neorg.tags.ranged_verbatim.begin - name: (tag_name - [(word) @neorg.tags.ranged_verbatim.name.word - ("_delimiter") @neorg.tags.ranged_verbatim.name.delimiter]) @neorg.tags.ranged_verbatim.name - (tag_parameters - (tag_param) @neorg.tags.ranged_verbatim.parameters.word)? @neorg.tags.ranged_verbatim.parameters) +(verbatim_ranged_tag + "@" @neorg.tags.ranged_verbatim + (tag_name + [(identifier) @neorg.tags.ranged_verbatim.name.word + "." @neorg.tags.ranged_verbatim.name.delimiter]) @neorg.tags.ranged_verbatim.name + (parameter)* @neorg.tags.ranged_verbatim.parameters.word + (end) @neorg.tags.ranged_verbatim) -(ranged_verbatim_tag_end - ("_prefix") @neorg.tags.ranged_verbatim.end - ("_name") @neorg.tags.ranged_verbatim.name.word) - -(ranged_verbatim_tag - ("_prefix") - name: (tag_name) @neorg.tags.ranged_verbatim.name +(verbatim_ranged_tag + "@" @neorg.tags.ranged_verbatim + (tag_name) @neorg.tags.ranged_verbatim.name (#eq? @neorg.tags.ranged_verbatim.name "comment") - content: (ranged_verbatim_tag_content)? @neorg.tags.comment.content) + (content)? @neorg.tags.comment.content) -(paragraph - (strong_carryover_set - (strong_carryover - name: (tag_name) @_name - (#eq? @_name "comment"))) - (paragraph_segment) @neorg.tags.comment.content) +( + (strong_carryover_tag + (tag_name) @_name + (#eq? @_name "comment")) + . + (paragraph) @neorg.tags.comment.content + ) -(strong_carryover - ("_prefix" @neorg.tags.carryover.begin) - name: (tag_name - [(word) @neorg.tags.carryover.name.word - ("_delimiter") @neorg.tags.carryover.name.delimiter]) @neorg.tags.carryover.name - (tag_parameters - (tag_param) @neorg.tags.carryover.parameters.word)? @neorg.tags.carryover.parameters) @neorg.tags.carryover -; Trailing Modifier -("_trailing_modifier") @neorg.modifiers.trailing +(strong_carryover_tag + "#" @neorg.tags.carryover.begin + (tag_name + [(identifier) @neorg.tags.carryover.name.word + "." @neorg.tags.carryover.name.delimiter]) @neorg.tags.carryover.name + (parameter)* @neorg.tags.carryover.parameters.word) @neorg.tags.carryover ; Link Modifier (link_modifier) @neorg.modifiers.link From 372cb36f4aac0870baa6fa099e8ba0d0bcdd7d77 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 21:15:03 +0200 Subject: [PATCH 06/14] chore: bump treesitter revision --- lua/neorg/modules/core/integrations/treesitter/module.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index d440141e0..c026805df 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -122,7 +122,7 @@ module.config.public = { url = "https://github.com/nvim-neorg/tree-sitter-norg3", files = { "src/parser.c", "src/scanner.cc" }, branch = "main", - revision = "e0a43c1a89bc98c49383fbab9c89a5a097b9fe23", + revision = "2ec46882b40e373b3d76cf6ea70f2fca0c154333", }, -- Configuration for the metadata parser (used to parse the contents -- of `@document.meta` blocks). From d82954fff25a12dbfb0894c6efe6b3b4073c5608 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 9 Aug 2023 21:15:18 +0200 Subject: [PATCH 07/14] refactor: continue refactoring highlights.scm --- queries/norg/highlights.scm | 414 ++++++++++++++++++------------------ 1 file changed, 211 insertions(+), 203 deletions(-) diff --git a/queries/norg/highlights.scm b/queries/norg/highlights.scm index 2242c74fe..328e96126 100644 --- a/queries/norg/highlights.scm +++ b/queries/norg/highlights.scm @@ -32,133 +32,146 @@ (link_modifier) @neorg.modifiers.link ; Links -(link - (link_location - ("_begin") @neorg.links.location.delimiter - [(("_begin") @neorg.links.file.delimiter - file: (link_file_text) @neorg.links.file - ("_end") @neorg.links.file.delimiter) - ((link_target_url) ; Doesn't require a highlight since it's a 0-width node - (paragraph) @neorg.links.location.url) - ((link_target_generic) @neorg.links.location.generic.prefix - (paragraph) @neorg.links.location.generic) - ((link_target_external_file) @neorg.links.location.external_file.prefix - (paragraph) @neorg.links.location.external_file) - ((link_target_definition) @neorg.links.location.definition.prefix - (paragraph) @neorg.links.location.definition) - ((link_target_footnote) @neorg.links.location.footnote.prefix - (paragraph) @neorg.links.location.footnote) - ((link_target_heading1) @neorg.links.location.heading.1.prefix - (paragraph) @neorg.links.location.heading.1) - ((link_target_heading2) @neorg.links.location.heading.2.prefix - (paragraph) @neorg.links.location.heading.2) - ((link_target_heading3) @neorg.links.location.heading.3.prefix - (paragraph) @neorg.links.location.heading.3) - ((link_target_heading4) @neorg.links.location.heading.4.prefix - (paragraph) @neorg.links.location.heading.4) - ((link_target_heading5) @neorg.links.location.heading.5.prefix - (paragraph) @neorg.links.location.heading.5) - ((link_target_heading6) @neorg.links.location.heading.6.prefix - (paragraph) @neorg.links.location.heading.6) - ((link_target_wiki) @neorg.links.location.wiki.prefix - (paragraph) @neorg.links.location.wiki) - ((link_target_timestamp) @neorg.links.location.timestamp.prefix - (paragraph) @neorg.links.location.timestamp)] - ("_end") @neorg.links.location.delimiter) - (link_description - ("_begin") @neorg.links.description.delimiter - text: (paragraph) @neorg.links.description - ("_end") @neorg.links.description.delimiter)?) +; (link +; (link_location +; ("_begin") @neorg.links.location.delimiter +; [(("_begin") @neorg.links.file.delimiter +; file: (link_file_text) @neorg.links.file +; ("_end") @neorg.links.file.delimiter) +; ((link_target_url) ; Doesn't require a highlight since it's a 0-width node +; (paragraph) @neorg.links.location.url) +; ((link_target_generic) @neorg.links.location.generic.prefix +; (paragraph) @neorg.links.location.generic) +; ((link_target_external_file) @neorg.links.location.external_file.prefix +; (paragraph) @neorg.links.location.external_file) +; ((link_target_definition) @neorg.links.location.definition.prefix +; (paragraph) @neorg.links.location.definition) +; ((link_target_footnote) @neorg.links.location.footnote.prefix +; (paragraph) @neorg.links.location.footnote) +; ((link_target_heading1) @neorg.links.location.heading.1.prefix +; (paragraph) @neorg.links.location.heading.1) +; ((link_target_heading2) @neorg.links.location.heading.2.prefix +; (paragraph) @neorg.links.location.heading.2) +; ((link_target_heading3) @neorg.links.location.heading.3.prefix +; (paragraph) @neorg.links.location.heading.3) +; ((link_target_heading4) @neorg.links.location.heading.4.prefix +; (paragraph) @neorg.links.location.heading.4) +; ((link_target_heading5) @neorg.links.location.heading.5.prefix +; (paragraph) @neorg.links.location.heading.5) +; ((link_target_heading6) @neorg.links.location.heading.6.prefix +; (paragraph) @neorg.links.location.heading.6) +; ((link_target_wiki) @neorg.links.location.wiki.prefix +; (paragraph) @neorg.links.location.wiki) +; ((link_target_timestamp) @neorg.links.location.timestamp.prefix +; (paragraph) @neorg.links.location.timestamp)] +; ("_end") @neorg.links.location.delimiter) +; (link_description +; ("_begin") @neorg.links.description.delimiter +; text: (paragraph) @neorg.links.description +; ("_end") @neorg.links.description.delimiter)?) +; +; ; Anchors +; (anchor_declaration +; (link_description +; ("_begin") @neorg.anchors.declaration.delimiter +; text: (paragraph) @neorg.anchors.declaration +; ("_end") @neorg.anchors.declaration.delimiter)) +; +; (anchor_definition +; (link_description +; ("_begin") @neorg.anchors.definition.delimiter +; text: (paragraph) @neorg.anchors.declaration +; ("_end") @neorg.anchors.definition.delimiter) @neorg.anchors +; (link_location +; ("_begin") @neorg.links.location.delimiter +; [(("_begin") @neorg.links.file.delimiter +; file: (link_file_text) @neorg.links.file +; ("_end") @neorg.links.file.delimiter) +; ((link_target_url) ; Doesn't require a highlight since it's a 0-width node +; (paragraph) @neorg.links.location.url) +; ((link_target_generic) @neorg.links.location.generic.prefix +; (paragraph) @neorg.links.location.generic) +; ((link_target_external_file) @neorg.links.location.external_file.prefix +; (paragraph) @neorg.links.location.external_file) +; ((link_target_definition) @neorg.links.location.definition.prefix +; (paragraph) @neorg.links.location.definition) +; ((link_target_footnote) @neorg.links.location.footnote.prefix +; (paragraph) @neorg.links.location.footnote) +; ((link_target_heading1) @neorg.links.location.heading.1.prefix +; (paragraph) @neorg.links.location.heading.1) +; ((link_target_heading2) @neorg.links.location.heading.2.prefix +; (paragraph) @neorg.links.location.heading.2) +; ((link_target_heading3) @neorg.links.location.heading.3.prefix +; (paragraph) @neorg.links.location.heading.3) +; ((link_target_heading4) @neorg.links.location.heading.4.prefix +; (paragraph) @neorg.links.location.heading.4) +; ((link_target_heading5) @neorg.links.location.heading.5.prefix +; (paragraph) @neorg.links.location.heading.5) +; ((link_target_heading6) @neorg.links.location.heading.6.prefix +; (paragraph) @neorg.links.location.heading.6) +; ((link_target_wiki) @neorg.links.location.wiki.prefix +; (paragraph) @neorg.links.location.wiki) +; ((link_target_timestamp) @neorg.links.location.timestamp.prefix +; (paragraph) @neorg.links.location.timestamp)] +; ("_end") @neorg.links.location.delimiter)) -; Anchors -(anchor_declaration - (link_description - ("_begin") @neorg.anchors.declaration.delimiter - text: (paragraph) @neorg.anchors.declaration - ("_end") @neorg.anchors.declaration.delimiter)) +; Headings +(heading + (heading_stars) @neorg.headings.1.prefix + (#eq? @neorg.headings.1.prefix "*") + (title) @neorg.headings.1.title) -(anchor_definition - (link_description - ("_begin") @neorg.anchors.definition.delimiter - text: (paragraph) @neorg.anchors.declaration - ("_end") @neorg.anchors.definition.delimiter) @neorg.anchors - (link_location - ("_begin") @neorg.links.location.delimiter - [(("_begin") @neorg.links.file.delimiter - file: (link_file_text) @neorg.links.file - ("_end") @neorg.links.file.delimiter) - ((link_target_url) ; Doesn't require a highlight since it's a 0-width node - (paragraph) @neorg.links.location.url) - ((link_target_generic) @neorg.links.location.generic.prefix - (paragraph) @neorg.links.location.generic) - ((link_target_external_file) @neorg.links.location.external_file.prefix - (paragraph) @neorg.links.location.external_file) - ((link_target_definition) @neorg.links.location.definition.prefix - (paragraph) @neorg.links.location.definition) - ((link_target_footnote) @neorg.links.location.footnote.prefix - (paragraph) @neorg.links.location.footnote) - ((link_target_heading1) @neorg.links.location.heading.1.prefix - (paragraph) @neorg.links.location.heading.1) - ((link_target_heading2) @neorg.links.location.heading.2.prefix - (paragraph) @neorg.links.location.heading.2) - ((link_target_heading3) @neorg.links.location.heading.3.prefix - (paragraph) @neorg.links.location.heading.3) - ((link_target_heading4) @neorg.links.location.heading.4.prefix - (paragraph) @neorg.links.location.heading.4) - ((link_target_heading5) @neorg.links.location.heading.5.prefix - (paragraph) @neorg.links.location.heading.5) - ((link_target_heading6) @neorg.links.location.heading.6.prefix - (paragraph) @neorg.links.location.heading.6) - ((link_target_wiki) @neorg.links.location.wiki.prefix - (paragraph) @neorg.links.location.wiki) - ((link_target_timestamp) @neorg.links.location.timestamp.prefix - (paragraph) @neorg.links.location.timestamp)] - ("_end") @neorg.links.location.delimiter)) +(heading + (heading_stars) @neorg.headings.2.prefix + (#eq? @neorg.headings.2.prefix "**") + (title) @neorg.headings.2.title) -; Headings -(heading1 - (heading1_prefix) @neorg.headings.1.prefix - title: (paragraph_segment) @neorg.headings.1.title) -(heading2 - (heading2_prefix) @neorg.headings.2.prefix - title: (paragraph_segment) @neorg.headings.2.title) -(heading3 - (heading3_prefix) @neorg.headings.3.prefix - title: (paragraph_segment) @neorg.headings.3.title) -(heading4 - (heading4_prefix) @neorg.headings.4.prefix - title: (paragraph_segment) @neorg.headings.4.title) -(heading5 - (heading5_prefix) @neorg.headings.5.prefix - title: (paragraph_segment) @neorg.headings.5.title) -(heading6 - (heading6_prefix) @neorg.headings.6.prefix - title: (paragraph_segment) @neorg.headings.6.title) +(heading + (heading_stars) @neorg.headings.3.prefix + (#eq? @neorg.headings.3.prefix "***") + (title) @neorg.headings.3.title) + +(heading + (heading_stars) @neorg.headings.4.prefix + (#eq? @neorg.headings.4.prefix "****") + (title) @neorg.headings.4.title) + +(heading + (heading_stars) @neorg.headings.5.prefix + (#eq? @neorg.headings.5.prefix "*****") + (title) @neorg.headings.5.title) + +(heading + (heading_stars) @neorg.headings.6.prefix + (#eq? @neorg.headings.6.prefix "******") + (title) @neorg.headings.6.title) ; Display errors (ERROR) @neorg.error ; Definitions -(single_definition - (single_definition_prefix) @neorg.definitions.prefix - title: (paragraph_segment) @neorg.definitions.title - content: [(_) "_paragraph_break"]* @neorg.definitions.content) -(multi_definition - (multi_definition_prefix) @neorg.definitions.prefix - title: (paragraph_segment) @neorg.definitions.title - content: [(_) "_paragraph_break"]* @neorg.definitions.content - end: (multi_definition_suffix) @neorg.definitions.suffix) +(definition_list_single + "$" @neorg.definitions.prefix + (title) @neorg.definitions.title + (paragraph) @neorg.definitions.content) + +(definition_list_multi + "$$" @neorg.definitions.prefix + (title) @neorg.definitions.title + _* @neorg.definitions.content + "$$" @neorg.definitions.suffix) ; Footnotes -(single_footnote - (single_footnote_prefix) @neorg.footnotes.prefix - title: (paragraph_segment) @neorg.footnotes.title - content: [(_) "_paragraph_break"]* @neorg.footnotes.content) -(multi_footnote - (multi_footnote_prefix) @neorg.footnotes.prefix - title: (paragraph_segment) @neorg.footnotes.title - content: [(_) "_paragraph_break"]* @neorg.footnotes.content - end: (multi_footnote_suffix) @neorg.footnotes.suffix) +(footnote_list_single + "^" @neorg.footnotes.prefix + (title) @neorg.footnotes.title + (paragraph) @neorg.footnotes.content) + +(footnote_list_multi + "^^" @neorg.footnotes.prefix + (title) @neorg.footnotes.title + _* @neorg.footnotes.content + "^^" @neorg.footnotes.suffix) ; Escape sequences (\char) (escape_sequence) @neorg.modifiers.escape @@ -174,62 +187,58 @@ (detached_modifier_extension (todo_item_recurring)) @neorg.todo_items.recurring ; ; Unordered lists -[(unordered_list1_prefix) - (unordered_list2_prefix) - (unordered_list3_prefix) - (unordered_list4_prefix) - (unordered_list5_prefix) - (unordered_list6_prefix)] @neorg.lists.unordered.prefix +(unordered_list_prefix) @neorg.lists.unordered.prefix ; Ordered lists -[(ordered_list1_prefix) - (ordered_list2_prefix) - (ordered_list3_prefix) - (ordered_list4_prefix) - (ordered_list5_prefix) - (ordered_list6_prefix)] @neorg.lists.ordered.prefix +(ordered_list_prefix) @neorg.lists.ordered.prefix ; Quotes -(quote1 - (quote1_prefix) @neorg.quotes.1.prefix - content: (paragraph) @neorg.quotes.1.content) -(quote2 - (quote2_prefix) @neorg.quotes.2.prefix - content: (paragraph) @neorg.quotes.2.content) -(quote3 - (quote3_prefix) @neorg.quotes.3.prefix - content: (paragraph) @neorg.quotes.3.content) -(quote4 - (quote4_prefix) @neorg.quotes.4.prefix - content: (paragraph) @neorg.quotes.4.content) -(quote5 - (quote5_prefix) @neorg.quotes.5.prefix - content: (paragraph) @neorg.quotes.5.content) -(quote6 - (quote6_prefix) @neorg.quotes.6.prefix - content: (paragraph) @neorg.quotes.6.content) +(quote_item + (quote_prefix) @neorg.quotes.1.prefix + (#eq? @neorg.quotes.1.prefix ">") + (paragraph) @neorg.quotes.1.content) +(quote_item + (quote_prefix) @neorg.quotes.2.prefix + (#eq? @neorg.quotes.2.prefix ">>") + (paragraph) @neorg.quotes.2.content) +(quote_item + (quote_prefix) @neorg.quotes.3.prefix + (#eq? @neorg.quotes.3.prefix ">>>") + (paragraph) @neorg.quotes.3.content) +(quote_item + (quote_prefix) @neorg.quotes.4.prefix + (#eq? @neorg.quotes.4.prefix ">>>>") + (paragraph) @neorg.quotes.4.content) +(quote_item + (quote_prefix) @neorg.quotes.5.prefix + (#eq? @neorg.quotes.5.prefix ">>>>>") + (paragraph) @neorg.quotes.5.content) +(quote_item + (quote_prefix) @neorg.quotes.6.prefix + (#eq? @neorg.quotes.6.prefix ">>>>>>") + (paragraph) @neorg.quotes.6.content) ; Paragraph Delimiters -(strong_paragraph_delimiter) @neorg.delimiters.strong -(weak_paragraph_delimiter) @neorg.delimiters.weak +(strong_delimiting_modifier) @neorg.delimiters.strong +(weak_delimiting_modifier) @neorg.delimiters.weak (horizontal_line) @neorg.delimiters.horizontal_line ; Markup -(bold ["_open" "_close"] @neorg.markup.bold.delimiter) @neorg.markup.bold -(italic ["_open" "_close"] @neorg.markup.italic.delimiter) @neorg.markup.italic -(strikethrough ["_open" "_close"] @neorg.markup.strikethrough.delimiter) @neorg.markup.strikethrough -(underline ["_open" "_close"] @neorg.markup.underline.delimiter) @neorg.markup.underline -(spoiler ["_open" "_close"] @neorg.markup.spoiler.delimiter) @neorg.markup.spoiler -(verbatim ["_open" "_close"] @neorg.markup.verbatim.delimiter) @neorg.markup.verbatim -(superscript ["_open" "_close"] @neorg.markup.superscript.delimiter) @neorg.markup.superscript -(subscript ["_open" "_close"] @neorg.markup.subscript.delimiter) @neorg.markup.subscript -(inline_comment ["_open" "_close"] @neorg.markup.inline_comment.delimiter) @neorg.markup.inline_comment -(inline_math ["_open" "_close"] @neorg.markup.inline_math.delimiter) @neorg.markup.inline_math -(inline_macro ["_open" "_close"] @neorg.markup.variable.delimiter) @neorg.markup.variable +(bold [(open) (close)] @neorg.markup.bold.delimiter) @neorg.markup.bold +(italic [(open) (close)] @neorg.markup.italic.delimiter) @neorg.markup.italic +(strikethrough [(open) (close)] @neorg.markup.strikethrough.delimiter) @neorg.markup.strikethrough +(underline [(open) (close)] @neorg.markup.underline.delimiter) @neorg.markup.underline +(spoiler [(open) (close)] @neorg.markup.spoiler.delimiter) @neorg.markup.spoiler +(verbatim [(open) (close)] @neorg.markup.verbatim.delimiter) @neorg.markup.verbatim +(superscript [(open) (close)] @neorg.markup.superscript.delimiter) @neorg.markup.superscript +(subscript [(open) (close)] @neorg.markup.subscript.delimiter) @neorg.markup.subscript +; (inline_comment [(open) (close)] @neorg.markup.inline_comment.delimiter) @neorg.markup.inline_comment +; (inline_math [(open) (close)] @neorg.markup.inline_math.delimiter) @neorg.markup.inline_math +; (inline_macro [(open) (close)] @neorg.markup.variable.delimiter) @neorg.markup.variable ; Free-form Markup -[(free_form_open) - (free_form_close)] @neorg.markup.free_form_delimiter +; [(free_form_open) +; (free_form_close)] @neorg.markup.free_form_delimiter (superscript (subscript) @neorg.error @@ -244,54 +253,53 @@ ; Conceals ( [ - "_open" - "_close" - "_trailing_modifier" + (open) + (close) (link_modifier) - (free_form_open) - (free_form_close) + ; (free_form_open) + ; (free_form_close) ] @conceal (#set! conceal "") ) -( - [ - (link_description - [ - "_begin" - type: (_) - "_end" - ] @conceal - ) - (link_location - [ - "_begin" - type: (_) - "_end" - ] @conceal - ) - (link - (link_location) @conceal - (link_description) - ) - ] - (#set! conceal "") -) - -( - [ - (anchor_definition - (link_description) - (link_location) @conceal - ) - ] - (#set! conceal "") -) +; ( +; [ +; (link_description +; [ +; "_begin" +; type: (_) +; "_end" +; ] @conceal +; ) +; (link_location +; [ +; "_begin" +; type: (_) +; "_end" +; ] @conceal +; ) +; (link +; (link_location) @conceal +; (link_description) +; ) +; ] +; (#set! conceal "") +; ) +; +; ( +; [ +; (anchor_definition +; (link_description) +; (link_location) @conceal +; ) +; ] +; (#set! conceal "") +; ) -( - (escape_sequence_prefix) @conceal +(escape_sequence + "\\" @conceal (#set! conceal "") ) ; Spell -(paragraph_segment) @spell +(paragraph) @spell From a811467cb8974364a88cc90e6b9d067d5a98dbf6 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Thu, 17 Aug 2023 21:43:44 +0200 Subject: [PATCH 08/14] feat!: migrate rest of queries to V3 --- queries/norg/folds.scm | 13 +++---------- queries/norg/highlights.scm | 2 +- queries/norg/injections.scm | 6 +++--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/queries/norg/folds.scm b/queries/norg/folds.scm index 2e5be1722..89d6a77f8 100644 --- a/queries/norg/folds.scm +++ b/queries/norg/folds.scm @@ -1,13 +1,6 @@ -(ranged_verbatim_tag - name: (tag_name) @_name +(verbatim_ranged_tag + (tag_name) @_name (#eq? @_name "document.meta") ) @fold -[ - (heading1) - (heading2) - (heading3) - (heading4) - (heading5) - (heading6) -] @fold +(heading) @fold diff --git a/queries/norg/highlights.scm b/queries/norg/highlights.scm index 328e96126..158a89f34 100644 --- a/queries/norg/highlights.scm +++ b/queries/norg/highlights.scm @@ -10,7 +10,7 @@ "@" @neorg.tags.ranged_verbatim (tag_name) @neorg.tags.ranged_verbatim.name (#eq? @neorg.tags.ranged_verbatim.name "comment") - (content)? @neorg.tags.comment.content) + (verbatim_content)? @neorg.tags.comment.content) ( (strong_carryover_tag diff --git a/queries/norg/injections.scm b/queries/norg/injections.scm index 57158cf33..df52ea943 100644 --- a/queries/norg/injections.scm +++ b/queries/norg/injections.scm @@ -1,6 +1,6 @@ ; Injection for code blocks -(ranged_verbatim_tag (tag_name) @_tagname (tag_parameters .(tag_param) @injection.language) (ranged_verbatim_tag_content) @injection.content (#any-of? @_tagname "code" "embed")) -(ranged_verbatim_tag (tag_name) @_tagname (tag_parameters)? (ranged_verbatim_tag_content) @injection.content (#eq? @_tagname "math") (#set! injection.language "latex")) +(verbatim_ranged_tag (tag_name) @_tagname .(parameter) @injection.language (verbatim_content) @injection.content (#any-of? @_tagname "code" "embed")) +(verbatim_ranged_tag (tag_name) @_tagname (verbatim_content) @injection.content (#eq? @_tagname "math") (#set! injection.language "latex")) ( (inline_math) @injection.content @@ -8,4 +8,4 @@ (#set! injection.language "latex") ) -(ranged_verbatim_tag (tag_name) @_tagname (ranged_verbatim_tag_content) @injection.content (#eq? @_tagname "document.meta") (#set! injection.language "norg_meta")) +(verbatim_ranged_tag (tag_name) @_tagname (verbatim_content) @injection.content (#eq? @_tagname "document.meta") (#set! injection.language "norg_meta")) From 0bdbe2860561bba494872fb0a7108b94e148ecb8 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Fri, 1 Sep 2023 20:01:15 +0200 Subject: [PATCH 09/14] chore: bump ts version --- lua/neorg/modules/core/integrations/treesitter/module.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neorg/modules/core/integrations/treesitter/module.lua b/lua/neorg/modules/core/integrations/treesitter/module.lua index c026805df..8af2eceb3 100644 --- a/lua/neorg/modules/core/integrations/treesitter/module.lua +++ b/lua/neorg/modules/core/integrations/treesitter/module.lua @@ -122,7 +122,7 @@ module.config.public = { url = "https://github.com/nvim-neorg/tree-sitter-norg3", files = { "src/parser.c", "src/scanner.cc" }, branch = "main", - revision = "2ec46882b40e373b3d76cf6ea70f2fca0c154333", + revision = "69f3e05deb28e71cccc3caeb1e93db39976f0acf", }, -- Configuration for the metadata parser (used to parse the contents -- of `@document.meta` blocks). From a45fbd1f944fdbd9ae8d691c845a9e3074286606 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Fri, 1 Sep 2023 20:01:37 +0200 Subject: [PATCH 10/14] ref(highlights.scm): update highlights for definitions, footnotes and tables --- queries/norg/highlights.scm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/queries/norg/highlights.scm b/queries/norg/highlights.scm index 158a89f34..a0e005117 100644 --- a/queries/norg/highlights.scm +++ b/queries/norg/highlights.scm @@ -151,27 +151,27 @@ ; Definitions (definition_list_single - "$" @neorg.definitions.prefix + (definition_single_prefix) @neorg.definitions.prefix (title) @neorg.definitions.title (paragraph) @neorg.definitions.content) (definition_list_multi - "$$" @neorg.definitions.prefix + (definition_multi_prefix) @neorg.definitions.prefix (title) @neorg.definitions.title _* @neorg.definitions.content - "$$" @neorg.definitions.suffix) + (definition_multi_end) @neorg.definitions.suffix) ; Footnotes (footnote_list_single - "^" @neorg.footnotes.prefix + (footnote_single_prefix) @neorg.footnotes.prefix (title) @neorg.footnotes.title (paragraph) @neorg.footnotes.content) (footnote_list_multi - "^^" @neorg.footnotes.prefix + (footnote_multi_prefix) @neorg.footnotes.prefix (title) @neorg.footnotes.title _* @neorg.footnotes.content - "^^" @neorg.footnotes.suffix) + (footnote_multi_end) @neorg.footnotes.suffix) ; Escape sequences (\char) (escape_sequence) @neorg.modifiers.escape From a18ca39b549819472dddacb1658b337526e7909c Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Fri, 1 Sep 2023 20:01:55 +0200 Subject: [PATCH 11/14] ref(concealer): refactor some node names in the concealer --- lua/neorg/modules/core/concealer/module.lua | 50 ++++++--------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/lua/neorg/modules/core/concealer/module.lua b/lua/neorg/modules/core/concealer/module.lua index 3a113dc7b..e736226c8 100644 --- a/lua/neorg/modules/core/concealer/module.lua +++ b/lua/neorg/modules/core/concealer/module.lua @@ -721,24 +721,14 @@ module.config.public = { list = { icons = { "•" }, nodes = { - "unordered_list1_prefix", - "unordered_list2_prefix", - "unordered_list3_prefix", - "unordered_list4_prefix", - "unordered_list5_prefix", - "unordered_list6_prefix", + "unordered_list_prefix", }, render = module.public.icon_renderers.multilevel_on_right, }, ordered = { icons = (not has_anticonceal) and { "⒈", "A", "a", "⑴", "Ⓐ", "ⓐ" } or nil, nodes = { - "ordered_list1_prefix", - "ordered_list2_prefix", - "ordered_list3_prefix", - "ordered_list4_prefix", - "ordered_list5_prefix", - "ordered_list6_prefix", + "ordered_list_prefix", }, --- A list of icon generators. @@ -765,14 +755,10 @@ module.config.public = { quote = { icons = { "│" }, nodes = { - "quote1_prefix", - "quote2_prefix", - "quote3_prefix", - "quote4_prefix", - "quote5_prefix", - "quote6_prefix", + "quote_prefix", }, highlights = { + -- TODO(vhyrro/rewrite): Update highlights "@neorg.quotes.1.prefix", "@neorg.quotes.2.prefix", "@neorg.quotes.3.prefix", @@ -793,19 +779,11 @@ module.config.public = { "@neorg.headings.6.prefix", }, nodes = { - "heading1_prefix", - "heading2_prefix", - "heading3_prefix", - "heading4_prefix", - "heading5_prefix", - "heading6_prefix", + "heading_prefix", concealed = { - "link_target_heading1", - "link_target_heading2", - "link_target_heading3", - "link_target_heading4", - "link_target_heading5", - "link_target_heading6", + -- TODO(vhyrro/rewrite): this can't be done this way + -- because of `(heading)` being the node name. + "heading_link", }, }, render = module.public.icon_renderers.multilevel_on_right, @@ -813,17 +791,17 @@ module.config.public = { definition = { single = { icon = "≡", - nodes = { "single_definition_prefix", concealed = { "link_target_definition" } }, + nodes = { "definition_single_prefix", concealed = { "link_target_definition" } }, render = module.public.icon_renderers.on_left, }, multi_prefix = { icon = "⋙ ", - nodes = { "multi_definition_prefix" }, + nodes = { "definition_multi_prefix" }, render = module.public.icon_renderers.on_left, }, multi_suffix = { icon = "⋘ ", - nodes = { "multi_definition_suffix" }, + nodes = { "definition_multi_end" }, render = module.public.icon_renderers.on_left, }, }, @@ -831,17 +809,17 @@ module.config.public = { footnote = { single = { icon = "⁎", - nodes = { "single_footnote_prefix", concealed = { "link_target_footnote" } }, + nodes = { "footnote_single_prefix", concealed = { "link_target_footnote" } }, render = module.public.icon_renderers.on_left, }, multi_prefix = { icon = "⁑ ", - nodes = { "multi_footnote_prefix" }, + nodes = { "footnote_multi_prefix" }, render = module.public.icon_renderers.on_left, }, multi_suffix = { icon = "⁑ ", - nodes = { "multi_footnote_suffix" }, + nodes = { "footnote_multi_end" }, render = module.public.icon_renderers.on_left, }, }, From 2693f1546cd2e931cab47d2ba8da98d6f05d035a Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 4 Oct 2023 17:10:10 +0200 Subject: [PATCH 12/14] fix: temporarily remove `inline_math` highlights --- queries/norg/injections.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/queries/norg/injections.scm b/queries/norg/injections.scm index df52ea943..a2789e02e 100644 --- a/queries/norg/injections.scm +++ b/queries/norg/injections.scm @@ -2,10 +2,10 @@ (verbatim_ranged_tag (tag_name) @_tagname .(parameter) @injection.language (verbatim_content) @injection.content (#any-of? @_tagname "code" "embed")) (verbatim_ranged_tag (tag_name) @_tagname (verbatim_content) @injection.content (#eq? @_tagname "math") (#set! injection.language "latex")) -( - (inline_math) @injection.content - (#offset! @injection.content 0 1 0 -1) - (#set! injection.language "latex") -) +; ( +; (inline_math) @injection.content +; (#offset! @injection.content 0 1 0 -1) +; (#set! injection.language "latex") +; ) (verbatim_ranged_tag (tag_name) @_tagname (verbatim_content) @injection.content (#eq? @_tagname "document.meta") (#set! injection.language "norg_meta")) From e3c91209fc4e4e7719f8ba3f18b9cb41b56aa7d5 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 4 Oct 2023 17:11:59 +0200 Subject: [PATCH 13/14] fix(highlights.scm): temporarily remove `inline_comment` highlights --- queries/norg/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/norg/highlights.scm b/queries/norg/highlights.scm index a0e005117..f60273b51 100644 --- a/queries/norg/highlights.scm +++ b/queries/norg/highlights.scm @@ -248,7 +248,7 @@ (#set! priority 300)) ; Comments -(inline_comment) @comment +; (inline_comment) @comment ; Conceals ( From 9463c7a0b0cd942ecc67ba59dc45a8bbb00ee956 Mon Sep 17 00:00:00 2001 From: Vhyrro Date: Wed, 4 Oct 2023 19:23:46 +0200 Subject: [PATCH 14/14] fix: make `esupports.metagen` work with V3 parser --- lua/neorg/modules/core/esupports/metagen/module.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/neorg/modules/core/esupports/metagen/module.lua b/lua/neorg/modules/core/esupports/metagen/module.lua index 9165f67be..70b2adeef 100644 --- a/lua/neorg/modules/core/esupports/metagen/module.lua +++ b/lua/neorg/modules/core/esupports/metagen/module.lua @@ -142,7 +142,7 @@ module.public = { local query = utils.ts_parse_query( "norg", [[ - (ranged_verbatim_tag + (verbatim_ranged_tag (tag_name) @name (#eq? @name "document.meta") ) @meta