supabase-community/postgres_lsp

Parse function bodies and sql strings

Opened this issue · 0 comments

Postgres parses sql strings such as execute 'select 1'; and function bodies, e.g.

CREATE FUNCTION dup(in int, out f1 int, out f2 text)
    AS $$ SELECT $1, CAST($1 AS text) || ' is text' $$
    LANGUAGE SQL;

as string constants. To improve dx, especially for function bodies, we should pass the string back into the SourceParser.

A few things to consider here:

  • refactor SourceFileParser to SourceParser, and pub fn parse_source_file(&mut self, text: &str) to pub fn parse_source(&mut self, text &str, at_offset: Option<i32>), similar to how the statement parser is designed (done)
  • we have to find a way to make a distinction between a sql string, and a normal string. I would propose to just parse any string constant, and if does not return an error use replace it with the sub-tree.