kevinhwang91 / nvim-ufo

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

feat(render): add support for concealed characters (#153) #156

Closed milisims closed 9 months ago

milisims commented 10 months ago

For testing, a simple example would be to add the following to vim.fn.stdpath('config') .. '/after/queries/lua/highlights.scm'

; extends
(function_declaration "function" @constant (#set! conceal "𝑓"))
kevinhwang91 commented 10 months ago

nvim-ufo should work under 0.7.2 version for neovim which is a stable version for ubuntu 22 lts, so don't use a function program API; Don't change the code for "better to read", the captureVirtText function is inside decoration_provider, and shouldn't use the core API.

I suggest you just change the code about concealed extmarks. Of course, you can also capture the concealed in synconcealed() if you are interested in the old highlight group system in vim.

milisims commented 10 months ago

nvim-ufo should work under 0.7.2 version for neovim which is a stable version for ubuntu 22 lts, so

I suggest you just change the code about concealed extmarks. Of course, you can also capture the concealed in synconcealed() if you are interested in the old highlight group system in vim.

I'll add synconcealed() support after a quick review:

I originally attempted to simply add an insertConcealed, but because conceal and inlays both change the length of the text trying to track the col and endCol with an offset was a nightmare. I had to change/remove fillSlots and insertInlay. Doing them at the same time made it possible for me to implement.

How does it look now? (before I look into adding synconcealed())

kevinhwang91 commented 10 months ago

Before checking the conceal, the 'conceallevel' option should be more than zero.

milisims commented 10 months ago

Added synconcealed support & made the rest of the changes, happy to address anything else but this works very well in my testing

kevinhwang91 commented 10 months ago

Should add concealLevel parameter to M.captureVirtText(bufnr, text, lnum, syntax, namespaces): 1: 0 will pass the conceal logic; 2: 1 and 2 show the cchar which is the first char of conceal extmark; 3: 3 hide the concealed range;

milisims commented 10 months ago

I think this is good for merge unless there's anything else you can think of!

kevinhwang91 commented 10 months ago

Thanks, I will append some commits in this PR. There are some details that are hard to say, you can check out the commit.

And I found an issue like below image: image

After adding virtual text or conceal, the width of foldtext output is not fixed sometime. The char text of foldtext output should map to the virtual text captured by ufo, otherwise, there is a flicker issue. The reason is adding extmarks in a decorator render in the next tick, but foldtext renders in the current tick.

I will rework the module to fix this issue later.

kevinhwang91 commented 9 months ago

Have appended some commits, feel free to review them. No issue will merge into main.

milisims commented 9 months ago

Other than typo looks great to me

kevinhwang91 commented 9 months ago

Thanks!