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

Smart auto expansion #22

Closed
Shatur opened this issue Jun 24, 2020 · 12 comments
Closed

Smart auto expansion #22

Shatur opened this issue Jun 24, 2020 · 12 comments

Comments

@Shatur
Copy link
Contributor

Shatur commented Jun 24, 2020

Previously you have added auto_expand feature. I use it every day, it is very convenient. But sometimes I do not need expansion, for example:

object.my_function(argument1, argument2);

I want to change my_function I can't use completion because it will be expanded automatically and I will have something like the following:

object.another_function(snippet_argument1, snippet_argument2)(argument1, argument2);

So, I suggest to make this function more smart. For example, do not expand function if next symbol is not a space. This is how it works in most IDE's.
Or, as alternative, the ability to complete text without expansion manually. For example, autoexpand on <CR> and insert without expansion with <C-y>.

@hrsh7th
Copy link
Owner

hrsh7th commented Jun 25, 2020

Thank you for reporting.
I have the same opinion we should improve expansion handling.

The LSP spec has the CompletionItem#commitCharacters that is the same concept.

But I'm busy now... anyway I will start considering it.

@Shatur
Copy link
Contributor Author

Shatur commented Jun 25, 2020

Interesting, did not know about commitCharacters property.

@hrsh7th
Copy link
Owner

hrsh7th commented Jun 26, 2020

Sorry, vsnip_integ can not support LSP's commit character (It would be good to support on completion-engine or LSP client).

But I implemented vsnip#skip_complete_done API.
Could you test it?

@Shatur
Copy link
Contributor Author

Shatur commented Jun 26, 2020

Sorry, vsnip_integ can not support LSP's commit character (It would be good to support on completion-engine or LSP client).

Thanks for the explanation!

I tested add-manual-skip with the following mapping from the readme:

inoremap <expr> <C-y> vsnip_integ#skip_complete_done('<C-y>')

But I have the following error on snippet expansion:
изображение
I just selected built-in function snippet in vim-language-server and pressed <CR>. Also the same with <C-y>.

Do I configured it correctly?

@hrsh7th
Copy link
Owner

hrsh7th commented Jun 26, 2020

My tested environment are the following.

  • Use neovim built-in lsp client
  • Use omnifunc via <C-x><C-o>
  • Map to inoremap <expr> <C-y> vsnip_integ#skip_complete_done('<C-y>') only (Did not using <CR> key to confirmation key)

Hm... this problem seems to have a complex dependency on many of the plugins.

Probably, We should consider more better API than current one.

FYI: I think the error may be avoidable by updating nvim to the latest.

@hrsh7th
Copy link
Owner

hrsh7th commented Jun 26, 2020

Could you tell me the your tested environment (I think you used completion-nvim + nvim built-in lsp.

@Shatur
Copy link
Contributor Author

Shatur commented Jun 26, 2020

My tested environment are the following.

I tested with exact the same environment! I also updated neovim to the latest commit in master.

But you are right, the problem was in my completion-nvim and pear-tree conflict. The following setting causes the issue:

let g:completion_confirm_key = ''

It used to make the following mapping (the problem exists even without this mapping, only settings above is enough):

imap <expr> <CR> pumvisible() ? complete_info()['selected'] != '-1' ? '<Plug>(completion_confirm_completion)' : '<C-e><CR>' : '<Plug>(PearTreeExpand)'

Can I somehow avoid this conflict? Maybe there is exists another "pairs" plugin without key mappings?

@hrsh7th
Copy link
Owner

hrsh7th commented Jun 27, 2020

I think the problem does not occurs when if you use C-e instead of C-y.

I want more better solution but I don't know that for now...

@Shatur
Copy link
Contributor Author

Shatur commented Jun 27, 2020

I think the problem does not occurs when if you use C-e instead of C-y.

I tried with the following mapping: inoremap <expr> <C-e> vsnip_integ#skip_complete_done('<C-e>') but it just closes completion window :(

Maybe it is possible to add a function to skip expansion manually? Say, expand completion items on <CR> / <C-y> and do not expand with <A-CR> (for example, user will can map it to any key)?..

@Shatur
Copy link
Contributor Author

Shatur commented Jun 27, 2020

BTW, ho do you handle it? You just do not use snippet auto expansion?

@hrsh7th
Copy link
Owner

hrsh7th commented Jun 27, 2020

Oh, Sorry I expected to map inoremap <expr> <C-e> vsnip_integ#skip_complete_done('<C-y>').

I guess completion-nvim sends <C-y> as imap instead of inoremap.

So probably we can't use properly <C-y> and <CR> for separate use-case.

@Shatur
Copy link
Contributor Author

Shatur commented Jun 27, 2020

Got it!
I think that will be better to send a proposal to completion-nvim to solve this issue. Thank you for your effort!

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

Successfully merging a pull request may close this issue.

2 participants