OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.71k stars 169 forks source link

Completion doesn't work unless OmniSharpGotoDefinition is run first #129

Closed robertwahler closed 10 years ago

robertwahler commented 10 years ago

When I startup MacVim 7.4 (72) on a Unity project and open a source file, I select one of the two solutions when prompted by Omnisharp, the server starts but I get no completions (C-X,C-O in Insert) until I execute a 'gd' for OmniSharpGotoDefinition and then all is well with completions.

I'm using the current master of Omnisharp. I'll be happy to do some poking around if someone could give me an overview of the Omnisharp debugging process. Thanks!

nosami commented 10 years ago

Can you see the .cs file in question being loaded by the OmniSharpServer process when it first starts? (in the console log)

robertwahler commented 10 years ago

I'd be happy to look if I knew where to look. Is there some way to tail a log file to the console? In Gvim, :messages doesn't return anything useful.

nosami commented 10 years ago

I didn't mean inside vim.... try starting OmniSharpServer manually using mono OmniSharp.exe -s path/to/sln in your terminal (optionally passing in the -v flag) and see if you see anything strange in there.

robertwahler commented 10 years ago

Thanks, that is helpful to know. So I tried running the server manually, then running vim and everything works as expected. When I let the server autostart, i just get Omni completion (^O^N^P) Pattern not found from vim until I do a 'gd' and then all works as expected.

nosami commented 10 years ago

That's strange. There shouldn't be any difference. Do you have any other plugins installed for completion (ycm, neocomplete) etc. ?

robertwahler commented 10 years ago

No other completion plugins. I tried YCM but it is hopeless if you have 2 sln files. YCM bombs out when it see two sln files. I don't know why it thinks it needs to spin up another server when Omnisharp has already done so unless this issue is related somehow.

nosami commented 10 years ago

Stupid question, but is there any chance that you started with the wrong sln file when using the auto start method? I don't use Unity myself, but I know that only one of the sln files that it generates has the references to the .cs files.

nosami commented 10 years ago

fwiw, I'm not overly keen on the YCM behaviour either. I've switched to neocomplete personally, which uses the same server (it just hooks into the standard vim omnicomplete system)

nosami commented 10 years ago

If you want to see what happens when the autostart mechanism is being called, try using terminal vim inside iterm2 (vim-dispatch opens a new tab for the server) or start vim inside tmux inside any terminal (vim-dispatch launches a new tmux session)

robertwahler commented 10 years ago

Thanks, the tmux tip worked. I see all the files load when I select the sln. When I C-xC-o in insert, nothing hits the server. If I do a 'gd' then I see:

Loading /Users/robert/unity/codered/Assets/Scripts/Hud.cs
/gotodefinition 166ms
Loading /Users/robert/unity/codered/Assets/Scripts/Hud.cs
/typelookup 29ms

Now if if C-xC-o, i get completions and this in the log:

Loading /Users/robert/unity/codered/Assets/Scripts/Hud.cs
Getting Completion Data
Got Completion Data
/autocomplete 109ms

As for the correct sln loading, it doesn't matter which of the 2 solutions I pick, the same thing happens in either case. I really can't tell what is different about them, they seem to reference the same source files, maybe one is tweaked out for VS and one for Monodevelop? I wish I could get rid of one but they pop in automatically whenever Unity is started.

nosami commented 10 years ago

As long as you have :-

autocmd FileType cs setlocal omnifunc=OmniSharp#Complete

<c-x><c-o> should always hit the server, even if the wrong solution file is loaded (or you have the YCM plugin - in which case it will use it's own server).

robertwahler commented 10 years ago

I do have the autocmd in my vimrc file. I have keyboard mappings in ~/.vim/ftplugin/cs.vim.

nosami commented 10 years ago

You could be hitting a timeout. Try let g:OmniSharp_timeout = 10

The responses are slower than normal when the server first starts. If you hit a timeout, you'd get the message that you were seeing Omni completion (^O^N^P) Pattern not found - but you should still see the command fire on the server side.

nosami commented 10 years ago

How long does the solution take to load? Is it possible that the solution hadn't finished loading when you first tried to autocomplete?

robertwahler commented 10 years ago

Setting the timeout to 10 didn't change anything, still nothing hits the server log until I 'gd'.

robertwahler commented 10 years ago

I see the "Solution has finished loading" in the log almost immediately.

nosami commented 10 years ago

Well... I'm all out of ideas. Can you share your code? Or screenshare?

nosami commented 10 years ago

What happens if you try the OmniSharpServer codebase?

robertwahler commented 10 years ago

I just tried the server codebase, same thing happens so it must not be Unity specific.

nosami commented 10 years ago

Could you do a git pull? I fixed it here https://github.com/nosami/Omnisharp/commit/2f1431ce2e54b03f8a6d319cdcb0925cc73c959c I'll need to think of a better solution when I get time. Thanks

robertwahler commented 10 years ago

Thanks, that fixed it. Appreciate all your effort. Awesome plugin.

nosami commented 10 years ago

Sorry if I wasted your time... I made a stupid commit the other night and completely forgot about it.