Setup language injection into tagged es6 template strings

ES6 brings us new feature called template strings, which can be tagged (actually processed with a function). This feature is very useful to wrap SQL:

 

```

import {SQL} from "sql-template-strings"

pg.query(SQL`SELECT * FROM public.user`).

```

This is very useful feature to use with language injection. Unfortunately, there is no any example how to do that. I can inject language manually to each usage, but I want to global setup: inject SQL into any es6 template string, started with `SQL`.

How can I do that?

0

You can try the following places pattern (Settings | Editor | Language Injections, Add, Generic JS):

+ jsLiteralExpression().withText(string().matchesBrics("SQL`.+`"))
0

I've tried this, but it is not working. Does this setting applies to typescript too?

 

0

Yes, it does work for me in .ts files as well (checked in 2016.3.3)

For tagged templates support, please vote for https://youtrack.jetbrains.com/issue/WEB-22106

0

In newer versions of WebStorm, use the simpler places pattern:

    + taggedString("SQL")

See https://youtrack.jetbrains.com/issue/WEB-22106#focus=streamItem-27-2451611.0-0

2

请先登录再写评论。