[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.
I've updated the OP with some of the latest features.

CWTools now provides intelligent validation and completion for all moddable files. These rules are defined here: https://github.com/tboby/cwtools-stellaris-config
If find a mistake or are interested in helping improve the rules, just get in touch!

Next up, EU4 and HOI4 support! Again, help in developing the rules is always welcome.
 
I'm noticing that it throws errors on custom added things. For example, if I create a new civic called my_custom_civic, and have something check for it like:

has_valid_civic = my_custom_civic

It will give an error: "Expected value of type civic CW240(CW240)"

This goes for jobs, buildings, all sorts of things. Is there any way to make the error checker recognize mod-added content so this doesn't happen?

Edit: It also tells me there is no localization for things that absolutely, 100% have defined localization, so I am assuming that there's something I'm doing wrong that it's not looking for localizations properly?

Edit 2: Also uhh maybe I don't understand how the config works, but is there any way to tell it to ignore an entire folder and all its subfolders and their contents for error checking, rather than individual files?

Awesome tool, btw, thank you.
 
Last edited:
Is there any way to make the error checker recognize mod-added content so this doesn't happen?
This should be the default behaviour :) Your mod content should be used for validation as well as completion.

The most common reason I see for the kind of problem you're talking about (where it doesn't seem to load all your files) is only opening one file at a time in vscode.
It will only correctly load everything if you use "File -> Open Folder" and then open either:
1. Your mod folder directly
2. The Stellaris folder two levels above it (e.g. either Stellaris in documents, or Vanilla Stellaris)

If you open the Output (View, Output) and then select "Paradox Language Server" in the drop down in the panel that opens, you can see the extension's logging. It narrates its search for your mod files a little, so you might see something useful there!

As to ignoring whole folders, I haven't had anyone ask for that, and I'm not sure why you'd need it. You can type file filters in the "Problems" list to filter to only certain folders, if that's what you're trying to do? The individual file ignores were really meant for things like credits.txt which aren't script files.
 
This should be the default behaviour :) Your mod content should be used for validation as well as completion.

The most common reason I see for the kind of problem you're talking about (where it doesn't seem to load all your files) is only opening one file at a time in vscode.
It will only correctly load everything if you use "File -> Open Folder" and then open either:
1. Your mod folder directly
2. The Stellaris folder two levels above it (e.g. either Stellaris in documents, or Vanilla Stellaris)

OK, that fixed it, thanks! The issue was that I had loaded a container folder for both the mod folder and the .mod file into a VBC "workspace" rather than using this method.

As to ignoring whole folders, I haven't had anyone ask for that, and I'm not sure why you'd need it. You can type file filters in the "Problems" list to filter to only certain folders, if that's what you're trying to do? The individual file ignores were really meant for things like credits.txt which aren't script files.

I'm migrating from Atom where I had kept a copy of the Stellaris files loaded as a kind of reference. When I do this in VBC with CWTools, all kinds of errors pop up because it's not technically the base files, just a copy. I guess I could point to the base files instead, I'm just super paranoid about changing them haha.
 
Hm, well I can use "Open Folder" to add my mod and have it parse correctly and then save it as a workspace, but if I add even the base game files to that workspace, even if I have error checking for vanilla files turned off, it will show errors. I dunno, maybe there's a better way to do this? I've found it just incredibly useful to have all the vanilla files loaded in my workspace to refer to when modding, but I can't figure out how to make it work here.
 
Hm, well I can use "Open Folder" to add my mod and have it parse correctly and then save it as a workspace, but if I add even the base game files to that workspace, even if I have error checking for vanilla files turned off, it will show errors. I dunno, maybe there's a better way to do this? I've found it just incredibly useful to have all the vanilla files loaded in my workspace to refer to when modding, but I can't figure out how to make it work here.

Better workspace support is something I'd like to do, but it's far from simple unfortunately.

I can't test this right now, but a workaround might be:
1. Place your Stellaris copy in a path that *does not* contain "Stellaris". E.g. F:/Programming/StellarisCopy/
2. Open your mod folder
3. Activate the extension (by opening a file in your mod).
4. Add the "StellarisCopy" folder to workspace.

