-
Notifications
You must be signed in to change notification settings - Fork 166
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
Omnisharp and Unity3D #152
Comments
Stupid question but did you compile the server? |
OmniSharp certainly works with Unity. I think Unity devs comprise the largest part of the OmniSharp user base. |
I ran If OmniSharp is known to work with Unity the error might be on my side. Is it OK if we keep discussing it here in the issue tracker? |
If you got no errors, then yes, it is built correctly. Do other OmniSharp features work - goto definition etc? Are you using other plugins to trigger completions? You haven't given me a lot to work with here :) |
Well, you haven't given me a lot to work with either, I can't find any user manual for OmniSharp :) I don't know how to use goto definition and the likes. And no, I don't have any plugins installed aside from the above. Here is what my .vimrc looks like:
|
There isn't a manual. All the instructions are on the README. Luckily for me, this has been quite adequate up until now - this is the first such question that I've had. Having said that, I can see from your vimrc file that you are new to Vim :) You will need some keybindings unless you want to invoke OmniSharp functions directly. You can find some example keybindings in the README. Also, please double check that the server is running with
|
Yeah, I know I will need key bindings, but I wanted to make sure things work before I start thinking about key bindings. Here is what I get printed (I assume I was supposed to call that command from Vim)
Also, sometimes when i open a C# script I get the following asked:
Which one should I pick? |
The reason I said you will need some keybindings is because you stated that you didn't know how to use gotodefinition etc. It doesn't matter whether or not you run the command from Vim or not. You should see something like
when the server is running. The server isn't started until it has established which sln file you want to use. If there is only one solution file, then you wouldn't see that prompt - I guess you should pick the -csharp.sln - but not really sure ( I don't do Unity ) |
Also, I would try and get OmniSharp working without YouCompleteMe at first as that complicates things somewhat. You'll need at a minimum autocmd FileType cs setlocal omnifunc=OmniSharp#Complete You may as well paste the whole of the example .vimrc into your file for now and tweak it later. Once you've established that the server has started, try and get completions with |
I recompiled Vim, MacVim and YCM so they all work nicely together now. I also uninstalled and re-installed all my plugins and copy-pasted your example vimrc. here is what I get when executing the above command:
Here is what happens when i try to type Vector2 as
|
v2 won't be auto-completed as Vector2 unless you have it mapped or an abbreviation. Try and type "Vec" and then Ctrl+o I also prefer to use gvim over a regular vim - things just work better |
But I have to agree, Unity integration isn't so smooth. I Just tried it myself, I had already a server instance running - I created a new project with a sample script like the one mentioned above ^ - O# wasn't able to identify the class "MonoBehaviour" nor know what does "using UnityEngine;" mean. I closed out of vim (leaving the server open) and reopened the file again, this time I kept getting errors almost each time I try to do anything. I closed out of vim and killed the server, opened up the script again with a new server, and it was able to detect things now. I managed to get completion for Unity objects like Vector2, etc. |
Typing Vec and pressing ctrl+o is the same. And how do I kill the server? |
On windows just do it from the task manager - go to the processes tab, find the server process and end it. in mac, sudo kill PID where PID is the process ID of the server process. you could use pgrep process_name to get the id of a process |
I used |
@HiPhish you are getting those completions because you are using YouCompleteMe. |
btw, there is an :OmniSharpStopServer command.... also |
Disable YouCompleteMe, add autocmd FileType cs setlocal omnifunc=OmniSharp#Complete if you don't have that line already.... then use |
I commented the YCM plugin in my vimrc, already had that line, killed Mono. My suggestions are still the samem they just don't pop up on their own anymore. |
You still get vertex at the top of the class? I don't believe that. That is impossible if you are using I also have never seen unicode errors... pretty sure they are coming from YCM |
Is the rest of the features working? Find usage, renaming, etc |
OK, you may officially call me an idiot. I thought I was supposed to press either |
Welcome to the club. You might find it easier if you mapped it, put this in your vimrc
If you want to auto-complete by pressing tabs, you could configure supertab to do it for you |
Don't worry about it. Vim has a steep learning curve. Simplest way to get started is to use SuperTab and put this in your vimrc (it's commented out in my README). Then you can use tab to trigger autocomplete and also to select. "Super tab settings
let g:SuperTabDefaultCompletionType = 'context'
let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
let g:SuperTabDefaultCompletionTypeDiscovery = ["&omnifunc:<c-x><c-o>","&completefunc:<c-x><c-n>"]
let g:SuperTabClosePreviewOnPopupClose = 1 |
One thing to watch out for (I just came across it) is that if you're using snipmate or ultisnips you might have issues with supertab, see this ervandew/supertab#74 - in this case, just map the snippet's to or something. |
Something weird: Let's say I type
Pressing anything other than ESC yields even more such junk. The problem is, even if I go back and fix the line that error keeps coming back every time I exit insert mode. Is this from OmniSharp or another plugin? EDIT: when I press
|
I think your issue is the same as this one #151 The second issue is the same I think. Go to definition is triggering the BufEnter event which in turn triggers a Syntastic check. |
You're right, running |
It seems that setting |
Yes, I could revert back to HEAD now. I'm now getting a number of warnings in my scripts, green arrows pointing to specific code lines. The warnings are:
The first warning is a legitimate one, however, that's the way Unity's API works and in this particular case I don't want to deviate. I'm a plugin developer, not a game developer, so my code will be used by other people who will expect it to work like Unity's API. Point 2 is something I don't really like using the Is there a way to turn off those particular kinds of warnings? I do like how it found an unneeded |
They are only suggestions. OmniSharp can attempt to fix these for you with the :OmniSharpFixIssue command (default You can exclude warnings here on the server config https://github.com/nosami/OmniSharpServer/blob/master/OmniSharp/config.json#L6 Unfortunately, this only accepts exact string matches and not regex matches or similar. I plan to change that. You need to rebuild the server to copy the config to the /bin/Debug folder and restart. |
OK, I removed the second warning. The first one uses the name of the property in the string, so I'll live with it for now. I still don't understand what the third warning means. Any ideas? |
@HiPhish I made a change to the server to allow you to use a regex pattern to ignore code issues. See OmniSharp/omnisharp-server#100 and OmniSharp/omnisharp-server@3b56e31 |
Thanks, you are awesome. One little problem though: if I modify Otherwise I have to comment away OmniSharp in my EDIT: BTW, this issue can be closed as far as I'm concerned, OmniSharp does work with Unity and anything else is outside the scope of this topic. |
That's odd.... NeoBundle allows local modifications to files. Doesn't Vundle do git pull --rebase ? Anyway..... you can specify an external config file by starting the server manually with the switch I'm planning on having OmniSharp look for config files within the project source tree to allow for different configs per solution. Would that solve your problem? |
Yeah, that would be OK, but I wouldn't call it a "problem", rather an "inconvenience". It would be a good idea though, suppressing warnings about lower-case properties makes sense in a Unity project, but could be considered harmful in a regular .NET or Mono project. I don't know how Vundle works, I only knew about Pathogen, then learned about Vundle and found that one to be nicer. I'll have a look at NeoBundle, but I don't want to change my setup for now after I go things working. |
What happens if you run |
Hi @nosami - thanks for all the work you do on OmniSharp. I know this is closed, but it seems like a reasonable place to ask about problems with Unity, since you are still active on it. Let me know if you prefer me to open a new issue. I've got omnisharp-vim installed with SuperTab and Syntastic, no YCM. Completions, go-to-definition, and find-usages (and syntax checking) are working for some basic examples. However, here is an example of something that isn't working:
Let me know if you'd like me try anything on this or anything else Unity-related. I'm pretty motivated to get this working for Unity, so willing to help however I can. (Right now I'm using Xamarin Studio, which has excellent completion/go-to-def/find-usages but very bad vi modes.) |
Btw, regarding @HiPhish's question above about which .sln file to pick, it seems the one to pick is sans -csharp, based on the fact that when you select "Sync MonoDevelop Project" in Unity with Xamarin Studio set as the external editor, Xamarin Studio will load the one without the -csharp name. Having said that, I've tried both and it doesn't seem to make any difference. For example, I get the same behavior noted above with either. |
The plot thickens regarding the If I have the following code:
then hit tab on the I.e. without the preceding preprocessor directive, it doesn't work, but with it, it does. In case it helps/matters, here's the Unity doc on |
Another thing: completion doesn't work on |
I have been trying to get Omnisharp to work with the Unity3D Game Engine but without success.
I installed Omnisharp using Vundle, as well as vim-dispatch, syntastic, Ctrl-P, Supertab and YouCompleteMe. As far as I understand Vundle does the whole
git submodule update --init --recursive
thing for me.I have set up a blank new project for testing and created a new C# script. This is what a script looks like by default:
I set my external editor to MacVim and then went to Assets -> Sync Monodevelop Project as described here:
http://docs.unity3d.com/Manual/VisualStudioIntegration.html
A new MacVim window opens with the solution file loaded (New Unity Project.sln) and I can double-click my script. however, code completion does not recognise any patters that aren't in the file already. For example, typing
vec
orv3
will not offerVector3
until i have already written it somewhere in my file. There might be more things not working, but this is what i noticed at first.I will provide any assistance I can to solving this issue, every minute I have to spend in Unity's MonoDevelop or Xamarin Studio is driving me nuts. Thank you for this plugin, hopefully we can get it to work with Unity as well.
The text was updated successfully, but these errors were encountered: