Forum Stats

  • 3,757,778 Users
  • 2,251,265 Discussions


Code folding improvement suggestion

User_K8OUQ Member Posts: 1 Green Ribbon


first off, I wanted to say thanks for the extension, it really makes my life easier :)

One thing that doesn't seem to work 100% correctly is code folding in .plsql files. After a bit of experimentation, I found out how to fix it fairly simply, but I'll have to apply the fix after each update of the extension, so I thought I'd try to get the fix into the extension itself, so it might benefit other users as well.

The problem:

Starting with this code block:

Currently, when I fold the first line, I get this:

Instead, with my fix, everything works as it should:

The fix:

In the language-configuration.json file, I added LOOP, IF and CREATE as possible folding start markers by changing the original regex ("^\\s*([Bb][Ee][Gg][Ii][nN])\\b") to this regex:


(as the comment in the language config file explain, the weird doubling of letters is needed to make the regex case insensitive)

It is possible that I am missing some more block opening keywords. Essentially, the beginning keyword of any block that can contain other blocks should be listed in the regex.

The explanation:

Here's my guess as to why folding is broken and why my fix works.

In the current state, VS Code sees the BEGIN keyword and finds the first instance of END and treats that as the end of the block, leaving two trailing END statements.

With my fix, VS Code understands that the IF (and LOOP and CREATE) keyword also enters a code block, which makes it consume the END statements correctly.

As I said, that is just an educated guess, as I haven't worked with VS Code extensions and language definitions before, but it makes sense to me.

Hopefully this post is clear and understandable.

Have a nice day,