Have you considered telling us what you find incorrect about the folding behavior?
I’m sorry I missed. So if I collapse BEGIN END block, it doesn’t collapse till the END keyword. Similarly, if I collapse a nested if block but doesn’t match. Please find the below screenshots. You can also try using the link.
Ah I see what you mean now. The SQL parser doesn’t really know SQL syntax, only tokens, and will fold any ‘statement’ that ends in a semicolon. In the constructs you are using there, that doesn’t work at all. SQL constructs are unfortunately pretty complicated and wildly different between different dialects, so properly parsing them isn’t something I want to commit to. There might be some heuristics we could use to improve stuff, but I’m not familiar enough with modern SQL to really know.
I can may be try creating custom folding. I’m guessing it should be part of PostgreSQL dialect. If you can give me some pointers where I can make changes then it would be helpful.
Hi @marijn,
I’m attaching the cold folding we used for CodeMirror 5 which kind of worked except nested blocks. May be this is a good starting point.
pgadmin-sqlfoldcode.js (4.5 KB)
Hi,
I can work on a PR if you guide me a bit. It will help a lot pgAdmin users.
If I had a good idea on how to do this, I would probably already have implemented it. But given that this is syntax the parser doesn’t recognize, I’m not sure how to derive folding information for it in a general way.
Can’t a dialect provide custom parsing or codefolding? Or is there any way to override code folding?
Hi @marijn,
Will creating a separate grammar for PostgreSQL work just like lang-sql/src/sql.grammar at main · codemirror/lang-sql · GitHub?
It would be good to get this correct for a lot of pgAdmin users. Please guide me.
It would have to be a lot more complex. That one is basically just a tokenizer, doesn’t recognize any actual syntax beyond that.