nvim-config

Log | Files | Refs | Submodules | README

matchparrents.lua (1398B)


      1 local PAREN_CHARS = {
      2   ['('] = true,
      3   [')'] = false,
      4   ['{'] = true,
      5   ['}'] = false,
      6   ['['] = true,
      7   [']'] = false,
      8 }
      9 
     10 -- local ns = vim.api.nvim_create_namespace('ts_matchpaten')
     11 -- vim.api.nvim_create_autocmd('CursorMoved', {
     12 --   callback = function()
     13 --     vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
     14 --     local cursor = vim.api.nvim_win_get_cursor(0)
     15 --     local row, col = cursor[1] - 1, cursor[2]
     16 --     local cursor_char = vim.api.nvim_buf_get_text(0, row, col, row, col + 1, {})[1]
     17 --
     18 --     local match = PAREN_CHARS[cursor_char]
     19 --     if match == nil then
     20 --       return
     21 --     end
     22 --
     23 --     local ok, res = pcall(vim.treesitter.get_node)
     24 --     if not ok then return end
     25 --
     26 --     local node = {res:range()}
     27 --     local row2, col2 --- @type integer, integer
     28 --     if match then
     29 --       row2, col2 = node[3], node[4] -1
     30 --     else
     31 --       row2, col2 = node[1], node[2]
     32 --     end
     33 --
     34 --     local cursor_char2 = vim.api.nvim_buf_get_text(0, row2, col2, row2, col2 + 1, {})[1]
     35 --
     36 --     vim.api.nvim_buf_set_extmark(0, ns, row, col, {
     37 --       end_row = row,
     38 --       end_col = col+1,
     39 --       end_right_gravity = false,
     40 --       hl_group = 'MatchParen'
     41 --     })
     42 --
     43 --     vim.api.nvim_buf_set_extmark(0, ns, row2, col2, {
     44 --       end_row = row2,
     45 --       end_col = col2+1,
     46 --       end_right_gravity = false,
     47 --       hl_group = 'MatchParen'
     48 --     })
     49 --   end
     50 -- })