diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-02-13 10:54:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-13 10:54:03 +0000 |
commit | d359f7a533bdec9f9f4a51244fefc01064d8b9f9 (patch) | |
tree | f2df533c2f048bdd29144bbf1dce580fea7e52ba /runtime/lua/vim/treesitter.lua | |
parent | 89722ddfac51b0f7cbe5f4b0914e19ee9e8fdfd6 (diff) | |
parent | 8a985d12dd6b4a5a4ba825939f36b7b1a324d849 (diff) | |
download | rneovim-d359f7a533bdec9f9f4a51244fefc01064d8b9f9.tar.gz rneovim-d359f7a533bdec9f9f4a51244fefc01064d8b9f9.tar.bz2 rneovim-d359f7a533bdec9f9f4a51244fefc01064d8b9f9.zip |
Merge pull request #22191 from lewis6991/feat/playground_imp
feat(treesitter): playground improvements
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 96b1e24ba9..4127198576 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -96,11 +96,13 @@ function M.get_parser(bufnr, lang, opts) if bufnr == nil or bufnr == 0 then bufnr = a.nvim_get_current_buf() end - if lang == nil then - lang = a.nvim_buf_get_option(bufnr, 'filetype') - end - if parsers[bufnr] == nil or parsers[bufnr]:lang() ~= lang then + if parsers[bufnr] == nil then + lang = lang or a.nvim_buf_get_option(bufnr, 'filetype') + parsers[bufnr] = M._create_parser(bufnr, lang, opts) + elseif lang and parsers[bufnr]:lang() ~= lang then + -- Only try to create a new parser if lang is provided + -- and it doesn't match the stored parser parsers[bufnr] = M._create_parser(bufnr, lang, opts) end @@ -411,6 +413,7 @@ function M.show_tree(opts) vim.bo[b].buflisted = false vim.bo[b].buftype = 'nofile' vim.bo[b].bufhidden = 'wipe' + vim.bo[b].filetype = 'query' local title = opts.title if not title then @@ -425,9 +428,6 @@ function M.show_tree(opts) pg:draw(b) - vim.fn.matchadd('Comment', '\\[[0-9:-]\\+\\]') - vim.fn.matchadd('String', '".*"') - a.nvim_buf_clear_namespace(buf, pg.ns, 0, -1) a.nvim_buf_set_keymap(b, 'n', '<CR>', '', { desc = 'Jump to the node under the cursor in the source buffer', @@ -467,6 +467,15 @@ function M.show_tree(opts) end_col = math.max(0, pos.end_col), hl_group = 'Visual', }) + + local topline, botline = vim.fn.line('w0', win), vim.fn.line('w$', win) + + -- Move the cursor if highlighted range is completely out of view + if pos.lnum < topline and pos.end_lnum < topline then + a.nvim_win_set_cursor(win, { pos.end_lnum + 1, 0 }) + elseif pos.lnum > botline and pos.end_lnum > botline then + a.nvim_win_set_cursor(win, { pos.lnum + 1, 0 }) + end end, }) |