CWTools uses the file path to detect script files (as I can't globally take .txt!) so if your vanilla files aren't stored under a folder called "Stellaris", they shouldn't trigger validation.
 
I'm getting some errors I can't quite figure out.
{
"resource": "/c:/Users/EspenHansen/OneDrive/Modding/Stellaris/Mods/essi2tweaks/Stellar Naming/common/random_names/00_empire_names.txt",
"owner": "_generated_diagnostic_collection_name_#2",
"code": "CW002",
"severity": 8,
"message": "This block has mixed key/values and values, it is probably a missing equals sign inside it.",
"source": "CW002",
"startLineNumber": 1153,
"startColumn": 2,
"endLineNumber": 1153,
"endColumn": 7
}

{
"resource": "/f:/Steam/steamapps/common/Stellaris/common/random_names/00_empire_names.txt",
"owner": "_generated_diagnostic_collection_name_#2",
"code": "CW002",
"severity": 8,
"message": "This block has mixed key/values and values, it is probably a missing equals sign inside it.",
"source": "CW002",
"startLineNumber": 1153,
"startColumn": 2,
"endLineNumber": 1153,
"endColumn": 7
}

And several of these, but only in the modded file, not the original. Even though the script parts in question are identical in both.

{
"resource": "/c:/Users/EspenHansen/OneDrive/Modding/Stellaris/Mods/essi2tweaks/Stellar Naming/common/random_names/00_empire_names.txt",
"owner": "_generated_diagnostic_collection_name_#2",
"code": "CW251",
"severity": 4,
"message": "This AND is unnecessary",
"source": "CW251",
"startLineNumber": 4941,
"startColumn": 4,
"endLineNumber": 4941,
"endColumn": 7
}

EDIT: Similar issue with 00_rules.txt gives warning in the modded file, but not the original
 
Last edited:
I'm getting some errors I can't quite figure out.
{
"resource": "/c:/Users/EspenHansen/OneDrive/Modding/Stellaris/Mods/essi2tweaks/Stellar Naming/common/random_names/00_empire_names.txt",
"owner": "_generated_diagnostic_collection_name_#2",
"code": "CW002",
"severity": 8,
"message": "This block has mixed key/values and values, it is probably a missing equals sign inside it.",
"source": "CW002",
"startLineNumber": 1153,
"startColumn": 2,
"endLineNumber": 1153,
"endColumn": 7
}

{
"resource": "/f:/Steam/steamapps/common/Stellaris/common/random_names/00_empire_names.txt",
"owner": "_generated_diagnostic_collection_name_#2",
"code": "CW002",
"severity": 8,
"message": "This block has mixed key/values and values, it is probably a missing equals sign inside it.",
"source": "CW002",
"startLineNumber": 1153,
"startColumn": 2,
"endLineNumber": 1153,
"endColumn": 7
}

And several of these, but only in the modded file, not the original. Even though the script parts in question are identical in both.

{
"resource": "/c:/Users/EspenHansen/OneDrive/Modding/Stellaris/Mods/essi2tweaks/Stellar Naming/common/random_names/00_empire_names.txt",
"owner": "_generated_diagnostic_collection_name_#2",
"code": "CW251",
"severity": 4,
"message": "This AND is unnecessary",
"source": "CW251",
"startLineNumber": 4941,
"startColumn": 4,
"endLineNumber": 4941,
"endColumn": 7
}

EDIT: Similar issue with 00_rules.txt gives warning in the modded file, but not the original
By default errors in Vanilla are hidden (as you usually aren't interested in validating/edited vanilla directly :) ).
If you were to enable the setting "cwtools.errors.vanilla" then you would see the same errors in the vanilla files.

That specific error is there to warn about the following:
Code:
some_cause = {
    first = true
    second = false
    third true
    fourth = true
}

It just happens that those name files are the only place where it's ok to mix "x = y" and "x y" in the same clause.
If the error bothers you, you can always disable it in the "cwtools.errors.ignore" setting.

As to the redundant AND, yes, vanilla isn't perfect! :)
 
Please explain how to validate the files. I have the extensions installed and the syntax highlighting and help with completing all work and I can see how it helps me while typing but how can I get your tool to check my mod for errors in the existing code?

Thanks
If you use "Open folder" and select your mod folder, it will load and validate as soon as you open a file inside it. This can take a minute or two to load depending on your PC's speed. You'll know it's happening because there's some progress text in the bottom left. "Loading project..." then "Validating files...". To test it just set a trigger/effect to a nonsense value, you should see it highlight that as an error.
 
If you use "Open folder" and select your mod folder, it will load and validate as soon as you open a file inside it. This can take a minute or two to load depending on your PC's speed. You'll know it's happening because there's some progress text in the bottom left. "Loading project..." then "Validating files...". To test it just set a trigger/effect to a nonsense value, you should see it highlight that as an error.

Thank you for your reply.

I understand but I still need some help. It keeps saying generating vanillia cache so I think I have the cache directory syntax wrong. The install is at

I:\Steam\steamapps\common\Stellaris - maybe the program has a problem with the install being on a drive other than c ?

using jason for the setting file it keeps trying to format it as

Code:
{
    "cwtools.cache.stellaris": "\"I\\Steam\\steamapps\\common\\Stellaris\"",
    "cwtools.localisation.languages": [ "English",],
    "cwtools.errors.vanilla":false,
    "cwtools.experimental":true,
    "cwtools.trace.server": "off",
    "cwtools.errors.ignorefiles": ["README.txt,credits.txt,credits_l_simp_chinese.txt,reference.txt,startup_info.txt"],
    "files.associations": {
        "*.txt": "stellaris"
    },
    "workbench.startupEditor": "newUntitledFile"
}

and jason shows no errors in the settings file. If I try to make any changes then jason complains about errors in expected syntax.

1) so is this correct the way jason wants to format the cache location?
2) for file association I have some drive letter short cuts that bypass the Stellaris so I tried to use "mod" but only ".txt" seems to work.

