CompleteParameter fails with named function parameters using Tern
danihodovic opened this issue · 7 comments
Issue Prelude
Please complete these steps and check these boxes (by putting an x
inside
the brackets) before filing you issue:
- I have read and understood CompleteParameter's README,
especially the Frequently Asked Questions section. - I have searched CompleteParameters's issue tracker to find issues similar
to the one I'm about to report and couldn't find an answer to my problem. - If filing a bug report, I have included the output of
vim --version
. - If filing a bug report, I have included which OS (including specific OS
version) I am using. - If filing a bug report, I have attached the contents of log follow the steps.
- Execute
let g:complete_parameter_log_level = 1
. - Replay you action.
- Execute
messages
. - Copy the output and place it to next section.
- Execute
- If filing a bug report, I have included a minimal test case that reproduces
my issue, including what I expected to happen and what actually happened. - I understand my issue may be closed if it becomes obvious I didn't
actually perform all of these steps.
Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.
Issue Details
Provide a clear description of the problem, including the following key
questions:
- What did you do?
CompleteParamter fails with named function parameters using Tern when an object is being passed in as an argument. Instead of inserting the entire object, it inserts the object properties as arguments.
# Completion for Hapi.server()
Hapi.Server fn(options: {compressible: bool, extensions: [?], register: ?, source: string, type: string})
What's inserted:
Hapi.Server(options, extensions, register, source, type)
What should be inserted:
Hapi.Server({compressible, extensions, register, source, type})
https://asciinema.org/a/VdIW3cTfN9gXorQf389cW6P7r
Include description of a minimal test case, including any actual code required
to reproduce the issue.
- What did you expect to happen?
Include description of the expected behaviour.
- What actually happened?
Include description of the observed behaviour, including actual output,
screenshots, etc.
Diagnostic data
Language
The program language you are using.
Output of vim --version
Place the output here, or a link to a gist.
Output of message
Place the output here, or a link to a gist.
OS version, distribution, etc.
Include system information here.
In this case, I don't think it's a good idea to insert {compressible, extensions, register, source, type}
. I will insert options
now.
I will try to insert {compressible, extensions, register, source, type}
when I fix #12
@tenfyzhong master seems broken. The lastest version I can get working with JS is 28f232b. After that inserting a parenthesis simply doesn't trigger the insertion of arguments.
@danihodovic I have remove default mappings. You should add this to your vimrc
inoremap <silent><expr> ( complete_parameter#pre_complete("()")
smap <c-j> <Plug>(complete_parameter#goto_next_parameter)
imap <c-j> <Plug>(complete_parameter#goto_next_parameter)
see: https://github.com/tenfyzhong/CompleteParameter.vim/blob/master/CHANGELOG#L1
I tried the following settings:
Plug 'tenfyzhong/CompleteParameter.vim'
call plug#end()
inoremap <silent><expr> ( complete_parameter#pre_complete("()")
It crashes:
https://asciinema.org/a/93tf6EgVOa9tc9rEjR9jaDS92
The end bracket in the magic regex grouping is missing:
https://github.com/tenfyzhong/CompleteParameter.vim/blob/master/cm_parser/javascript.vim#L18
let param = substitute(param, '\m\(\w\+)\s*:{[^{}]*}', '\1', 'g')
should be
let param = substitute(param, '\m\(\w\+\)\s*:{[^{}]*}', '\1', 'g')
even when this is fixed the code gets stuck in a endless loop at https://github.com/tenfyzhong/CompleteParameter.vim/blob/master/cm_parser/javascript.vim#L17-L19
@danihodovic can you send a pr?
I can solve the initial regex typo, but fixing the endless while loop may take more time. I'll have a look once I get off work.
Fixed in 930fc5a