From f2fb792d781cfd8328136f5f73a710faa5c179c7 Mon Sep 17 00:00:00 2001 From: wenjin Date: Thu, 23 May 2024 17:59:34 +0800 Subject: [PATCH] fix(hurl): fold not work if set foldexpr to `vim.treesitter.foldexpr()` set filetype to `hurl-nvim` by default make `vim.treesitter.foldexpr()` not work, causes zc zo to fail. this commit check if edgy.nvim exists and then set filetype to hurl-nvim, otherwise just set filetype to input param type. --- lua/hurl/split.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/hurl/split.lua b/lua/hurl/split.lua index 3b912e1..8f08e36 100644 --- a/lua/hurl/split.lua +++ b/lua/hurl/split.lua @@ -5,9 +5,6 @@ local split = Split({ relative = 'editor', position = _HURL_GLOBAL_CONFIG.split_position, size = _HURL_GLOBAL_CONFIG.split_size, - -- Create a custom filetype so that we can use https://github.com/folke/edgy.nvim to manage the window - -- E.g: { title = "Hurl Nvim", ft = "hurl-nvim" }, - buf_options = { filetype = 'hurl-nvim' }, }) local utils = require('hurl.utils') @@ -22,6 +19,15 @@ local M = {} M.show = function(data, type) -- mount/open the component split:mount() + -- If have edgy.nvim + if pcall(require, 'edgy') then + -- Create a custom filetype so that we can use https://github.com/folke/edgy.nvim to manage the window + -- E.g: { title = "Hurl Nvim", ft = "hurl-nvim" }, + vim.api.nvim_buf_set_option(split.bufnr, 'filetype', 'hurl-nvim') + end + + -- Set content to highlight, refer https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770 + vim.api.nvim_buf_set_option(split.bufnr, 'filetype', type) if _HURL_GLOBAL_CONFIG.auto_close then -- unmount component when buffer is closed @@ -57,9 +63,6 @@ M.show = function(data, type) split:map('n', 'q', function() quit() end) - - -- Set content to highlight, refer https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770 - vim.api.nvim_buf_set_option(split.bufnr, 'filetype', type) end M.clear = function()