Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance for new inline option #80

Open
brenoprata10 opened this issue May 19, 2024 · 24 comments
Open

Improve performance for new inline option #80

brenoprata10 opened this issue May 19, 2024 · 24 comments
Assignees
Labels
enhancement New feature or request

Comments

@brenoprata10
Copy link
Owner

After neovim 0.10, the new inline option seems to take a big performance hit. I need to check and polish the code to make it faster

@brenoprata10 brenoprata10 added the enhancement New feature or request label May 19, 2024
@brenoprata10 brenoprata10 self-assigned this May 19, 2024
@catgoose
Copy link

I haven't tested this plugin prior to 0.10, but are you experiencing a flicker on textchange event?

@brenoprata10
Copy link
Owner Author

Yes I am working on a fix for it

@jorgebef
Copy link

jorgebef commented Jun 4, 2024

I would love to help out with the issue causing the flicker.
I've checked out another plugin that manages to display the colors inline as virtual text and doesn't flicker while doing so:
https://github.com/luckasRanarison/tailwind-tools.nvim/blob/a95aaf11d9deca884743c9017323c0ffea0015f2/lua/tailwind-tools/lsp.lua#L10

I believe they are taking a debounced request approach as seen in the debounced_color_request, however, I don't know what is causing the actual flickering of the virtual text character in this plugin.

@brenoprata10
Copy link
Owner Author

The flickering is happening due to the lsp integration. I have already planned a way to fix it, but I do not have the time to code it right now :(

@brenoprata10
Copy link
Owner Author

I've pushed a2a20e8 which fixes the flickering while editing. Please give it a try and report any bugs here for me 😄

@brenoprata10
Copy link
Owner Author

I've just found a few bugs on it, will be reverting for now

@serhez
Copy link

serhez commented Jun 17, 2024

Perhaps updating on InsertLeave or something similar would help? IMO it's not necessary for the colors to change on every keystroke, but just when I finish typing. If I am typing something that is not a color, then the rendered colors would not change anyway; if I'm typing a color, I would only want to see it rendered when I finish doing so. Perhaps this could even be a config option, e.g., update_autocmd.

@chrsrns
Copy link

chrsrns commented Jun 19, 2024

Perhaps updating on InsertLeave or something similar would help? IMO it's not necessary for the colors to change on every keystroke, but just when I finish typing. If I am typing something that is not a color, then the rendered colors would not change anyway; if I'm typing a color, I would only want to see it rendered when I finish doing so. Perhaps this could even be a config option, e.g., update_autocmd.

This makes sense to me. I usually use a color picker tool to find and view colors before putting them in code. I don't usually need to see the colors as I type them too.

@brenoprata10
Copy link
Owner Author

I will check this one out again this weekend

@brenoprata10
Copy link
Owner Author

I've put some hours in it this morning. I've just pushed the code which fixes the flickering text.
Could you guys give it a try again?

CC @jorgebef @catgoose

@serhez
Copy link

serhez commented Jun 23, 2024

@brenoprata10 I still get this:

Screen.Recording.2024-06-23.at.14.31.19.mov

@brenoprata10
Copy link
Owner Author

Could you describe your auto complete setup?

@brenoprata10
Copy link
Owner Author

Also, could you share this template tag?

@brenoprata10
Copy link
Owner Author

I've pushed some code. Could you give it a try again?

@serhez
Copy link

serhez commented Jun 23, 2024

@brenoprata10 with the newer commits, the issue gets worse (most colors now flicker). I also get the following error:

Error executing vim.schedule lua callback: ...vim-highlight-colors/lua/nvim-highlight-colors/utils.lua:193: attempt to index a nil value
stack traceback:
	...vim-highlight-colors/lua/nvim-highlight-colors/utils.lua:193: in function 'handler'
	.../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:685: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

I use cmp. You can find my config here.

Template tag:

<template>
    <div
        class="relative p-8 lg:p-14 bg-[#ffffff] lg:bg-zinc-50 lg:rounded-xl shadow-md hover:shadow-xl transition-shadow duration-300 ease-in-out overflow-y-auto">
        <button @click="$emit('close')"
            class="absolute top-6 right-7 lg:top-8 lg:right-8 text-zinc-600 hover:text-zinc-300">
            <icon name="heroicons-solid:x" class="h-6 w-6 lg:h-7 lg:w-7" />
        </button>
        <div class="flex flex-col divide-y-2">
            <div class="flex flex-col gap-2 pb-3">
                <h2 class="text-xl font-bold tracking-tight sm:text-2xl sm:leading-tight">{{ model?.title }}</h2>
                <div class="flex flex-col gap-1 text-zinc-700 italic">
                    <h3 class="text-lg tracking-tight sm:text-xl sm:leading-tight">
                        {{ model?.authors.join(', ') }}
                    </h3>
                    <h4 class="text-lg tracking-tight sm:text-xl sm:leading-tight">
                        {{ model?.venue }} - {{ model?.year }}
                    </h4>
                </div>
            </div>
            <div class="flex flex-col gap-4 pt-3">
                <p class="text-zinc-600">{{ model?.abstract }}</p>
                <div class="flex gap-6">
                    <a v-for="link in model?.links" :key="link.title" :href="link.url" :title="link.title"
                        class="text-zinc-600 transition hover:text-zinc-300" rel="me  noopener" target="_blank">
                        <icon :name="link.icon" class="h-6 w-6" />
                    </a>
                </div>
            </div>
        </div>
    </div>
</template>

@brenoprata10
Copy link
Owner Author

brenoprata10 commented Jun 23, 2024

The nil issue was fixed already. Please update the plugin.
As for the colors. it's hard to believe it could get worse with the code that was added. Could someone else here test the latest changes?

@serhez
Copy link

serhez commented Jun 23, 2024

Would it not be possible to change the events listed here to InsertLeave or something similar, instead of TextChanged?

@brenoprata10
Copy link
Owner Author

Will give it a try later

@serhez
Copy link

serhez commented Jun 23, 2024

Here is another screen recording with the newer changes:

Screen.Recording.2024-06-23.at.16.39.53.mov

@brenoprata10
Copy link
Owner Author

I have modified the autocmd as asked. Could you please check if things are still working properly?

@brenoprata10
Copy link
Owner Author

brenoprata10 commented Jun 23, 2024

Now the colors will not highlight when user deletes a line with dd or use X in normal mode.
Does anyone know of an autocmd that I could use to handle these cases?

@serhez
Copy link

serhez commented Jun 23, 2024

Maybe TextChanged actually covers this (changes in normal mode) and TextChangedI covers changes in insert mode? I'm reading here and here. Perhaps just removing TextChangedI from the original list of events would solve the issue?

EDIT: Actually, I'm guessing you would need to swap TextChangedI for InsertLeave, and keep the other events.

@brenoprata10
Copy link
Owner Author

You're right!
Changing TextChangedI with InsertLeave fixes the flickering and the plugin still works fine :)

@brenoprata10
Copy link
Owner Author

I've pushed the code. Please give it a go and let me know if you find any issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants