shellRaining / hlchunk.nvim

This is the lua implementation of nvim-hlchunk, you can use this neovim plugin to highlight your indent line and the current chunk (context) your cursor stayed
MIT License
472 stars 29 forks source link

Exclude files based on `buftype` #79

Closed hinell closed 2 months ago

hinell commented 7 months ago

Thank you for the great project.

Is your feature request related to a problem? Please describe. Nope.

Describe the solution you'd like Exclude files by using buftype, see vimdoc help on that one.

shellRaining commented 7 months ago

ok, i will try to improve this

dsully commented 6 months ago

Additionally, the include types should be on filetype instead of extension as well. I currently need to exclude the following:

["bzl"] = true,
["cfg"] = true,
["gitcommit"] = true,
["json5"] = true,
["jsonc"] = true,
["just"] = true,
["sshdconfig"] = true,
["text"] = true,

As support_filetypes has "*.json" listed.

However, I don't think this is the right approach.

If I make this change:

diff --git hlchunk/mods/chunk.lua hlchunk/mods/chunk.lua
index 65e3064..02618b0 100644
--- hlchunk/mods/chunk.lua
+++ hlchunk/mods/chunk.lua
@@ -49,7 +49,7 @@ end

 -- set new virtual text to the right place
 function chunk_mod:render(opts)
-    if not self.options.enable or self.options.exclude_filetypes[vim.bo.ft] then
+    if not self.options.enable or not vim.tbl_contains(self.options.support_filetypes, vim.bo.ft) then
         return
     end

@@ -158,8 +158,7 @@ function chunk_mod:enable_mod_autocmd()

     api.nvim_create_autocmd({ "CursorMovedI", "CursorMoved" }, {
         group = self.augroup_name,
-        pattern = self.options.support_filetypes,
             local cur_win_info = fn.winsaveview()
             local old_win_info = chunk_mod.old_win_info

@@ -176,8 +175,7 @@ function chunk_mod:enable_mod_autocmd()
     })
     api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, {
         group = self.augroup_name,
-        pattern = self.options.support_filetypes,
             chunk_mod:render({ lazy = false })
         end,
     })
diff --git hlchunk/utils/filetype.lua hlchunk/utils/filetype.lua
index 19bce2c..15628ed 100644
--- hlchunk/utils/filetype.lua
+++ hlchunk/utils/filetype.lua
@@ -1,24 +1,20 @@
 local M = {}

 M.support_filetypes = {
-    "*.ts",
-    "*.tsx",
-    "*.js",
-    "*.jsx",
-    "*.html",
-    "*.json",
-    "*.go",
-    "*.c",
-    "*.py",
-    "*.cpp",
-    "*.rs",
-    "*.h",
-    "*.hpp",
-    "*.lua",
-    "*.vue",
-    "*.java",
-    "*.cs",
-    "*.dart",
+    "typescript",
+    "javascript",
+    "html",
+    "json",
+    "go",
+    "c",
+    "python",
+    "cpp",
+    "rust",
+    "lua",
+    "vue",
+    "java",
+    "csharp",
+    "dart",
 }

 M.exclude_filetypes = {

Then only explicitly included file types will be used. I think this is a better than the file extension autocommand match + an ever growing list of excluded types.

Happy to put together a full PR if you're good with this change.

hinell commented 6 months ago

@dsully There are 3 PRs that haven't been merged since 2023, including mine. Don't expect much.

dsully commented 6 months ago

@dsully There are 3 PRs that haven't been merged since 2023, including mine. Don't expect much.

Yeah - I just forked the repo and committed the change above for my usage.

shellRaining commented 2 months ago

in recent commit I have change to vim.filetype.match, as for support_filetype, I have removed this.

If there are any further questions, welcome to open again

hinell commented 1 month ago

@shellRaining Are you on a feature-hunting spree? Haven't seen you in a while. :smile:

Thanks for great work!

shellRaining commented 1 month ago

Yes, I have been relatively free recently. Past months I was busy with school matters 😄

shellRaining commented 1 month ago

@hinell I plan to replace vim.filetype.match with vim.bo[bufnr].ft because the former has performance problem, and each call takes about 1ms.

hlchunk_v120_ft_match hlchunk_v120_ft_bo

hope can understand~

hinell commented 1 month ago

@shellRaining Nice. What tool have you used to generate a flamegraph?

shellRaining commented 1 month ago

@hinell profile.nvim