ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.46k stars 2.81k forks source link

how to get this func.help wanted!! #1779

Closed wsdjeg closed 8 years ago

wsdjeg commented 8 years ago

hi @Valloric i have add this to my vimrc

        let g:ycm_semantic_triggers =  {
                    \   'c' : ['->', '.'],
                    \   'objc' : ['->', '.'],
                    \   'ocaml' : ['.', '#'],
                    \   'cpp,objcpp' : ['->', '.', '::'],
                    \   'perl' : ['->'],
                    \   'php' : ['->', '::'],
                    \   'cs,javascript,d,python,perl6,scala,vb,elixir,go' : ['.'],
                    \   'java,jsp' : ['.'],
                    \   'vim' : ['re![_a-zA-Z]+[_\w]*\.'],
                    \   'ruby' : ['.', '::'],
                    \   'lua' : ['.', ':'],
                    \   'erlang' : [':'],
                    \ }

so afte '.',the completion words will,also i do not type every char of the string. for example if i want get finalize() i just need to type fz 2015-11-15 15-27-22 but in this case

after Sys i start the completion manually by type <c-space> get this result 2015-11-15 15-28-43 if i want SystemTray i need to type every char of this string,i hope just type less char to get the result i wantted

wsdjeg commented 8 years ago

@artur-shaik i think maybe you kown what i want,i have read you vimrc,but i can not find the related configration

vheon commented 8 years ago
        let g:ycm_semantic_triggers =  {
                    \   'c' : ['->', '.'],
                    \   'objc' : ['->', '.'],
                    \   'ocaml' : ['.', '#'],
                    \   'cpp,objcpp' : ['->', '.', '::'],
                    \   'perl' : ['->'],
                    \   'php' : ['->', '::'],
                    \   'cs,javascript,d,python,perl6,scala,vb,elixir,go' : ['.'],
                    \   'java,jsp' : ['.'],
                    \   'vim' : ['re![_a-zA-Z]+[_\w]*\.'],
                    \   'ruby' : ['.', '::'],
                    \   'lua' : ['.', ':'],
                    \   'erlang' : [':'],
                    \ }

This doesn't seems relevant to the question.

You're talking about java code for which we don't provide a native semantic engine so you have to rely on some vimscript omnifunc. When we call the omnifunc for you (after a . in this example) then we are able to handle the normal behaviour of YCM and provide fuzzy search of the candidates. When you type <C-Space> to force completion then we simply do <C-X><C-O><C-P> which means that in this particular case all we do is call the vim omnifunc and there is no way for us to provide the same experience. Closing since this is not a YCM bug but a vim limitation more than everything. If I misunderstood something we can always reopen this.

wsdjeg commented 8 years ago

i have understand what you mean,thank you ,you mean after '.' YCM no only call omnifunc ,but also provide some fuzzy search,but c-space only call omni,just like type c-x c-o c-p

puremourning commented 8 years ago

This is an interesting case: use YCM's OmniCompleter instead of just invoking omnicompletion when hitting the g:ycm_key_invoke_completion sequence in non-semantic supported files.

The use-case seems would be likely most useful when using something like eclim in combination with YCM, or, say another plugging providing a useful omnifunc (e.g. the one that currently works for racer, etc.).

Sounds fiddly to implement and probably rather niche. FWIW I believe we'd have to map the trigger to something like <C-R>=youcompleteme#InvokeOmniCompleter()<CR> and then have some way to force CreateCompletionRequest to ask the omni-completer. All very messy I think.

vheon commented 8 years ago

All very messy I think.

@puremourning I believe that is why is the way it is currently :)

puremourning commented 8 years ago

Hah yes. Well I was bored (it's Sunday and it's dark and cold), so I have made a prototype of this and it isn't anywhere near as ugly as I thought. I'll post a demo in a bit, see what you all think.

vheon commented 8 years ago

@puremourning :+1:

puremourning commented 8 years ago

OK It took me longer than I expected. It was working very nicely, except it didn't work for any of my supposed use cases (specifically: eclim and vim-racer). Joy. Anyway that turned out to be a sort-of-bug in YCM in the way it interacts with the omnifunc. It's quite detailed, so I'll spare you the explanation for now, but here's a quick demo using eclim (for java) and vim-racer (for rust).

In each test I type some stuff like Sys and f then hit <C-Space>. I think use YCM's word-boundary-chars fuzzy search to narrow down the list.

eclim

ycm-omnicompleter-force-java

vim-racer

ycm-omnicompleter-force

It's not perfect as the initial query string must be a real prefix, but interested in thoughts.

vheon commented 8 years ago

@puremourning so let's say that you don't type anything and press <C-Space> it would then provide fuzzy search?

puremourning commented 8 years ago

yes, sort of. Actually, the g:ycm_cache_omnifunc sort of gets in the way of this - it doesn't re-query each time i don't think. I haven't looked into it much yet.

I've pushed the code here: https://github.com/puremourning/YouCompleteMe/tree/force-omni-completer

note - it's really just a prototype/hack at the moment, so please don't think less of me if it is ugly and poorly tested :grin:

wsdjeg commented 8 years ago

it is very strange why javacomplete cannot do that,it is the func of ycm or eclim

puremourning commented 8 years ago

@vheon actually, it seems to work. I tried it with the problematic php completer:

ycm-omnicompleter-force-php

@wsdjeg The demo above is with some changes to YCM. I haven't used javacomplete, but you're welcome to check out my branch and see if it works for you.

wsdjeg commented 8 years ago

greate,i hope this for a long time ,and i will check it tonoght,if it works well,i think most omnifunc will be nicer,such as origin html xml omnifuc

puremourning commented 8 years ago

gave it a quick test - seems to work with javacomplete2.

wsdjeg commented 8 years ago

greate,i think @artur-shaik will be glad to hear this!

artur-shaik commented 8 years ago

@puremourning nice work. Thank you. @wsdjeg thank you for mention.

wsdjeg commented 8 years ago

@artur-shaik @puremourning i have check this branch,for java html xml js css and any other vim origin omnifunc ,it works very well,but still has some issue! for example

not work well with BackSpace

here is out put for Sys 2015-11-16 19-50-08 then i type t or any other char will get nothilng but then i type backspace type t again, will get this 2015-11-16 19-52-57 maybe first time get result but second time will not

you can try with type any char and type backspace and type this char again

error with complete java annotation

here is javacomplete OUT PUT OF C-X C-O 2015-11-16 20-01-29

and here is YCM 2015-11-16 20-01-44

because YCM donot check @ the output just same as Ove 2015-11-16 20-13-39

after @Override both words well and both of ycm and javacomplet can not search ,just need tpye c-n or c-p to select what i want. 2015-11-16 20-17-58

MAYBE THIS IS THE FEAUTURE OF JAVACOMPLETE2

puremourning commented 8 years ago

Thanks for testing

I think it is because YCM doesn't consider @ to be an identifier character, though I thought thought my branch would use the omnifunc decision about that. Probably YCM internals. I'll look when inhale some time.

wsdjeg commented 8 years ago

thank you

puremourning commented 8 years ago

Well, this particular problem with javacomplete and @ symbols in completions is quite difficult to fit into YCM's ethos. I had a go, but unfortunately couldn't find a simple solution. Maybe I will look more, but no promises, as even if I get it to work, the other devs. might not love the solution :grin:

wsdjeg commented 8 years ago

yes how about iusse with backspace