For my test error I did

Code:
immediate = {
        add_resource = { fred = 54000 }
    }

and the program never marks fred as being in error but as I said it keeps doing the generate vanilla cache.

EDIT:

I also tried the following with no change

Code:
{
    "cwtools.cache.stellaris": "I\\Steam\\steamapps\\common\\Stellaris",
    "cwtools.localisation.languages": [ "English",],
    "cwtools.errors.vanilla":false,
    "cwtools.experimental":true,
    "cwtools.trace.server": "off",
    "cwtools.errors.ignorefiles": ["README.txt,credits.txt,credits_l_simp_chinese.txt,reference.txt,startup_info.txt"],
    "workbench.startupEditor": "newUntitledFile",
    "files.associations": {
        "*.txt": "stellaris",
        "*.yml": "stellaris",
        "mod": "stellaris",
        "Stellaris": "stellaris"
    }
}

so what should I change to the above?
 
Last edited:
Thank you for your reply.

I understand but I still need some help. It keeps saying generating vanillia cache so I think I have the cache directory syntax wrong. The install is at

I:\Steam\steamapps\common\Stellaris - maybe the program has a problem with the install being on a drive other than c ?

using jason for the setting file it keeps trying to format it as

Code:
{
    "cwtools.cache.stellaris": "\"I\\Steam\\steamapps\\common\\Stellaris\"",
    "cwtools.localisation.languages": [ "English",],
    "cwtools.errors.vanilla":false,
    "cwtools.experimental":true,
    "cwtools.trace.server": "off",
    "cwtools.errors.ignorefiles": ["README.txt,credits.txt,credits_l_simp_chinese.txt,reference.txt,startup_info.txt"],
    "files.associations": {
        "*.txt": "stellaris"
    },
    "workbench.startupEditor": "newUntitledFile"
}

and jason shows no errors in the settings file. If I try to make any changes then jason complains about errors in expected syntax.

1) so is this correct the way jason wants to format the cache location?
2) for file association I have some drive letter short cuts that bypass the Stellaris so I tried to use "mod" but only ".txt" seems to work.

For my test error I did

Code:
immediate = {
        add_resource = { fred = 54000 }
    }

and the program never marks fred as being in error but as I said it keeps doing the generate vanilla cache.

EDIT:

I also tried the following with no change

