cyrusfirheir / twee3-language-tools

[ VSCode extension ] Syntax highlighting and programmatic language tools for Twee 3, and Twine 2 storyformats.
https://marketplace.visualstudio.com/items?itemName=cyrusfirheir.twee3-language-tools
MIT License
47 stars 15 forks source link

Auto-indentation rules #144

Open ghost opened 1 year ago

ghost commented 1 year ago

I've noticed that currently there isn't any auto-indentation rules for Sugarcube 2 at least. Unless I'm wrong and they're in one of the configuration files. I was thinking just for the built in macros that Sugarcube has for now. Since you can add your own, I have my own that I've added in there but I'm not much of regex wizard so the indentation rules are pretty janky but the decrease rules seem to work fairly well.

"indentationRules": { "increaseIndentPattern": "^\\s*<<(capture.*|type.*|if.*|elseif.*|else|for.*|switch.*|button.*|cycle.*|link.*|linkappend.*|linkprepend.*|listbox.*|prepend.*|replace.*|createaudiogroup.*|createplaylist.*|done.*|repeat.*|timed.*|widget.*)>>.*$", "decreaseIndentPattern": "^\\s*<<(\\/.*|elseif|else)>>.*$" },

This is what I have going on so far, I kept matching other non-indentation macros. Which is why the first part is so bad but think this would be a good addition to this awesome extension.

Thanks, Dz

Tranberry commented 1 year ago

the AI wants to add (?!\\w) to link like so: cycle.*|link(?!\\w).*|linkappend.*.

I wonder if it's dizzy or actually on to something. I mean would VS Code really add multiple indentations due to matching with link and linkappend and linkprepeand? I figure it is dizzy but still worth a thought.

It's also saying that elseif and else should be covered by the <<\\/.*>> pattern but I figured you had to add it while testing.

ghost commented 1 year ago

the AI wants to add (?!\\w) to link like so: cycle.*|link(?!\\w).*|linkappend.*.

I wonder if it's dizzy or actually on to something. I mean would VS Code really add multiple indentations due to matching with link and linkappend and linkprepeand? I figure it is dizzy but still worth a thought.

It's also saying that elseif and else should be covered by the <<\\/.*>> pattern but I figured you had to add it while testing.

<<\\/.*>> Shouldn't be matching elseif and else. It should just match any macro that closes with / like <</if>>. Know that in the language-configuration file you have to escape a lot of the \ characters for it to be parsed by VSCode. So not sure if the AI is reading the extra \ characters that normal regex usually doesn't need.

Also my regex doesn't account for 1 liners and oops, wrong button when replying.

cyrusfirheir commented 1 year ago

Indentation rules require more investigation. Single regular expressions don't handle all edge cases properly.

Meanwhile, v0.22.0 adds OnEnterRules for SC-2. It will use custom definitions from config files alongside the built-in macro list to indent inside container macros. Hopefully, that is helpful.

Besides, #118 has always been on the todo-list.

ghost commented 1 year ago

Oh I missed that issue but I'll give the 0.22.0 version a go and if some of them work then I'm good. Thanks.