mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-18 01:38:57 +00:00
Add TS lang-based skips, fixes #198
This commit is contained in:
@@ -63,3 +63,5 @@
|
||||
(do_block
|
||||
"do" @open.do
|
||||
"end" @close.do) @scope.do
|
||||
|
||||
(if_modifier) @skip
|
||||
|
||||
@@ -18,7 +18,15 @@ function! matchup#ts_syntax#synID(lnum, col, trans) abort
|
||||
return s:forward('synID', a:lnum, a:col, a:trans)
|
||||
endfunction
|
||||
|
||||
function! matchup#ts_syntax#lang_skip(lnum, col) abort
|
||||
return s:forward('lang_skip', a:lnum, a:col)
|
||||
endfunction
|
||||
|
||||
function! matchup#ts_syntax#skip_expr(lnum, col) abort
|
||||
if matchup#ts_syntax#lang_skip(a:lnum, a:col)
|
||||
return 1
|
||||
endif
|
||||
|
||||
let l:syn = synIDattr(matchup#ts_syntax#synID(
|
||||
\ a:lnum, a:col, 1), 'name')
|
||||
return l:syn =~? '\%(String\|Comment\)'
|
||||
|
||||
@@ -9,6 +9,8 @@ end
|
||||
|
||||
local api = vim.api
|
||||
local hl_info = require'treesitter-matchup.third-party.hl-info'
|
||||
local queries = require'treesitter-matchup.third-party.query'
|
||||
local ts_utils = require'nvim-treesitter.ts_utils'
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -18,6 +20,40 @@ function M.is_active(bufnr)
|
||||
and api.nvim_buf_get_option(bufnr, 'syntax') == '')
|
||||
end
|
||||
|
||||
--- Get all nodes that are marked as skip
|
||||
function M.get_skips(bufnr)
|
||||
local matches = queries.get_matches(bufnr, 'matchup')
|
||||
|
||||
local skips = {}
|
||||
|
||||
for _, match in ipairs(matches) do
|
||||
if match.skip then
|
||||
skips[match.skip.node:id()] = 1
|
||||
end
|
||||
end
|
||||
|
||||
return skips
|
||||
end
|
||||
|
||||
function M.lang_skip(lnum, col)
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local skips = M.get_skips(bufnr)
|
||||
|
||||
if vim.tbl_isempty(skips) then
|
||||
return false
|
||||
end
|
||||
|
||||
local node = ts_utils.get_node_at_cursor()
|
||||
if not node then
|
||||
return false
|
||||
end
|
||||
if skips[node:id()] then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function M.synID(lnum, col, transparent)
|
||||
if not M.is_active() then
|
||||
return vim.fn.synID(lnum, col, transparent)
|
||||
|
||||
Reference in New Issue
Block a user