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

Support visual selection for code actions #178

Open
slonoed opened this issue Apr 13, 2019 · 3 comments
Open

Support visual selection for code actions #178

slonoed opened this issue Apr 13, 2019 · 3 comments

Comments

@slonoed
Copy link

slonoed commented Apr 13, 2019

Hello! And thank you for this excellent plugin.

I'm working on my language server and use this plugin in Vim 8. And I can't implement support for code actions, which requires some selection. Example: extract code to function.
This plugin always sends the cursor position for start and cursor + 1 column for end.
It would be nice, that if vim in selection mode it sends proper range.

I don't know viml. I tried to change this code

\ 'start': {'line': line('.') - 1, 'character': col('.') - 1},

by using line('v').
But end position with line('.') is wrong.

Reference in docs. http://vimdoc.sourceforge.net/htmldoc/eval.html#line()

I would like to help with this, but don't know where to start.

@natebosch
Copy link
Owner

I think the tricky part is knowing when to check "'<" vs '.' - we want to know if we were in visual mode when running the command and I'm not sure that we can know that...

natebosch added a commit that referenced this issue Apr 22, 2019
Towards #178

Uses a hack to try to figure out if the user is likely to have set
reasonable marks for the range and is running from a visual selection so
that lines were passed with `:'<,'>LSClientFindCodeActions`.
@natebosch
Copy link
Owner

We could maybe do something like #179 but it's pretty hacky.

Alternatively we could add vnoremap key mappings which call the function in a way that specifies it was from visual mode, but then that would rule out the workflow of making a visual selection and typing the :LSClientFindCodeActions workflow. Getting that behavior worked into the configuration for keybindings is also tricky...

@slonoed
Copy link
Author

slonoed commented Apr 24, 2019

I tried visual-range branch. It works when I run :'<,'>LSClientFindCodeActions. 👍
For visual I made this mapping

vnoremap <silent> ga :call lsc#edit#findCodeActions(lsc#edit#filterActions(), 0, 0)<CR>

Looks ugly, but works.

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

No branches or pull requests

2 participants