From 2eaf18826988f921ddb39e4a2e7d23d95bb0e52a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 21 Apr 2022 10:48:47 +0100 Subject: fix(fold): don't include whitespace end regions Some languages that are difficult to parse via Treesitter may incorrectly include whitespace lines at the end of regions. This can makes the calculated folds sub-optimal. To recitfy, use a custom directive (trim), to calculate the range with the trailing whitespace lines removed. Note this only works if the region end column is 0. Also added folds for Make. --- lua/nvim-treesitter/query.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lua/nvim-treesitter/query.lua') diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index bad1c27e..aeaa683b 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -209,7 +209,7 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row) local matches = query:iter_matches(qnode, bufnr, start_row, end_row) local function iterator() - local pattern, match = matches() + local pattern, match, metadata = matches() if pattern ~= nil then local prepared_match = {} @@ -219,6 +219,8 @@ function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row) if name ~= nil then local path = split(name .. ".node") insert_to_path(prepared_match, path, node) + local metadata_path = split(name .. ".metadata") + insert_to_path(prepared_match, metadata_path, metadata[id]) end end -- cgit v1.2.3