postgres-language-server icon indicating copy to clipboard operation
postgres-language-server copied to clipboard

support plpgsql function bodies

Open psteinroe opened this issue 10 months ago • 5 comments

once we have #178, we can start looking into this too. pg_query.rs already exposes a basic binding for parsing plpgsql. we should first improve that binding upstream and then start adding language features like autocompletion.

psteinroe avatar Jan 28 '25 20:01 psteinroe

Very much looking forward to this. Given that most of our non-trivial sql code is functions rather than regular schema tables and whatnot, not having the language server parse those means we lose a lot of error checking.

mpayette-3rdeyecam avatar Apr 28 '25 17:04 mpayette-3rdeyecam

Is there a way one could help you on this without writing/building (rust) code for this repo @psteinroe ? Like researching, specifying, test examples or other sql/plpgsql related tasks?

Donnerstagnacht avatar May 26 '25 07:05 Donnerstagnacht

we have made a bit of progress here! although there is still a lot to do for "proper" support, we have a clearer road ahead of us now:

  • the latest version (releasing as we speak) will show plpgsql syntax errors. this is a low-hanging fruit we wanted to get out already now
  • unfortunately, proper support will require us to have a proper parser. libpg_query, the underlying postgres parser we use, does support parsing plpgsql, but they do not have a proper binding for it (yet). it returns just unstructured json.
  • there is effort over at https://github.com/sbdchd/squawk to build custom parsers. I am a big fan of the project, but it's a huge effort. maybe the plpgsql syntax is simple enough to get there eventually though.
  • at the same time, I am exploring ways to add a proper binding for plpgsql to upstream libpg_query. this is I think the simpler and more robust approach, since we are really just using the same parser that Postgres uses internally.

psteinroe avatar Jul 15 '25 06:07 psteinroe

in the next version, we will support plpgsql_check (#469). If you have that extension installed on your local database, we will use the extension to provide diagnostics in your IDE. I will be on vacation next week, and will release it right when I am back!

I kinda forgot about it when I wrote the previous comment, but it works remarkably well and should cover most needs already - without any custom parser!

psteinroe avatar Aug 01 '25 06:08 psteinroe

the new version with plpgsql_check is out now! looking forward to your feedback :)

psteinroe avatar Aug 20 '25 12:08 psteinroe