postgres-language-server
postgres-language-server copied to clipboard
Parse function bodies and sql strings
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
SourceFileParsertoSourceParser, andpub fn parse_source_file(&mut self, text: &str)topub 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.