[TOOL] CWTools - a mod validating extension for VS Code

  • We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Dayshine

Second Lieutenant
43 Badges
Aug 25, 2016
111
45
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Common Sense
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Conclave
  • Stellaris
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Crusader Kings II: Monks and Mystics
  • Crusader Kings II: Horse Lords
  • BATTLETECH
  • Surviving Mars
  • Stellaris: Humanoids Species Pack
  • Cities: Skylines - Parklife
  • Imperator: Rome Deluxe Edition
  • Imperator: Rome Sign Up
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Cities: Skylines
  • Europa Universalis IV
  • Crusader Kings II: Charlemagne
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Imperator: Rome
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Crusader Kings II: Sons of Abraham
  • Stellaris: Synthetic Dawn
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sword of Islam
  • Stellaris - Path to Destruction bundle
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Call to arms event
  • Magicka
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Mare Nostrum
  • Sword of the Stars II
  • Crusader Kings II
CWTools is a library that provides common language services for paradox scripting files. This can be used to provide live validation of mod files as you are writing them. This is currently done through an extension for the text editor VS Code.

Current features are for Stellaris and EU4:
  • Immediate highlighting of syntax errors
  • Autocomplete everywhere, providing appropriate dynamically generated options and descriptions when available
  • Community supported rule based validation.
  • A wide range of validators for common, interface, and events, checking
    • That required localisation keys are defined
    • Existence of effects/triggers/modifiers
    • Scope context for used effects/triggers/modifiers
    • Usage of scripted effects/triggers
    • Correct entries for weights/AI_chance/etc
    • That event\_targets are saved before they're used
    • Check all "@" variables are defined before they're used
    • That referenced sprites and graphics files exist
    • and a number of other specific validators
  • "Code actions" to generate .yml for missing localisation
  • Tooltips providing localisation info, effect documentation as well as scope information
  • A range of settings that allow you to customize what errors you see to fit your use

These all happen near-instantly as you're writing, just take a look at the examples below.

8UZDaFL.gif

8UZDaFL.gifv


Validate syntax

VWRXtT7.gif


Check for correct scopes

EPb4XSL.gif


Find missing localisation

pzZ8Z22.gif


Tooltips for effects

qeyMSyo.gif


See all your errors in a nice convenient summary

IaqoFgF.png
Tips:
  • You can type "error", "warning" or "info" into the search box in the problems panel to filter.
  • If you don't like a specific diagnostic, you can use the setting "cwtools.errors.ignore" to hide it
  • By default only English localisation is checked. Use "cwtools.localisation.languages" to check others.
Validation errors/Feedback
The validation rules that make CW Tools work aren't perfect, but are open to contribution from the community. If you think you've found an incorrect error (something that works in vanilla but errors in CW Tools) or have other feedback/suggestions, you can:
1. Post them here, but please provide a complete example
2. PM @Dayshine
3. Have a try at fixing it yourself (Get in touch with me for details, it's really easy)

Contributors:
The initial set of rules that made this all possible were a collaboration of modders from the Stellaris modding den, and we'll try to acknowledge everyone who contributes here.
- ExNihil
- Dayshine
- Caligula Caeser
- had
- Iyur
- ViolentBeetle

Installation:
  1. Install VS Code from https://code.visualstudio.com/docs/setup/setup-overview
  2. Go to the extensions tab and search for "cwtools" (or go to https://marketplace.visualstudio.com/items?itemName=tboby.cwtools-vscode and press "install".
  3. Wait for it to install and "Reload".
  4. Open your mod folder directly, or open your Stellaris folder in "Documents/Paradox Interactive".
  5. Start editing to get syntax validation immediately
  6. Wait up to a minute for the full analysis to kick in.
  7. Take a look at configuration below for available settings.
  8. Optionally, install the syntax highlighting extension https://marketplace.visualstudio.com/items?itemName=tboby.paradox-syntax

Configuration:
The tool currently has the follow settings you can change:
Code:
// Error codes to ignore, list of IDs (e.g. "CW100" for syntax errors)
"cwtools.errors.ignore": [ "CW100" ],

// Whether or not to show errors for vanilla files
  "cwtools.errors.vanilla": "false",

// Whether or not to enable experimental features
"cwtools.experimental": "false",

  // The list of languages to validate localisation for.
  "cwtools.localisation.languages": [
      "English", "German"
  ],

  // Traces the communication between VSCode and the language server.
  "cwtools.trace.server": "off",
 
  //Files to ignore error from, list of file names
  "cwtools.errors.ignorefiles": "README.txt,credits.txt,credits_l_simp_chinese.txt,reference.txt,startup_info.txt"

To change these:
1. File, Preferences, Settings (or Ctrl-comma)
2. Search for "cwtools"
3. Press the pencil icon on the left to modify a setting, and edit them on the right
4. The changes should immediately take effect

Updates:
To update the extension go to the extensions tab, hit the three dots, and press "Check for updates". Then press the update button that appears next to the extension. Alternatively just turn on auto-updating extensions.

If you have suggestions for extra validation errors, warnings, or hints, please post them here.
Planned (Current)
*
Variables: Check variables are used in consistent scopes (if you set on a planet, you can only check on a planet)
* IDE: Contextual autocompletion, only show relevant keywords not all of them!
* Dead code detection (e.g. find events that are never called)
* Localisation: Scripted locs
* Localisation: Check correct scope for localisation keys

Future
* Events: (title, desc, picture, location, show_sound, diplomatic, picture_event_data) + hide_window doesn't make sense
* Events: is_triggered_only = yes and never called
* Performance: never use any_planet or every_system_planet if you are not in system scope
* Localisation: Support custom localisations (e.g. mandarin)
* Localisation: Check validation file names
* Localisation: Reduced false-positives for static modifiers
* Events: This trigger should be a pretrigger
* Variables: Unused by defined variables
* Syntax: Find multiple syntax errors in the same file
* Common: Building tags/component tags need whitespace above/below
* Localisation: Building tags/component tags
* Defines: Check defines overriden by mods exist in vanilla

Blue skies
*

Completed
*
Common: Check all effects/triggers/scopes in all files, not just events.
* Effects/Triggers: Intelligently calculate scope for *recursive* effects/triggers
* Events: event_target is not defined but is used in effect/trigger
* IDE: Autocompletion
* Localisation: traditions, buildings, aura components, component templates
* Localisation: Static modifiers
* Localisation: Check names inside event effects (create_ship `name`)
* Localisation: Check "default" language, i.e. localisation_synced
* Localisation: $keys$
* Localisation: Special command validator (the keywords in localisation strings)
* Modifiers: Check existence of modifiers in common files (buildings, etc).
* Modifiers: Check correct scope usage of modifiers in common files (buildings, etc).
* Modifiers: Derive modifiers from ship sizes
* Variables: Check that variables have been defined somewhere
* Deal with file overwriting with multiple mods

Roadmap
This doesn't include the addition of extra individual validators, but the overall key features.
0.8 (In progress)
* Full support for CK2/HOI4
0.7 (DONE)
* Full support for EU4
0.6 (DONE)
* Basic syntax validation for EU4, HOI4.
0.5 (DONE)
* Tailored trigger/effect checking (e.g. check "who" in effects)
* Performance improvements, reduce startup time
0.4 (DONE)
* Basic effect/trigger/modifier support for all files
* Selective disabling of warnings
* Dependent revalidation (e.g. if you change the localisation file, recheck all files)
0.3 (DONE)
* Full localisation validation (of all required implicit and explicit keys)

Acknowledgements
Thanks to Jamie550 for getting me started.
Also thanks to Caligula, blackninja9939, the ExO team, the Paradoxial Development Group and many others for their patience with my neverending questions.
 
Last edited:
  • 6Like
Reactions:
Thank you for the great tool, I've caught a lot of bugs that would have been missed without it!
 
  • 1Like
Reactions:
This is indeed really helpful and cool, pinned ;)
 
@Tarne you may have missed this as I don't think it's in the description, but you can also get the tool to check the other languages. You have to go on preferences/settings and then look for CW tools, you will find a setting for languages, you then can overwrite it with your own version where you add some languages. I found a quite a lot of localisations that were only missing in one language or other in both my mods and MEM, so it's worth checking that! (I'm assuming STNH has translations)
 
  • 2Like
