Adding #region folding markers to language-configuration.json in asciidoc extension

Viewed 692

Dear fellow VSCode users!

I've recently switched to VSCode from Sublime3, and I've finally found how region coding works. When writing documentation in AsciiDoc however, it doesn't work, as it isn't defined (yet).

So I found this in the VSCode documentation: language-configuration-guide#folding and tried tweaking the language configuration file in the extension's folder. Here is a link to the extension in quesiton: joaompinto.asciidoctor-vscode.

Now, when I add the lines from the documentation to the end of the language configuration json and restart VSCode, it offers a minus sign to collapse the region for the first region defined in the code, not for subsequent ones. Also, when I create new regions, it doesn't register them as such.

Also, as it is a straight copy over from the JavaScript language configuration file (from the documentation), I assume it should work no problems, due to single-line comments in JavaScript and AsciiDoc being the same.

Is this a regex problem and I have to write the regex differently somehow (I'm not a heavy regex user). Am I missing something else? Do I have to make any changes elsewhere in the extension?

Thank you all and a happy, productive new year.

1 Answers

The AsciiDoc extension has its own folding provider implementation (this is the third, programmatic kind of folding mentioned in the docs you linked). If a folding provider is registered for a language, the indentation-based folding and the "folding" section in the language configuration are ignored.

You can avoid this by adding the following to your settings, in which case region folding works as expected for me with your modification:

"[asciidoc]": {
    "editor.foldingStrategy": "indentation"
}

Curiously, AsciiDoc's folding provider seems to be copied from VSCode's built-in Markdown extension, and as such supports folding for regions in the form of <!-- #region -->. In theory at least, in practice it seems to simply crash instead, which I've reported here.

Related