Code:
{
    "cwtools.cache.stellaris": "I\\Steam\\steamapps\\common\\Stellaris",
    "cwtools.localisation.languages": [ "English",],
    "cwtools.errors.vanilla":false,
    "cwtools.experimental":true,
    "cwtools.trace.server": "off",
    "cwtools.errors.ignorefiles": ["README.txt,credits.txt,credits_l_simp_chinese.txt,reference.txt,startup_info.txt"],
    "workbench.startupEditor": "newUntitledFile",
    "files.associations": {
        "*.txt": "stellaris",
        "*.yml": "stellaris",
        "mod": "stellaris",
        "Stellaris": "stellaris"
    }
}

so what should I change to the above?

Assuming you're on windows, the minimum configuration I think you'd want is the following. The path format is different to yours, that double quoting is weird. I would recommend trying without any file association for *.txt, as that might cause cwtools to trigger in places it can't properly support. The "messages" trace value will produce a little more diagnostic info in the log.
Code:
        "cwtools.cache.stellaris": "f:\\Games\\Steam\\steamapps\\common\\Stellaris",
    "cwtools.trace.server": "messages",
        "cwtools.rules_version": "latest",
        "extensions.autoUpdate": true,

You can always try setting the stellaris path to blank and it'll prompt you to select it through the pop-up, which should get the format right.

If that doesn't work, please follow these steps to get some log files and PM them to me so I can have a closer look :)
1. Open vscode/cwtools and let it try and do the initial load (give it a minute or so)
2. View -> Output
3. In the panel that opens, on the right hand side, select "Paradox language server" in the dropdown. If there are multiple, pick the one with more it in.
4.Copy that log into a file/pastebin/somewhere and send it to me in a PM. Please note it might have your user path in there, so make sure to censor that if you don't want me to know it.
 
Does this work for Vic2 files as well?
simsulla kindly contributed a good amount of the basic support for Vic2, so if you open a vic2 mod it should activate and do basic syntax validation.
However, the rules that provide more detailed validation/completion/etc aren't quite done, so you'll get quite a lot of false positives. If you'd be interested in helping finish support for vic2 send me a PM and I can link you to the github repository where you can contribute :)
 
I'm getting error messages on random lists that seem incorrect. It looks like, from the tooltip, what's expected is something like this:

Code:
random_list = {
            0.5 = { do stuff }
}

Because it says it wants a floating point value between 0 and 0.99999. However, the base game code contains plenty of random lists that are like this:

Code:
random_list = {
            50 = { do stuff }
}

With whole number values that are conceptually percentages. What's going on?

OP6arAu.png
 
I'm getting error messages on random lists that seem incorrect. It looks like, from the tooltip, what's expected is something like this:

Code:
random_list = {
            0.5 = { do stuff }
}

Because it says it wants a floating point value between 0 and 0.99999. However, the base game code contains plenty of random lists that are like this:

Code:
random_list = {
            50 = { do stuff }
}

With whole number values that are conceptually percentages. What's going on?

OP6arAu.png

The odds are that you have an error inside one of the effect blocks inside.

It's a slight flaw with how the rules are set up. It has two versions of `random_list`, one with integers and one with percentages.
It's seeing that inner error and going "Oh, maybe the mistake is that I picked the wrong type of random_list", so gives you that error *in addition to the real error inside*.
I should perhaps try and link the two errors to make it clearer.

Is that right?
 
I'm getting a problem since yesterday where autocomplete suggestions on ctrl+space only show the terms already in the file (not even paradox language stuff, it shows as autocomplete even stuff I write on comments) prefixed by an icon containing the letters abc. I suppose this is a Visual Studio Code utility and has nothing to do with your extension.

It appears your extension simply stopped working properly. I can still see it sending and receiving messages, but nothing gets validated and no code suggestion works (the code snippets for events work, by the way, that's the only thing still working).

I don't understand a thing about the internal workings of a Visual Studio Code extension but something is definitely broken. I have both CWTools Paradox Language Server and Paradox Syntax Highlighting.

Now, getting to the point, should I try to reinstall? How to do that properly, just click uninstall on both extensions, close VS Code, open it search for them and install again? Or should I not do that and something else instead to fix it?

Thanks for this great extension and for any help you're willing to offer to solve this issue.