1. Thread posting restricted: Only the BeamNG team members can post new threads in this sub-forum in order to prevent spam. New: Feel free to reply and comment :)

Trying out a new editor

Discussion in 'Microblogs' started by Diamondback, May 6, 2018.

  1. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    986
    Today, we talk about something a bit different, editor workflow! :) Sounds amazing, doesn't it?
    I'm sure some of you can appreciate a little insight into how I work with lua and jbeam though. :cool:

    Let's speak first about what tools I've used in the past for the majority of work for BeamNG:
    The Zerobrane IDE is a very nice tool to work with lua, it supports all the nice stuff like syntax highlighting, auto formatting, linting, code outlines etc. All in all a very useful piece of software and what I have used in the past 3 or so years. (It also supports debugging lua with breakpoints and all, but that usually isn't all that helpful with the kind of work I do)
    Here's a typical screenshot:


    The second tool, Notepad++, is something literally everyone should have on their computers, it's just a super handy and powerful text editor. I use it for all text files other than lua, so mostly *.jbeam, *.json, *.pc, etc
    Screenshot:


    In addition to that, I also work a lot with our versioning control software, so that's overall 3 pieces of software for the majority of work.


    Now, just out of curiosity, I wanted to take another look at Visual Studio Code, Microsoft's new-ish all around lightweight code editor. I gave it a spin when it was really new but didn't see any advantages over my existing setup.

    The next post will detail what I've set up now with VS Code and how that works out. :)
     
    • Like Like x 19
    • Informative Informative x 4
    • Agree Agree x 1
  2. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    986
    Now let's take a look at what kind of setup I created for VS Code:
    The requirements are to at least match what I had before:
    • Lua
      • Syntax highlighting
      • Some basic form of code completion (nowhere near as useful as with something like C#)
      • Formatting
      • Linting
      • Code outline/function overview
    • Jbeam
      • Syntax highlighting
      • NO linting (we'll get back to this later)
      • NO auto-formatting
    • Generic text editor features
      • Comment/Uncomment
      • Multi-Cursor editing
      • Duplicate lines
      • Indent visualization
    VS Code itself is not all that powerful, the real advantage is the extension system which allows you to create very nice extensions. By default it doesn't even support lua properly, so the first thing I did was to install a lua extension:
    This already makes a lot of stuff possible with lua inside VS Code. It needs some basic configuration to meet my taste: (note: in VS Code all settings are done via JSON)
    Code:
    "lua.luacheckPath": "C:\\Program Files\\Microsoft VS Code\\luacheck.exe",
    "lua.preferLuaCheckErrors": true,
    "lua.format.indentCount": 2,
    "lua.format.lineWidth": 3000,
    The extension can use the very useful tool "luacheck" to lint your lua code and find potential issues. It's a much better linter than what is build into ZeroBrane, so that's already a plus.
    Typical warnings from luacheck:


    These can sometimes be safely ignored, other times they may point to a serious issue.
    Now, with lua we are already almost there, the only thing missing now is some sort of code outline. Luckily I found a useful extension for that too:
    It adds this little window in the explorer view:


    Good. Lua sorted, the next post will take a look at working with jbeam files. :)
     
    #2 Diamondback, May 6, 2018
    Last edited: May 6, 2018
    • Like Like x 5
    • Informative Informative x 5
  3. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    986
    Jbeam files... In theory these are just loosely based on the JSON sytnax, but in practice they can be quite difficult to work with.

    One of the things that really helps is a good syntax highlighter. It makes you spot mistakes like having used a string instead of an int/float much easier for example. Take a look here:

    Without highlighting:

    With highlighting:


    Note how the "maxIntegralPart" mistake is much much easier to spot now. You could also go ahead and adjust the color settings to make it even more obvious.

    Since jbeam generally uses similar syntax to JSON, finding a syntax highlighter for jbeam is as easy as opening VS Code, it has support for JSON built-in so that's already taken care of. (You'll have to tell VS code to treat jbeam files as JSON data so it automatically uses the right highlighting)

    Now the less fun parts about jbeam, linting and formatting.
    Since jbeam is a superset of JSON, it uses many things that JSON does not support and generally would be plain wrong with strict JSON.
    This makes it difficult to lint a jbeam document, it's somewhat our own format, so there are no tools yet to lint jbeam data. This brings up the first issue with jbeam editing inside VS Code.
    I haven't found a way yet to turn off the VS Code JSON linter, so I'm always stuck with these warnings/errors here:


    This definitely can be ignored, but it's not ideal, especially since I need that panel for my work on lua, so just hiding it is not a solution either.

    The second issue is formatting. While jbeam generally can be formatted by various JSON formatters, the result is often way too verbose when it comes to line breaks. Take a look at this example:
    This is what we usually format our jbeam like:

    Now, if I let VS code format that, it ends up like this:


    Definitely much less usable. So by default, the formatting can't be used.

    Unfortunately I did not find any solution yet for either of these two issues after I set up the whole thing yesterday. I may have to end up writing some jbeam support extension for VS Code.
    Having a working formatter for jbeam is definitely something very desirable.

    The next post will just detail what exact settings I have used and what other extension I installed that are not directly related to lua or jbeam.
     
    • Like Like x 5
    • Informative Informative x 4
  4. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    986
    • Like Like x 6
    • Informative Informative x 3
  5. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    986
    So what does this all boil down to? I can now potentially replace 3 programs (ZeroBrane, Notepad++ and version control) with just one neatly integrated solution while at the same time picking up some additional features.
    Will it work out? I have no idea, but I'm willing to give it a try :)

    Feel free to comment and/or ask questions!
     
    • Like Like x 11
    • Informative Informative x 1
  6. RobertGracie

    RobertGracie
    Expand Collapse

    Joined:
    Oct 15, 2013
    Messages:
    2,842
    When I got into editing files for the game before this for some reason I got Notepad++ installed and it works with the files I mentioned earlier and well being slightly autistic I found change quite difficult to go from one editing program to another, I like having consistency so I can happily go in and edit say the settings.LUA file while editing the utilities.js and also adjusting the en-US.json file in 1 program rather than having to swap between programs for each different file format so thats why for me Notepad++ just works for m, as for those files I mentioned I was adding in additional information to the code to allow for Imperial Gallons and Imperial MPG to be added into my game settings, its just personal preference that I have
     
    • Like Like x 2
    • Agree Agree x 1
  7. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    986
    Let's not turn this into a chat where everyone posts his favorite text editor, ok?

    The idea was to talk about beam specific tasks and solutions. :)
     
    • Agree Agree x 7
  8. Frank ツ

    Frank ツ
    Expand Collapse

    Joined:
    Jan 27, 2015
    Messages:
    88
    you not gonna tell what words are cencored right? in the left side
     
    • Agree Agree x 1
  9. BombBoy4

    BombBoy4
    Expand Collapse

    Joined:
    May 16, 2015
    Messages:
    2,006
    If it's a path, I'd assume the blurred parts are Diamondback's name/other personal info.
     
    • Agree Agree x 3
    • Like Like x 1
  10. luckyman

    luckyman
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    405
    Its most likely hidden or cars and props in the making that aren't going to be released but also doesn''t want the public to know anything about. So its probably nothing to worry about. But this will end up probably in the Update Spec thread.
     
    • Agree Agree x 2
  11. Paul K

    Paul K
    Expand Collapse

    Joined:
    May 7, 2018
    Messages:
    1
    https://studio.zerobrane.com/doc-general-preferences#static-analyzer
    @Diamondback, thank you for the kind words; I have a couple of quick comments on ZeroBrane Studio.

    > The extension can use the very useful tool "luacheck" to lint your lua code and find potential issues. It's a much better linter than what is build into ZeroBrane, so that's already a plus.

    You can use luacheck with ZBS as well, as it comes bundled with it, just not enabled by default (you'll need ZBS version 1.70+). You can enable it with `staticanalyzer.luacheck=true`; you can also pass a table with luacheck options. See the documentation for details/examples: https://studio.zerobrane.com/doc-general-preferences#static-analyzer

    > Since jbeam generally uses similar syntax to JSON, finding a syntax highlighter for jbeam is as easy as opening VS Code, it has support for JSON built-in so that's already taken care of. (You'll have to tell VS code to treat jbeam files as JSON data so it automatically uses the right highlighting)

    You can do the same thing with ZBS with something like this: `editor.specmap.jbeam = 'json'`. In fact, since the lexers are in Lua, you can tweak the json lexer to parse jbeam files and register it from a plugin.

    ZBS uses the same editor component as Notepad++ (Scintilla), so they should be on par in terms of editor features, but ZBS also includes some development features not available in Notepad++, like a command bar with fuzzy matching for files and symbols, search/replace in files with preview and undo, markers panel, plus all the Lua-related features. The outline also includes functions not generally available in other editors (https://studio.zerobrane.com/doc-general-preferences#outline).

    Let me know if I can help with anything else ZBS-related. Paul.
     
    • Informative Informative x 3
    • Like Like x 2
    • Staff Pick Staff Pick x 2
  12. SixSixSevenSeven

    SixSixSevenSeven
    Expand Collapse

    Joined:
    Sep 13, 2013
    Messages:
    7,042
    Similarly to how you've set your lua indent to 2 space, you can do the same for JSON in your user settings, can also configure the new line setting with a vast array of options available such as whether opening braces go on same line, new line or new line with indent etc
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice