feat(preview): Use treesitter for highlighting if possible

Closes #27
This commit is contained in:
simrat39
2021-06-14 15:55:35 -07:00
parent e4172c803c
commit c6318d9279

View File

@@ -65,6 +65,17 @@ end
local function setup_preview_buf()
local code_buf = vim.api.nvim_win_get_buf(main.state.code_win)
local ft = vim.api.nvim_buf_get_option(code_buf, "filetype")
local function treesitter_attach()
local ts_highlight = require('nvim-treesitter.highlight')
local ts_parsers = require('nvim-treesitter.parsers')
ts_highlight.attach(state.preview_buf, ft)
end
-- user might not have tree sitter installed
pcall(treesitter_attach)
vim.api.nvim_buf_set_option(state.preview_buf, "syntax", ft)
vim.api.nvim_buf_set_option(state.preview_buf, "bufhidden", "delete")
vim.api.nvim_win_set_option(state.preview_win, "cursorline", true)