Author Topic: Ruleset Validator for VSCode  (Read 1135 times)

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2108
    • View Profile
Ruleset Validator for VSCode
« on: August 30, 2018, 02:54:16 am »
I made an extension for Visual Studio Code that checks your rulesets for syntax errors so you can catch them as you type instead of having to wait for OpenXcom to crash/spew nonsense/do nothing when you make a typo. It looks like this:



I figured it was more useful to extend a familiar text editor than trying to make an entirely separate tool. If this is worth developing further let me know.

Installation Instructions
1. Install Visual Studio Code if you don't already have it.
2. Install the OpenXcom Ruleset Tools extension and follow the instructions.
3. Just open any .rul file and edit away.

Recommended Usage:
- Use File > Open Folder (or Open With Code in explorer) to open an entire mod at a time, so your workspace is preserved per mod.
- Open the View > Problems window to get a listing of all the errors in the currently open files.
- Use Trim Trailing Whitespace to fix tab errors (this can be done automatically in the Preferences).

What's Visual Studio Code? Isn't that some kind of IDE?
Despite the name, VSCode (for short) is just a fancy text editor in the vein of Notepad++/Sublime/Atom/etc. It's not related to Visual Studio (the IDE) which we use for developing OpenXcom.
It can be extended to be very powerful, but you don't need to be a programmer to use it. I know we've always recommended Notepad++ for YAML, but it's become kinda lackluster over the years.

Why not <insert your favorite editor>?
VSCode is free, cross-platform, and honestly it was the easiest to extend. It already had a powerful YAML extension available so I just had to build on that. If you'd rather port it to <insert your favorite editor> the source is here: https://github.com/OpenXcom/vscode-ruleset
« Last Edit: January 04, 2019, 12:29:54 am by SupSuper »

Offline FeruEnzeru[RETIRED/I QUIT]

  • Colonel
  • ****
  • Posts: 430
  • retired, because of Meridian and his followers. 👎
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #1 on: August 30, 2018, 03:30:12 am »
Nice idea, SupSuper. :)

I do not know Visual Studio Code since i always use Notepad++ for rulesets and other things 3 years ago, but i'll get VSCode and the Ruleset Validator extension for it maybe tomorrow after some things (like HxD).

I would probably give that a try if like since i've read your thread and the gif on there.
I hope this requires Windows 10 because i always use W10 instead of Windows 7 and 8.

It would be cool and awesome for OpenXCOMmers to try this out. :D



Thank you for posting this on the forums. ;)

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1210
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #2 on: August 30, 2018, 02:32:30 pm »
Very cool! I just use Notepad++ though. It doesn't do all that, but it does some of it at least.

I wonder if one could use this to scan for new rules they didn't know about?
« Last Edit: August 31, 2018, 09:11:11 pm by The Reaver of Darkness »

Offline davide

  • Commander
  • *****
  • Posts: 579
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #3 on: August 30, 2018, 03:11:31 pm »
+100

Offline Finnik

  • Sergeant
  • **
  • Posts: 28
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #4 on: December 02, 2018, 04:13:12 pm »
Its totally great! im using it full time for modding. one question - is there any way to add custom commands? as it counts all OXCE syntax as an errors.

Offline Yankes

  • Commander
  • *****
  • Posts: 2072
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #5 on: December 02, 2018, 08:20:01 pm »
Yes it should allow as SupSuper careate it anybody can alter it to fit it goals.

btw SupSuper maybe add this file to `docs` folder in oxc repo? This could be source of truth for ruleset available for users.
When someone add new ruleset he need update this file, some thing like this I did for oxce documentation.

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2108
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #6 on: December 05, 2018, 08:51:07 pm »
Yes it should allow as SupSuper careate it anybody can alter it to fit it goals.

btw SupSuper maybe add this file to `docs` folder in oxc repo? This could be source of truth for ruleset available for users.
When someone add new ruleset he need update this file, some thing like this I did for oxce documentation.
Arguably you could count this as the "source of truth": https://github.com/OpenXcom/vscode-ruleset/tree/master/schemas
Though it's already out-of-date :( I'm trying to figure out a way of having versioning and OXC/OXCE without making a mess of things.

