From 19c47873441ce6583f1d346d6ac8c1c511ca22b2 Mon Sep 17 00:00:00 2001 From: "Andy K. Massimino" Date: Sat, 6 May 2023 20:53:36 -0400 Subject: [PATCH] Add TS quote patterns re #234 --- after/queries/cpp/matchup.scm | 2 +- after/queries/javascript/matchup.scm | 2 ++ after/queries/lua/matchup.scm | 2 ++ after/queries/quote/matchup.scm | 7 +++++++ lua/treesitter-matchup/internal.lua | 11 ++++++++--- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 after/queries/quote/matchup.scm diff --git a/after/queries/cpp/matchup.scm b/after/queries/cpp/matchup.scm index 22039c9..7f8f292 100644 --- a/after/queries/cpp/matchup.scm +++ b/after/queries/cpp/matchup.scm @@ -1,4 +1,4 @@ -; inherits: c +; inherits: c,quote (template_parameter_list "<" @open.template diff --git a/after/queries/javascript/matchup.scm b/after/queries/javascript/matchup.scm index 9426592..b908fe4 100644 --- a/after/queries/javascript/matchup.scm +++ b/after/queries/javascript/matchup.scm @@ -1,3 +1,5 @@ +; inherits: quote + ; functions [ (arrow_function "=>" @open.function) diff --git a/after/queries/lua/matchup.scm b/after/queries/lua/matchup.scm index 5b9e2b0..b75d554 100644 --- a/after/queries/lua/matchup.scm +++ b/after/queries/lua/matchup.scm @@ -1,3 +1,5 @@ +; inherits: quote + (for_statement "do" @open.loop "end" @close.loop) @scope.loop diff --git a/after/queries/quote/matchup.scm b/after/queries/quote/matchup.scm new file mode 100644 index 0000000..a5c3493 --- /dev/null +++ b/after/queries/quote/matchup.scm @@ -0,0 +1,7 @@ +(_ + "\"" @open.quote_double + "\"" @close.quote_double) @scope.quote_double + +(_ + "'" @open.quote_single + "'" @close.quote_single) @scope.quote_single diff --git a/lua/treesitter-matchup/internal.lua b/lua/treesitter-matchup/internal.lua index d808217..00f0700 100644 --- a/lua/treesitter-matchup/internal.lua +++ b/lua/treesitter-matchup/internal.lua @@ -107,8 +107,10 @@ M.get_active_nodes = ts_utils.memoize_by_buf_tick(function(bufnr) for _, match in ipairs(matches) do if match.open then for key, open in pairs(match.open) do + local reject = key:find('quote') + and not M.get_option(bufnr, 'enable_quotes') local id = _node_id(open.node) - if open.node and symbols[id] == nil then + if not reject and open.node and symbols[id] == nil then table.insert(nodes.open, open.node) symbols[id] = key end @@ -116,8 +118,10 @@ M.get_active_nodes = ts_utils.memoize_by_buf_tick(function(bufnr) end if match.close then for key, close in pairs(match.close) do + local reject = key:find('quote') + and not M.get_option(bufnr, 'enable_quotes') local id = _node_id(close.node) - if close.node and symbols[id] == nil then + if not reject and close.node and symbols[id] == nil then table.insert(nodes.close, close.node) symbols[id] = key end @@ -359,7 +363,8 @@ function M.get_option(bufnr, opt_name) local lang = parsers.get_buf_lang(bufnr) if (opt_name == 'include_match_words' or opt_name == 'additional_vim_regex_highlighting' - or opt_name == 'disable_virtual_text') then + or opt_name == 'disable_virtual_text' + or opt_name == 'enable_quotes') then return opt_tbl_for_lang(config[opt_name], lang) end error('invalid option ' .. opt_name)