kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.23k stars 44 forks source link

Syntax highlighting on folds #35

Closed ranebrown closed 2 years ago

ranebrown commented 2 years ago

Neovim version (nvim -v | head -n1)

v0.8.0-dev+513-g01fc5097d

Operating system/version

macOS 12.4

How to reproduce the issue

  1. Open file and syntax highlighting does not penetrate folds.
  2. :TSBufDisable highlight
  3. Open/close folds to refresh and highlighting appears.

Expected behavior

Syntax highlighting on folds while using treesitter highlighting.

Actual behavior

Highlighting only shows up after disabling treesitter highlighting and using regex i.e. :TSBufDisable highlight

kevinhwang91 commented 2 years ago

What's your treesitter parser?

lua =require('vim.treesitter.highlighter').active[vim.api.nvim_get_current_buf()]

ranebrown commented 2 years ago

I've seen the same behavior with lua and cpp parsers.

Output ``` <1>{ =require('vim.treesitter.highlighter').active[vim.api.nvim_get_current_buf()] _highlight_states = { [] = { iter = , next_row = 48 } }, _queries = { cpp = { _query = { captures = <2>{ "variable", "keyword", "keyword.operator", "keyword.return", "repeat", "conditio nal", "constant.macro", "include", "operator", "boolean", "punctuation.delimiter", "punctuation.special" , "punctuation.bracket", "string", "string.escape", "constant.builtin", "number", "character", "function .macro", "property", "_parent", "label", "type", "constant", "_u", "function", "comment", "parameter", " attribute", "error", "field", "method", "namespace", "constructor", "function.builtin", "variable.builti n", "exception" }, info = { captures = , patterns = { [23] = { { "not-has-parent?", 21, "template_method", "function_declarator", "call_expression " } }, [25] = { { "has-ancestor?", 20, "field_declaration" }, { "not-has-ancestor?", 20, "function_ declarator" } }, [29] = { { "lua-match?", 24, "^[A-Z][A-Z0-9_]+$" } }, [33] = { { "eq?", 25, "#undef" } }, [44] = { { "match?", 31, "(^_|^m_|_$)" } }, [50] = { { "has-parent?", 21, "template_method", "function_declarator", "call_expression" } }, [55] = { { "lua-match?", 23, "^[A-Z]" } }, [56] = { { "lua-match?", 24, "^[A-Z][A-Z_0-9]*$" } }, [63] = { { "lua-match?", 34, "^[A-Z]" } }, [71] = { { "lua-match?", 34, "^[A-Z]" } }, [72] = { { "lua-match?", 34, "^[A-Z]" } }, [73] = { { "lua-match?", 34, "^[A-Z]" } }, [74] = { { "lua-match?", 34, "^[A-Z]" } } } }, query = , = <3>{ __index =
, apply_directives = , iter_captures = , iter_matches = , match_preds = } }, hl_cache = { 984, [5] = 990, [6] = 992, [9] = 989, [11] = 988, [13] = 986, [17] = 991, [23] = 983, [26] = 985, [28] = 987, [30] = 993, = { __index = } }, = { __index = <4>{ __index =
, _get_hl_from_capture = , new = , query = } } } }, bufnr = 1, edit_count = 0, line_count = {}, redraw_count = 11, tree = { _callbacks = { bytes = { }, changedtree = { }, child_added = {}, child_removed = {}, detach = { } }, _children = {}, _injection_query = { captures = <5>{ "cpp", "comment" }, info = { captures =
, patterns = {} }, query = , =
}, _lang = "cpp", _opts = {}, _parser = , _regions = {}, _source = 1, _trees = { }, _valid = true, = <6>{ __index =
, _do_callback = , _get_injections = , _on_bytes = , _on_detach = , _on_reload = , add_child = , children = , contains = , destroy = , for_each_child = , for_each_tree = , included_regions = , invalidate = , is_valid = , lang = , language_for_range = , new = , parse = , register_cbs = , remove_child = , set_included_regions = , source = , trees = } }, = <7>{ __index =
, _on_buf = , _on_line = , _on_win = , active = {
}, destroy = , get_highlight_state = , get_query = , hl_map = { annotation = "TSAnnotation", attribute = "TSAttribute", boolean = "TSBoolean", character = "TSCharacter", ["character.special"] = "TSCharacterSpecial", comment = "TSComment", conditional = "TSConditional", constant = "TSConstant", ["constant.builtin"] = "TSConstBuiltin", ["constant.macro"] = "TSConstMacro", constructor = "TSConstructor", debug = "TSDebug", define = "TSDefine", error = "TSError", exception = "TSException", field = "TSField", float = "TSFloat", function = "TSFunction", ["function.builtin"] = "TSFuncBuiltin", ["function.macro"] = "TSFuncMacro", ["function.special"] = "Function", include = "TSInclude", keyword = "TSKeyword", ["keyword.function"] = "TSKeywordFunction", ["keyword.operator"] = "TSKeywordOperator", ["keyword.return"] = "TSKeywordReturn", label = "TSLabel", macro = "Macro", method = "TSMethod", namespace = "TSNamespace", none = "TSNone", number = "TSNumber", operator = "TSOperator", parameter = "TSParameter", ["parameter.reference"] = "TSParameterReference", preproc = "TSPreProc", property = "TSProperty", ["punctuation.bracket"] = "TSPunctBracket", ["punctuation.delimiter"] = "TSPunctDelimiter", ["punctuation.special"] = "TSPunctSpecial", repeat = "TSRepeat", storageclass = "TSStorageClass", string = "TSString", ["string.escape"] = "TSStringEscape", ["string.regex"] = "TSStringRegex", ["string.special"] = "TSStringSpecial", structure = "Structure", symbol = "TSSymbol", tag = "TSTag", ["tag.attribute"] = "TSTagAttribute", ["tag.delimiter"] = "TSTagDelimiter", text = "TSText", ["text.danger"] = "TSDanger", ["text.emphasis"] = "TSEmphasis", ["text.environment"] = "TSEnvironment", ["text.environment.name"] = "TSEnvironmentName", ["text.literal"] = "TSLiteral", ["text.math"] = "TSMath", ["text.note"] = "TSNote", ["text.reference"] = "TSTextReference", ["text.strike"] = "TSStrike", ["text.strong"] = "TSStrong", ["text.title"] = "TSTitle", ["text.underline"] = "TSUnderline", ["text.uri"] = "TSURI", ["text.warning"] = "TSWarning", todo = "TSTodo", type = "TSType", ["type.builtin"] = "TSTypeBuiltin", ["type.definition"] = "TSTypeDefinition", ["type.qualifier"] = "TSTypeQualifier", variable = "TSVariable", ["variable.builtin"] = "TSVariableBuiltin", = { __index = } }, new = , on_bytes = , on_changedtree = , on_detach = , reset_highlight_state = } } ```
kevinhwang91 commented 2 years ago