Offline Yankes

  • Commander
  • *****
  • Posts: 2072
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #7 on: December 05, 2018, 10:49:44 pm »
To reduce my work needed for describing every possible script function and its parameters I made hack, hole metadata need to parse string can be dump in semi human readable format. Something similar could be done for ruleset.

This probably would need some metaprograming or warper that will at once describe format and load data.

e.g.
Code: [Select]
void generateSchema()
{
  _schema = Schema<T>();
  _schema.field(&T::_id, "id of something");
  _schema.field(&T::_type, "type");
  _schema.field(&T::_weapon, "default weapon");
}
void load(Yaml::node& n)
{
   _schema.load(this, n);
}
Yaml::node save() //if we expand this do saves too
{
   return _schema.save(this);
}
std::string dump()
{
  return _schema.dump();
}

And then source of truth will be `oxc.exe --dump=filename.json`

[ps]

`dump()`  probably should dump YAML too, because it will be more compossible.
« Last Edit: December 06, 2018, 12:50:01 am by Yankes »

Offline luke83

  • Commander
  • *****
  • Posts: 1423
    • View Profile
    • openxcommods
Re: Ruleset Validator for VSCode
« Reply #8 on: December 18, 2018, 07:11:54 am »
Trying this out tonight, i am making HEAPS of errors in my first Ruleset so i need all the help i can get :)

I have installed VS2017 Community edition, i have also followed the link but the Download Buttone does nothing, how do i install and Use this, is there a video tutorial? OK, trying CSCODE instead. :P

I have found and fixed more errors tonight since installing this ruleset checker than i have in the last 2 weeks combined, this is GREAT!!!!!!!

SupSUper - Question, does this only know about Vanilla commands? I noticed the AllowKneel command from OXCE is marked as a issue, i have ignored it for now.
« Last Edit: December 18, 2018, 10:31:25 am by luke83 »

Offline Yankes

  • Commander
  • *****
  • Posts: 2072
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #9 on: December 18, 2018, 01:36:15 pm »
When I find some time I will fork this validator and add OXCE specific properties.

Offline FeruEnzeru[RETIRED/I QUIT]

  • Colonel
  • ****
  • Posts: 430
  • retired, because of Meridian and his followers. 👎
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #10 on: December 21, 2018, 11:45:12 pm »
Hmmm... Maybe i'll use VSCode for OXC til OXCE codes are added to the RS-Validator. (sometimes OXCE's really important for mods that require that stuff, especially people waiting for OXCE codes to be on the RS-Validator extension for their mods too)

Is is okay if can still use Notepad++ while waiting. :D

ps: I've installed VSCode and that on the 2nd of this month and checked it out, it looks fine and useful to anyone's opinion :), i'll use it unless OXCE codes and custom codes are there.
« Last Edit: December 21, 2018, 11:46:43 pm by FeruEnzeru »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2108
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #11 on: January 04, 2019, 12:25:03 am »
OpenXcom Extended support is here! It's a Christmas New Years miracle! After updating the extension (should happen automatically next time you run VSCode) just go into your Settings and pick your preferred version. If you run into any bugs let me know.


Offline FeruEnzeru[RETIRED/I QUIT]

  • Colonel
  • ****
  • Posts: 430
  • retired, because of Meridian and his followers. 👎
    • View Profile
Re: Ruleset Validator for VSCode
« Reply #12 on: January 04, 2019, 01:19:35 am »
@SupSuper
OpenXcom Extended support is here! It's a Christmas New Years miracle! After updating the extension (should happen automatically next time you run VSCode) just go into your Settings and pick your preferred version. If you run into any bugs let me know.


Sweet! I'm trying this out since it got updated for adding OXCE! ;D

Before i finding the right stuff, i said "OMG" before i got to my settings for the VSCode stuff :O, turns out, it showed me endless amounts of "idunnowhatdeyare" stuff meaning syntax errors for some kind.

If so, i might need to move my .rul file stuff from notepad++ since this came out. Does this work on looking up (or editing) saved (OXC/OXCE) games/states or no? ???


EDIT: Oh yeah, tried to see if a .sav file would work, turns out, .sav files won't work on the Ruleset Validator (just to check to see if it work). Sorry! :(
« Last Edit: January 04, 2019, 01:54:34 am by FeruEnzeru »