Reactions:
This looks very promising. Keep up the good work!
 
Very good tool !

It's installed and i started to use it ! 20% cooler than using notepad++ (which is already great).

EDIT:
By the way @Dayshine you say in planned :
"Performance: never use any_planet or every_planet if you are not in system scope"

It's not supposed to be "every_system_planet" ? (every_planet is scopeless)
 
Last edited:
By the way @Dayshine you say in planned :
"Performance: never use any_planet or every_planet if you are not in system scope"

It's not supposed to be "every_system_planet" ? (every_planet is scopeless)

Oops, forgot to reply, I've corrected this now, thanks for the spot!
 
I installed this in vcode and its been able to scan my mod folder once and then just flat out stops even while clicking in a file and making changes nothing happens, no loading files in the bottom left, tried reinstalling the extension a couple times to no avail.
 
I installed this in vcode and its been able to scan my mod folder once and then just flat out stops even while clicking in a file and making changes nothing happens, no loading files in the bottom left, tried reinstalling the extension a couple times to no avail.

Huh, that's odd. I'd appreciate if you could help me work out why, it's generally quite robust and should just work.

1. What OS?
2. What version of the extension?
3. What's the full path to the folder you opened (feel free to censor username etc)?
4. Does it say "paradox" in the bottom right when you have a file open?
5. If you open the Output (Ctrl-Shift-U) and change the dropdown on the right to "Paradox Language Server", is there anything obviously wrong there? Could you possible upload that log for me?
 
Huh, that's odd. I'd appreciate if you could help me work out why, it's generally quite robust and should just work.

1. What OS? Windows 10 64bit
2. What version of the extension? 0.3.3 - I I tried checking for updates for it but found none.
3. What's the full path to the folder you opened (feel free to censor username etc)? :\Users\*****\Documents\Paradox Interactive\Stellaris\mod\Echo2
4. Does it say "paradox" in the bottom right when you have a file open? Yes
5. If you open the Output (Ctrl-Shift-U) and change the dropdown on the right to "Paradox Language Server", is there anything obviously wrong there? Could you possible upload that log for me?
I assume you mean for the output dropdown box where it says Tasks initially there is no option for Paradox Language Server.

One thing that I just noticed on my Windows 7 laptop, with the same mod folder it was set to plain text, when changing it be Paradox like it is supposed to, it started scanning. I also checked the output dropdown since its missing from my win10 machine its visible on the laptop instead.
 
I assume you mean for the output dropdown box where it says Tasks initially there is no option for Paradox Language Server.

One thing that I just noticed on my Windows 7 laptop, with the same mod folder it was set to plain text, when changing it be Paradox like it is supposed to, it started scanning. I also checked the output dropdown since its missing from my win10 machine its visible on the laptop instead.

Just to resolve this in case someone else runs into the issue.

We fixed this by uninstalling the extension, deleting the extension folder at C:\Users\<user>\.vscode\extensions and reinstalling the extension. It looks like something corrupted when it installed.
 
Any chances you intend to add some color coding of keywords, etc. to the editor? Or do you know the textmate theme color rules for the files for us to do it ourselves?
There are two extensions I know of on vscode for paradox syntax highlighting, they can both be found by just searching "Paradox" :)

I might update one of them to cover more stellaris specific keywords and such at some point, but the available ones are enough for now I think.
 
Would it be possible to support alternate directories? I keep my mods in version-tracked repositories elsewhere and copy them in as I update them.

The extension automatically activates when you open a file that meets this pattern "**/stellaris/**/*.txt", e.g. any folder below a folder called "stellaris".

If you want to manually activate it, open your mod folder, open a .txt file, then use the language selector in the bottom right to change it to "paradox". That should do what you want :)