cwtools / cwtools-vscode

A VS Code extension providing language server support for paradox script files using cwtools
Other
88 stars 12 forks source link

Can I use this for non-Paradox games? #97

Closed rlidwka closed 6 months ago

rlidwka commented 6 months ago

Question: can this extension be used as a general-purpose LSP for paradox-like domain-specific languages, if I provide a custom validation schema for them?


I'm creating my own game. I want it to be moddable from the beginning. And I'm looking for a declarative language for config files (scripting if needed would be done in js or lua).

I do not particularly like toml or yaml for this particular case. And I absolutely hate json and xml (looking at you, rimworld), because those are not designed to be written by humans. And I'm a big fan of how Paradox games approach modding, so...

So I thought, can I use paradox's .txt files? File name is a bit unfortunate (what's the file format even called?). But there're plenty of parsers around, and that's the important thing. So let's try, it surely isn't patented or anything, is it.

Syntax highlighting works fine (with Paradox Syntax Highlighting). But I'd like some LSP support as well (autocompletion, maybe documentation).

So, the question is: can I provide a custom schema for cwtools, and use it as general-purpose LSP? I imagine it can look for parent directories for .cwtools folder, and try to apply any schemas found from there.

Or am I crazy for trying to use pdx format for other things? Or should I roll out my own lsp server?

tboby commented 6 months ago

I don't see why not. Keep in mind this extension and the language server behind it are two different things. As it currently stands, this extension might be too tightly coupled to paradox games for you to use my published version of it as your recommended tooling. Look at the client\extension\extension.ts for all the very specific setup I have to make paradox games just work.

You might be able to use a recommended json config which triggered the "paradox" language id, which starts the language server in the "Custom" language. This was designed as a sort of non-specific Jomini (latest paradox scripting engine) mode which supports the latest features but doesn't have any of the game specific assumptions.

As for the language server itself: In Custom mode, it's pretty much 100% based off the rules. If you relied heavily on types and value sets (https://github.com/cwtools/cwtools/wiki/.cwt-config-file-guidance) then you would get pretty much all the language features you need (find all ref, go to def, rename symbol, etc). Documentation is just pulled from the rules.

I would not recommend writing your own LSP server unless you're using a very c or javascript like language which lets you just re-use another as a starting point. There are so many annoying fiddly bits!

If you get to the point of actually having a parser for the format integrated in to your game, and are willing to provide me with some non-trivial sample files (and spec for what they're supposed to be setting), this is interesting enough that I'd probably spend a half-day making any modifications needed to get cwtools/cwtools-vscode general enough for you to use it. :)

There is no name for the file format, but you can pick another extension and just tell cwtools-vscode to detect that :P

rlidwka commented 6 months ago

As it currently stands, this extension might be too tightly coupled to paradox games

Ah okay, thanks. I noticed that extension is tightly coupled, so I thought that LSP might be as well.

I'll try to change this extension and use LSP as is with custom rules, and see how it goes.

There is no name for the file format, but you can pick another extension and just tell cwtools-vscode to detect that :P

I'm not worried so much about extension, but about documentation.

People are gonna ask what format is being used, and how do I call it? "Clausewitz"? "Jomini"? (I don't actually know the difference between those two, just that latter is supposed to be more high level).

Or "that format that's used by Paradox"? It's certainly more descriptive, but using a company name in vain is a sin (kinda like in Exodus 20:7), and punishable by all sorts of trademark laws.