Search Unity

Visual Studio "Code" integration

Discussion in 'Scripting' started by Foriero, Apr 30, 2015.

  1. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    liortal, Rolemancer and rakkarage like this.
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Likely wont happen since it dosnt support extensions like proper Visual Studio does, and that it dosnt work with solution files and operates more similar to a text editor than a ide
     
    liortal likes this.
  3. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    If you are Windows user I understand. But the situation on OSX side is terrible. There are more and more developers that are just longing to get rid of mono develop. We have hack for sublime text, that works nice, but CODE would give us much nicer intelisense and debugging as well.
     
    liortal likes this.
  4. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Ya i know i live with that reality since at work since the target is iOS, so we are a mac shop. Most people are putting up with monodev and a few people like me are using parallels to run a windows VM and Visual Studio in seamless mode to get access to it.
     
  5. eshan-mathur

    eshan-mathur

    Joined:
    Nov 22, 2011
    Posts:
    118
    I completely agree. Developing with MonoDevelop is an awful experience rife with bugs that never get fixed and poor debugging. Unity, please make this happen!

    As an aside, does anyone know what address/port Unity uses to attach it's debugger to MonoDevelop? There is an Attach option in the VSCode debugger and all it needs is that info. Maybe, just maybe, it'd work?
     
  6. Mishaps

    Mishaps

    Joined:
    Nov 28, 2011
    Posts:
    181
    Unity seem to be partnering with Microsoft on a few things so wouldn't be surprised to this working soon enough.

    BTW Xamarin is a good free alternative to monodevelop and doesn't really need any hacking just "sync Monodevelop Project" from the unity menu instead of double-clicking a script.
     
  7. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Frankly, i was really excited about this, but after installing it on my OSX, i'm not really sure what is it.

    VSCode seems more of an editor than an IDE.
    I already have "intellisense" (e.g: code complete) in MonoDevelop, i'd like better debugging support, plugin ecosystem and other "rich" IDE features that are missing there.

    It is possible of course these will be added in the future, but for now, I am less excited as i was when i saw the headline "Visual studio comes to Mac"...
     
  9. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Ya like a stated before it is more of a advanced editor similar to atom sublime text rather than a ide. Also it seems yo be targeting asp.net and node.js work at the moment so the tool was designed with web development in mind.
     
  10. VirtualCharlie

    VirtualCharlie

    Joined:
    Feb 3, 2014
    Posts:
    10
    There's a script up on Github that adds a drop-down menu in the unity top-bar for generating a VSCode-compatible .sln header file (or whatever).
    https://github.com/kode80/VSCUnity

    If you're having problems with Omnisharp and Mono versions, try downloading the latest version of Mono (http://www.mono-project.com/download/).

    I'm at the point where I can open my project, and Intellisense sort of works, but I get a ton of exceptions and seemingly all class references are broken.
     
    liortal likes this.
  11. MPowell

    MPowell

    Joined:
    Apr 30, 2013
    Posts:
    9
    To correct a common misconception:

    VS Code DOES work with solution files.

    It just has a weird UI for using them. You need to open the directory which contains the solution files. Then you'll notice a little button on the left side of the bottom bar with a flame icon. Click on that, and a menu will pop up at the top of the screen allowing you to select from the available solution files. As soon as you select one, the Intellisense turns on!

    And another common misconception:

    VS Code IS a full IDE.

    It supports full project files, integrates directly with the build system, and provides a debugger. It even provides version control integration (though only git for the moment). If you were building a straight .NET application, instead of a Unity program, you could do all of that without leaving VS Code. The UI feels more like lightweight text editors, like Sublime and Atom, but it still has all the features that make a full IDE.

    And another one:

    VS Code is currently a PREVIEW release.

    It's not feature complete. I can't say with any certainty what features will be in the "full" release, but I know plug-in support will be among them. See the top suggestion in Microsoft's VS Code uservoice page, with official developer response: http://visualstudio.uservoice.com/forums/293070-visual-studio-code

    Thus far, VS Code is proving far faster and more stable than MonoDevelop. Yes, MonoDevelop provides Intellisense, but it's slow and buggy.

    Yes, MonoDevelop provides a debugger, and sometimes, if the stars align and perform the appropriate incantations to the Ancient Dark Gods of Code, it even manages to hit breakpoints without crashing. And if you're one of the True Chosen Ones, you might even be able to inspect variables, though I've never seen this.

    And VS Code's text editor is almost as good as Sublime, which is not something I can say of any fully featured IDE I've tried before.
     
  12. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    222
    Well...it's really not that complicated to make Visual Studio Code work as the script editor for Unity3d, I wrote a little blogpost about it, as I can see many people are having problems with it.

    http://laumania.net/2015/04/30/how-to-use-visual-studio-code-as-unity3d-script-editor/

    This works for me, with Intellisense and everything. I haven't tested if I can build from VSCode, debug or anything yet, but as a code editor it works perfectly! CMD+T is a pure winner. Press it and start typing class, property or method name you would like to goto - bam! :)
     
  13. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,365
  14. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    There have been rumors of some upcoming tighter integration between Unity and Visual Studio. I'm guessing it will involve Code.
     
  15. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,365
    So after your post I gave Xamarin another go. It was terrible, I had a good laugh. From the "would you like to give feedback" popup that freezes the IDE, to typing inside the search field at the top right corner that also types in the script file so you probably use an old version of xamarin, don't upgrade ;)
     
  16. VirtualCharlie

    VirtualCharlie

    Joined:
    Feb 3, 2014
    Posts:
    10
    I "solved" this exact issue (On OSX 10.9) by simply downloading the latest version of Mono. However, I've still been having problems (as I mentioned earlier), so I'm going to try this solution now.

    Can you find all references of a class or public variable? Because I can't. I'm still troubleshooting though -- maybe there's simply something wrong with my environment.
     
  17. MPowell

    MPowell

    Joined:
    Apr 30, 2013
    Posts:
    9
    I can. It just worked, as soon as I opened the solution file.

    Did you edit your solution file? I saw some people recommending that you change the 2008 to 2012, but that doesn't seem to actually be necessary. Maybe that's throwing something off?
     
  18. Mishaps

    Mishaps

    Joined:
    Nov 28, 2011
    Posts:
    181
    I've haven't experienced the problems you described but hey whatever floats your boat. You might want to give the 5.9 update a shot it was only released yesterday.
     
  19. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Has anyone worked out how to close a solution once opened?
    Also how do we tell VSC not to show files like .meta in the explore list ? Or is that not where it's showing me the files in the solution?

    Edit: Am I correct that if there is any UnityScript in the solution, the solution wont load?
     
    Last edited: Apr 30, 2015
  20. VirtualCharlie

    VirtualCharlie

    Joined:
    Feb 3, 2014
    Posts:
    10
    I just got it to work as expected on a Windows 7 machine, and it worked alright -- as long as I opened the solution by double-clicking a code file from inside the project, as Laumania mentioned in his blog post.

    Still, my project is seemingly full of exceptions ("Type or namespace name [somePluginClassName] could not be found (are you missing a using directive...)" yadda yadda), yet Intellisense and find all references/go to declaration works great.

    MPowell, are you using OSX? (If so, what version of OSX, and what version of Mono do you have installed).

    My next step is to make a new project and see if I can get that to work, error free, but I don't have a lot of time for that today.
     
  21. MPowell

    MPowell

    Joined:
    Apr 30, 2013
    Posts:
    9
    By "from inside the project" you mean "in the Unity editor"? That's odd. I'm not sure why that should matter.

    Edit: Wait, opening the SOLUTION from inside the editor? How is that possible? Even Laumania's blog post doesn't describe doing that. You need to open the solution by opening the right folder inside VS Code, and then clicking the little flame button at the bottom.

    seon has an interesting point: Does your project include any JavaScript/UnityScript or Boo? VS Code isn't going to know how to deal with that properly, and may throw up some errors.

    I'm using OS X 10.9, with Mono 3.12.0.
     
  22. VirtualCharlie

    VirtualCharlie

    Joined:
    Feb 3, 2014
    Posts:
    10
    Nah, double-clicking a script from inside Unity. Sorry for the confusion. I've also tried opening the root folder of the project, and then using the flame icon to select the correct solution, but that produces the same error for me on OSX and just doesn't work on Windows (and I'm sure I'm doing it right and opening the correct solution, if it even matters).

    I thought of this too, and systematically purged every .js file in the project (all from plugins or standard assets -- we weren't using any of them anyway). I didn't need to do this to get things working on Windows.

    Let me try with a fresh project and see what happens.

    EDIT: Fresh project looks good (on OSX); no issues. It's probably a plugin in our project causing issues, but I'm not sure what or why. Still, there are a few weird warnings, like "Unnecessary using directive" for the line "using System.Collections" which comes default with a new script.

    In my actual project, pretty much every occurrence of using [something]; produces this warning. On top of the countless errors about missing references that aren't actually missing.

    EDIT 2: Made a javascript file. Doesn't work at all, on either OSX or windows. Doesn't recognize the syntax.
     
    Last edited: Apr 30, 2015
  23. MPowell

    MPowell

    Joined:
    Apr 30, 2013
    Posts:
    9
    Those are unnecessary, unless you're actually using a type from System.Collections. Which I basically never do. All the useful collection classes are in System.Collections.Generic. I have no idea why Unity includes that using directive in new files.
     
  24. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Because Coroutines return IEnumerator, which is in System.Collections.
     
  25. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Well reinstalling Xamarin on OSX helped to solve error with OmniSharp just for the first time. Second time I opened VSCode is is getting back to Error with omnisharp. Any idea?
     
  26. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    I switched from Visual Studio Pro to VS Code. Love the light-weightedness of the editor and it does everything you need minus the extra baggage.
     
  27. VirtualCharlie

    VirtualCharlie

    Joined:
    Feb 3, 2014
    Posts:
    10
    Ah.. so it's complaining because I'm not using anything from it. Makes sense.
    Yeah it seems pretty rad, but I'm going to have to stick with Visual Studio through a VM using UnityVS until I have something that works consistently. I use debugging heavily, which works perfectly in VS for me but hangs up Monodevelop half of the time I try to attach.

    Part of the reason I'm on OSX is because I want the tools I use to "just work," and this isn't quite there (obviously it's a preview and every Unity person who's spoke about Code hadn't heard of it until yesterday, so it makes sense).
     
  28. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Trying it out on OSX. Seems to hang a lot. Maybe the git stuff? Can I turn that off?
     
  29. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    I wrote the VSCUnity script (https://github.com/kode80/VSCUnity). Aside from removing the need to manually choose the correct SLN each time you open the project, I've also just added Unity type syntax highlighting as well.

    Just add the script and run the two commands in the VS Code menu. Project update command will need to be run per-project. The Add Unity Types to VSC command only needs to be run once (as it updates VSC's internal C# language definition).

    IMO - Visual Studio Code is a million times nicer than MonoDevelop, even in it's earlier state. It's faster, infinitely more stable and code comfort in general is great - so I'm eager to see Unity integration brought up to speed.
     
    rakkarage, J_P_ and der_r like this.
  30. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
  31. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Eric, any idea how to filter files so that we don't see meta and other not relevant files?
     
  32. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    i keep getting this error on win8.1 :(
    thanks
     
  33. PixelArtist

    PixelArtist

    Joined:
    Aug 7, 2012
    Posts:
    14
    I first tested out Kode80's plugin by starting a new project and didn't have that issue. But when I tried to integrate Kode80's tools with my current (large) project, I got this error as well :/



    Please note that this error appeared after I clicked the Flame Icon and selected my .sln file.
     
  34. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    i fixed that error by removing spaces from (moving) project folder name
    if you open the log and select OmniSharp you can see exactly why it fails
     
  35. PixelArtist

    PixelArtist

    Joined:
    Aug 7, 2012
    Posts:
    14
    My project folder name has no spaces, so I don't think that's the issue. After doing some tests, it seems to be based on the size of the project. At a certain point, if I import any more assets from the asset store, Visual Studio Code gives me that error.

    How do I open the log to see exactly why it fails? Is that file stored somewhere?
     
  36. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    ctrl-shift-u
    or
    view->output
    or search log in pallete
    ctrl+p

    then select omnisharp from the dropdown in top right of output window
     
  37. PixelArtist

    PixelArtist

    Joined:
    Aug 7, 2012
    Posts:
    14
    Nvm, I figured out how to access the OmniSharp log
     
  38. PixelArtist

    PixelArtist

    Joined:
    Aug 7, 2012
    Posts:
    14
    Ok, I fixed my OmniSharp error by hand-modifying my .sln files through trial and error. Adding this section to the end of them seemed to do the trick:



    Here's the easy-to-copy-paste version:

    GlobalSection(MonoDevelopProperties) = preSolution
    StartupItem = Assembly-CSharp.csproj
    Policies = $0
    $0.TextStylePolicy = $1
    $1.inheritsSet = null
    $1.scope = text/x-csharp
    $0.CSharpFormattingPolicy = $2
    $2.inheritsSet = Mono
    $2.inheritsScope = text/x-csharp
    $2.scope = text/x-csharp
    $0.TextStylePolicy = $3
    $3.FileWidth = 120
    $3.TabWidth = 4
    $3.IndentWidth = 4
    $3.EolMarker = Unix
    $3.inheritsSet = Mono
    $3.inheritsScope = text/plain
    $3.scope = text/plain
    EndGlobalSection
     
  39. Quido3

    Quido3

    Joined:
    Jan 28, 2014
    Posts:
    1
    Has anyone tried using the platform dependent codes? Meaning the #if UNITY_EDITOR and such. Seems to me that VSCode understands the #if part but not the UNITY_EDITOR.
     
  40. Reapazor

    Reapazor

    Joined:
    Jun 19, 2008
    Posts:
    173
    Here's my current system for keeping VSCode functioning with Unity.
    This has been tested against the upcoming VSCode release, as well as future versions of Unity.

    https://gist.github.com/reapazor/132abf1e7efc317d9e15

    It's not pretty, it just gets the job done.
    No highlighting ... I suppose I could do something about that, but meh :)
     
  41. CapnCromulent

    CapnCromulent

    Joined:
    Sep 7, 2010
    Posts:
    45
    rakkarage likes this.
  42. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    you should not need any of that and highlighting works too!?
     
  43. Reapazor

    Reapazor

    Joined:
    Jun 19, 2008
    Posts:
    173
    Shader syntax highlighting isn't included in the plugin, which I should add is getting some love from the Visual Studio Code team shortly.

    I've actually just moved it to a repo on GitHub: https://github.com/dotBunny/VSCode


    I've also submitted a copy to the UAS, still hasn't been approved but its link is: http://u3d.as/jmM
    Hopefully the USA link is active soon.
     
  44. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    J_P_ likes this.
  45. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Has anybody been able to use VSC 0.9 IntelliSense with Unity 5.2.2?
    When opening a project, I will get a warning message that says "Some projects have trouble loading".
     
  46. mollermanden

    mollermanden

    Joined:
    Apr 2, 2013
    Posts:
    23
    Have you checked out the Consulo IDE? https://github.com/consulo/consulo

    I can't compare it to VSC as I haven't tried the latter, but personally I prefer Consulo way over MonoDevelop.
    It is based on the Intellij Community Edition so if any of you like the JetBrains IDE's you should definitely give it try.
     
    Shushustorm likes this.
  47. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  48. drhmiri

    drhmiri

    Joined:
    Jun 17, 2014
    Posts:
    82
    @shaun Hi shaun, While using vscode to create a brand new simple console app (HelloWorld) even the one and only using System directive is underlined with a green squiggly! I wonder if you have come across this? I am confused by all the posts and search results... My dotnet version is 1.0.0-preview2-1-003177 and this line "version": "1.0.0-*" also exists in the project.json file. I wonder if you would know a hack around this? Thanks
     
  49. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Hover over the green squiggle and it will tell you what it means.
    I think it just means that you do not need that using statement ("unnecessary using directive")?
    Which means it is working, and understands your code enough to know that.
     
    drhmiri likes this.