C# Parser and Code View

I don't have any Proof of Concept in place yet on this, but I've finally started designing how the code editor UI will work, then designed some of the basic architecture needed to support how the UI would work, and finally, this lead to how I need to protect the user from dangerous code (you can write C# to format your machine, or try to steal memory from other apps like passwords), while also improving the debugging and teaching abilities.


Alright, so I'm planning on having Classes exposed, as an item, then under the class view, is a list of items, like fields, properties, methods, etc. When selecting one of the members, you get details like notes, title, version history; for beginner coders I felt giving them a really easy ability to step back a version or two to something that last worked.

Then show the code.  To be able to provide physical system responses, we need to detect all sort of things, like an infinite loop. In the case of an infinite loop, we don't want the environment to freeze up, but instead detect it will happen (by way of injecting code in what actually runs) to break out after X Time, and then stop executing it, but instead make a visual happen, like something overheating.  Then we can apply a bug directly to the offending method, so the user can see it and deal with it better.

This means we need to parse the code fully to be able to detect and inject these protections.  I've personally built a parser for HTML and VBS back in the lat 90's. C# is more complex in symbols and flexibility, but I'm confident we can support it pretty well. This also means we can identify attempts to create a new CSharp.Compiler() or an attempt to use Directory.Files(...).  What we can do, is write a small piece of reflection code and extract classes/methods/etc, and pull them into our system, with certain filters to remove entire namespaces, classes, or just elements of a class.

Because the parsing system will exist, we will be able to apply colors and formatting.

So, I'm building a C# IDE in Unity, with Intellisense, custom. 


This feels a bit overwhelming, but it also feels like I have a set of surmountable tasks. I've got work to do.

Comments

  1. Update: I'm looking into potentially using Roslyn to parse the C#. After initial seeing if I could pull in the DLL's, I'm finding enough issue that it might not install well on client machines. However, I also found out its open source. :) So now I'm seeing about extracting the API's that will allow me to cut out a huge amount of the development work. https://github.com/dotnet/roslyn

    ReplyDelete
  2. I downloaded the Roslyn code, and made sure it loaded. It did need to do a VS project upgrade of some type. There were over 200K unit tests, so I only executed the C# Parsing related ones (194), and those all passed.

    NEXT STEPS:
    - Run a larger test pass, including all C# (not just parsing in specific, though not all will be needed for working.) I'm currently 7K passes, no fails into >80K unit tests.
    - I have to extract the C# parser from Roslyn and import it into the Unity project.
    - I need to verify parser works in Unity directly.
    - Then I need to test on a clean VM with no Development IDE's installed.
    - - This is to make sure it can run cleanly on install to client machines.
    - - if not, I'll need to catalog/research the minimum installs needed, and what it will take to create an installer to do that.

    ReplyDelete
  3. 119 failed for memory issues. :( Investigating

    ReplyDelete
  4. ok,
    - 1026 test cases were skipped (for I assume environmental/version support)
    - 83816 test cases passed.
    - the 119 failed test cases happened when the computer fell asleep during execution. I assume a setup timed out, and crashed the rest. But there were no issues when I ran them without it sleeping. :D

    On to the next step of extracting the parser and putting it into Unity...

    ReplyDelete
  5. OI... I've probably put about 5 hours into stripping out code now. First, I've been removing everything that deals directly with Visual Basic, as that has nothing to do with this. That initially affected some test cases, and a few support libraries, and created around 1000 errors. Then I started moving down the line, and with every few changes, the number of errors fluxuates wildly. Mostly it's been clearing out superfluous functions and most methods that depend on them. I still have not been able to run the test case suite again, to see how it's doing, so this is like poking a bunch of holes in ice, hoping I don't fall in. Good luck Dan.

    ReplyDelete
  6. I was really worried that after 7-8 hours of deleting lines, files and entire projects, I had no end in site. Multiple times, I widdled the error list to zero, only to see it climb right up on a rebuild. But finally, it rebuilt clean, and the total test cases are down to 61,858 test cases, and 95% of them are C# Code Analysis. I'm running the test cases again to see if I've destroyed any tests, and if its important or not. Assuming that works out, I'll be committing a new branch to my fork of Roslyn - https://github.com/DanVioletSagmiller/roslyn - and then attempting to port into Unity. There is still plenty of risk ahead, and I've put so much work into it, I'd hate to see it fail somewhere ahead.

    ReplyDelete
  7. Time for a new article to continue this debacle. :(

    ReplyDelete

Post a Comment

Popular posts from this blog

A Momentary Lapse of Passion

How to Setup a Multi-Scene Unity Project for Startup