plmustache icon indicating copy to clipboard operation
plmustache copied to clipboard

Syntax highlighting doesn't work when storing mustache files in function definitions

Open steve-chavez opened this issue 2 years ago • 3 comments

Problem

As it can be seen on https://github.com/PostgREST/plmustache?tab=readme-ov-file#sections, regular syntax highlighting for mustache files doesn't work.

Solution

Add a psql command that can obtain the function body from another file.

\create_function from ./templates/hello.mustache hello(arg text) returns int LANGUAGE plmustache

I've submitted this on https://www.postgresql.org/message-id/CAGRrpzZnoWY-kK_0qK-OY%3D-e0eDqhc5kdFSkuxN0mxe9iuiz0Q%40mail.gmail.com

It can also be tried on this branch https://github.com/steve-chavez/postgresql/tree/cf with:

$ nix-shell
$ pg-build && with-pg psql

\create_function from ./src/pl/plpython/data/max.py public.max(a int, b int) returns int language plpython3u

select max(3, 4);

Alternatives

  • A special syntax highlighter for postgres functions with different langs in VIM? This would have to be done for various editors/IDEs though.
  • Another executable besides psql that deploys the functions based on mustache files.

steve-chavez avatar Jan 26 '24 18:01 steve-chavez

Really nice that this already sparked some discussion! Looks like the final interface will be like this though:

\file_read fbody source_file.txt
CREATE FUNCTION foo() RETURNS whatever AS :'fbody' LANGUAGE ...;

@wolfgangwalther You mentioned you follow the mailing list daily. I was wondering, what's the protocol on implementing a feature? Should I just jump in with a new patch? Not sure if I should leave that to Tom Lane since he proposed it.

steve-chavez avatar Jan 26 '24 21:01 steve-chavez

You mentioned you follow the mailing list daily. I was wondering, what's the protocol on implementing a feature? Should I just jump in with a new patch? Not sure if I should leave that to Tom Lane since he proposed it.

I don't expect him to work on this. If so, he would likely have said that.

I guess you could just write a patch for the above, yes.

wolfgangwalther avatar Jan 26 '24 21:01 wolfgangwalther

Note that this already works as:

\set tpl `cat tpl.mustache`
create function tpl() returns text as :'tpl' language plmustache;

On the pg patch we're working on a native way that's not dependent on the shell.

steve-chavez avatar Jan 30 '24 00:01 steve-chavez