nvim-code-action-menu icon indicating copy to clipboard operation
nvim-code-action-menu copied to clipboard

Integration with Coc?

Open yatesco opened this issue 4 years ago • 15 comments

Hi there - this looks great. Does it only integrate with the native LSP? If I run code actions from Coc I get a bunch but if I run CodeActionMenu without changing the cursor I get "No code actions available!"

image image

yatesco avatar Sep 29 '21 09:09 yatesco

I'm sorry to say, but this does not support CoC. I have 0 experience with CoC. How easy is it to ask CoC for code actions at the current cursor location? 🤔 So I could add the feature that it tries both, the native LSP clients and CoC (if available).

weilbith avatar Sep 29 '21 10:09 weilbith

No problem at all :-). I have no idea either, I was just wondering if it was already done. I could add this to my never-ending list of TODOs but... :-(.

I'm converting over to native LSP anyway, I just need to make Telescope as fast as FZF to complete the switch .

yatesco avatar Sep 29 '21 10:09 yatesco

Haha okay. Let's see if more users want this. I don't need it, but it looks like it is fairly easy to add. Depending on how easy CoC is to use. Though I would rather not like to add CoC to my local setup to test it. So I appreciate if someone would open a PR 😬

weilbith avatar Sep 29 '21 10:09 weilbith

It would be really great if this plugin could support CoC as a source. It should be be pretty easy to get a code action from CoC. There's a <Plug> mapping for it, which is mapped to :<C-u>call CocActionAsync('codeAction', 'cursor') here

TxHawks avatar Oct 01 '21 18:10 TxHawks

Hey guys, check this https://github.com/xiyaowong/coc-code-action-menu

@TxHawks @yatesco

xiyaowong avatar Oct 02 '21 00:10 xiyaowong

@xiyaowong Thanks!

@weilbith Would you be open to integrating @xiyaowong's work into this repo? Seems like a shame to keep two different plugins that are likely to get out of sync at some point

TxHawks avatar Oct 02 '21 07:10 TxHawks

I'm honestly confused about @xiyaowong. Why isn't he just doing this in a feature branch and open a PR for it. Just discussing the solution together. That's usually how open source projects work. Yes therefore you have to fork the repo. But why rename it, don't open a PR and advertise it? I was going to check how I can integrate CoC here best. The idea of this plugin should be independent from where the data comes from. Though I have no experience with CoC and honestly don't like its approach too much. But I thought with the help of you guys we can do it together.

PS: @xiyaowong if your intention was to first have others test it and you planned to open a PR soon, you can ignore the above. I'm just confused right now. 🤷🏻‍♂️

weilbith avatar Oct 02 '21 20:10 weilbith

I am very happy to contribute, it requires adding a settings feature, so it may modify many codes, I also see you have a pr about new feature , I'm waiting for your work to be merged, then reorganize them

xiyaowong avatar Oct 03 '21 00:10 xiyaowong

I am very happy to contribute, it requires adding a settings feature, so it may modify many codes, I also see you have a pr about new feature , I'm waiting for your work to be merged, then reorganize them

Thanks for replying. 😊 I checked the commits on your branch to get a feeling how if works. Due to the recent work here (especially with the current open PR) there will be tons of conflicts. Anyway you are right, adding this feature will require some "bigger" changes to maintain a good architecture. I plan to work on this tonight and start to refactor this. In theory it should be possible to add then any kind of LSP client implementation, not only native and CoC.

weilbith avatar Oct 03 '21 11:10 weilbith

It would be very helpful if someone could tell me if CoC it's client implementation sets the capability to resolve actions. And if so, if it does resolve them automatically when requesting the actions. Though this is kinda against the idea of resolvable actions but "necessary" for this plugin to preview as much metadata as possible. Would be good to know for a few design decisions I have to make.

weilbith avatar Oct 03 '21 12:10 weilbith

Hey there, I'm not sure if this is the right thread, but I've been struggling to make @xiyaowong's plugin work.

Is it even possible using Plug ? -- I dont really feel like changing my whole plugin management env' to packer just for this, honestly.

I can't seem to understand when/where/how I'm supposed to make the menu require the plugin, since its README says "in code-action-menu's config" and code-action-menu's README basically says "there is no actual config file yet"

This is how they're installed for now, and reading Plug's docs there is no real dependency management, which seems to be an issue in how I should get the CoC extension to work... :thinking: image I also have a ~/.vim/after/ftplugin/code-action-menu-menu.lua containing a single line: require 'coc-code-action-menu' even though I'm pretty sure this line is actually something to be executed in the packer installation chain.

SirWrexes avatar Sep 05 '22 14:09 SirWrexes

try Plug 'weilbith/nvim-code-action-menu', {'do': 'lua require"coc-code-action-menu"'}

xiyaowong avatar Sep 05 '22 14:09 xiyaowong

That didn't work. The do option is only to perform certain commands after install/upgrade so I tried fully reinstalling and it didn't work either.

SirWrexes avatar Sep 05 '22 16:09 SirWrexes

That didn't work. The do option is only to perform certain commands after install/upgrade so I tried fully reinstalling and it didn't work either.

put lua require"coc-code-action-menu" to the last line in your config

xiyaowong avatar Sep 06 '22 16:09 xiyaowong

I had no idea you could run Lua right inside .vim files. o.o Anyway, doing that broke everything and CoC with it BUT...

Despite my abysmal knowledge of Lua, I found a way to require the module only if it exists. I've then tried it with and without coc-code-action-menu and calling <Plug>(coc-codeaction) with my prefered keystroke did in fact show me CoC's menu when coc-code-action-menu was not installed, and then the custom menu when I reinstalled it.

Here's what I did, I added this line before the return in code_action_menu.lua:l134:

local _hasCCAM, _ccam = pcall(require, "coc-code-action-menu")

Simple and works.

Now I have other issues, apparently the pop-up window blends into what's behind it, I see characters from under the window appear inside it. image Do you guys think it's a side effect of the way I've loaded the plugin ?

I'm also having the issues described in #52 but they're not for this thread.

SirWrexes avatar Sep 07 '22 11:09 SirWrexes