can't reproduce, use a minimal config about treesitter please.

jaschenb commented 2 years ago

I have a similar problem. It seems the treesitter provider takes the highlights from syntax or something. I have a custom colorscheme and it displays the 'normal' highlights like String correctly, however things like TSVariable are white as soon as I close the fold. I tried to look into things yesterday, but I'm also not familiar with Treesitter to much, so I couldn't figure out, where to look for the highlight groups your plugin returns.

ranebrown commented 2 years ago

I was deleting plugins to try and find what might be causing the issue and I'm not seeing the behavior anymore after re-enabling everything. I'm wondering if there were some old treesitter queries laying around causing issues. I'll report back if I figure out what was causing the issue but seems ok for me now.

kevinhwang91 commented 2 years ago

I have a similar problem. It seems the treesitter provider takes the highlights from syntax or something. I have a custom colorscheme and it displays the 'normal' highlights like String correctly, however things like TSVariable are white as soon as I close the fold. I tried to look into things yesterday, but I'm also not familiar with Treesitter to much, so I couldn't figure out, where to look for the highlight groups your plugin returns.

https://github.com/kevinhwang91/nvim-ufo/blob/98b07fc2606c40ae5bf0eaf67e74d8b82a69f040/lua/ufo/render/treesitter.lua#L42

kevinhwang91 commented 2 years ago

close the issue, ping me it has been reproduced.