diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a389ca0..73e84568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ vim.keymap.set('i', '', 'u[s1z=`]au', { desc = 'Correct late ## mini.pick - FEATURE: Implement `window.prompt_cursor` and `window.prompt_prefix` config options. +- FEATURE: Update `builtin.help()` to use tree-sitter highlighting (if there is any). ## mini.sessions diff --git a/lua/mini/pick.lua b/lua/mini/pick.lua index 29040e59..866a40ed 100644 --- a/lua/mini/pick.lua +++ b/lua/mini/pick.lua @@ -1349,7 +1349,9 @@ MiniPick.builtin.help = function(local_opts, opts) -- Take advantage of `taglist` output on how to open tag vim.api.nvim_buf_call(buf_id, function() vim.cmd('noautocmd edit ' .. vim.fn.fnameescape(item.filename)) - vim.bo.buftype, vim.bo.buflisted, vim.bo.bufhidden, vim.bo.syntax = 'nofile', false, 'wipe', 'help' + vim.bo.buftype, vim.bo.buflisted, vim.bo.bufhidden = 'nofile', false, 'wipe' + local has_ts = pcall(vim.treesitter.start, 0) + if not has_ts then vim.bo.syntax = 'help' end local cache_hlsearch = vim.v.hlsearch -- Make a "very nomagic" search to account for special characters in tag diff --git a/tests/screenshots/tests-test_pick.lua---builtin.help()---has-proper-preview b/tests/screenshots/tests-test_pick.lua---builtin.help()---has-proper-preview index 947affcb..c4c90a80 100644 --- a/tests/screenshots/tests-test_pick.lua---builtin.help()---has-proper-preview +++ b/tests/screenshots/tests-test_pick.lua---builtin.help()---has-proper-preview @@ -22,11 +22,11 @@ 04|11111111111111111111111111111111111111111111111111111111111111111111111111111111 05|23222222222222222222222222222222222222222222222222211111111111111111111111111111 06|24444444444444444444444444444444444444444444444444211111111111111111111111111111 -07|25666666666666666644444445555555666666665555555555211111111111111111111111111111 +07|25555555555555555544444445555555666666665555555555211111111111111111111111111111 08|24444444444444444444444445555555566666666555555555211111111111111111111111111111 09|25555555555555555555555555555555555555555555555555211111111111111111111111111111 10|24444444444444444444444444444444444444444444444444211111111111111111111111111111 -11|25566666666444444444444445555555666666655555555555211111111111111111111111111111 +11|25555555555444444444444445555555555555555555555555211111111111111111111111111111 12|24444444444444444444444446666666655555555555555555211111111111111111111111111111 13|25555555555555555555555555555555555555555555555555211111111111111111111111111111 14|22222222222222222222222222222222222222222222222222211111111111111111111111111111 diff --git a/tests/screenshots/tests-test_pick.lua---builtin.help()---works-for-help-tags-with-special-characters b/tests/screenshots/tests-test_pick.lua---builtin.help()---works-for-help-tags-with-special-characters index fc900487..09ff87b7 100644 --- a/tests/screenshots/tests-test_pick.lua---builtin.help()---works-for-help-tags-with-special-characters +++ b/tests/screenshots/tests-test_pick.lua---builtin.help()---works-for-help-tags-with-special-characters @@ -21,13 +21,13 @@ 03|11111111111111111111111111111111111111111111111111111111111111111111111111111111 04|11111111111111111111111111111111111111111111111111111111111111111111111111111111 05|23333333322222222222222222222222222222222222222222211111111111111111111111111111 -06|24444445444444454444444666666666666666666666666666211111111111111111111111111111 -07|26666666666666666555555555555555555557777777755555211111111111111111111111111111 -08|26666666666666666555555555555555555555555555555555211111111111111111111111111111 -09|25555555555555555555555555555555555555555555555555211111111111111111111111111111 -10|24444445444444444466666666666666666666666666666666211111111111111111111111111111 -11|26666666666666666555555555555555555555555555555555211111111111111111111111111111 -12|26666666666666666555555544444455555555555555555555211111111111111111111111111111 -13|26666666666666666555555555555555555555555555555555211111111111111111111111111111 +06|24444444555555545555555666666666666666666666666666211111111111111111111111111111 +07|26666666666666666444444444444444444447777777744444211111111111111111111111111111 +08|26666666666666666444444444444444444444444444444444211111111111111111111111111111 +09|24444444444444444444444444444444444444444444444444211111111111111111111111111111 +10|24444444555555555566666666666666666666666666666666211111111111111111111111111111 +11|26666666666666666444444444444444444444444444444444211111111111111111111111111111 +12|26666666666666666444444488888844444444444444444444211111111111111111111111111111 +13|26666666666666666444444444444444444444444444444444211111111111111111111111111111 14|22222222222222222222222222222222222222222222222222211111111111111111111111111111 15|00000000000000000000000000000000000000000000000000000000000000000000000000000000 diff --git a/tests/test_pick.lua b/tests/test_pick.lua index 9f4bd4e3..a0278ab9 100644 --- a/tests/test_pick.lua +++ b/tests/test_pick.lua @@ -2733,7 +2733,8 @@ T['builtin.help()']['has proper preview'] = function() type_keys('') child.expect_screenshot() eq(child.bo.buftype, 'nofile') - eq(child.bo.syntax, 'help') + -- Neovim<0.8 should use built-in syntax, while Neovim>=0.8 - tree-sitter + if child.fn.has('nvim-0.8') == 0 then eq(child.bo.syntax, 'help') end eq(child.v.hlsearch, 0) eq(child.fn.getreg('/'), 'aa')