atom / language-sql

SQL package for Atom
Other
38 stars 50 forks source link

Add ability to highlight SQL within a template literal #62

Closed gajus closed 7 years ago

gajus commented 7 years ago

Description

SQL code within template literals appears without SQL syntax highlighting.

screen shot 2017-04-15 at 11 00 12

It would be nice to be able to utilize language-sql syntax highlighting for arbitrary text string within a code base.

A SQL string can be differentiated from other text by using a convention comment, e.g.

-- syntax-sql
SELECT
  id
FROM
  event
WHERE
  id IN ? AND
  -- Do not update seat information for event that has past or is due
  -- to start in less than 2 minutes.
  starts_at > + INTERVAL '2 MINUTE' AND
  -- Used to throttle seat request to at most once a minute.
  (
    seat_asked_at IS NULL OR
    seat_asked_at < NOW() - INTERVAL '1 MINUTE'
  )
FOR UPDATE

where syntax-sql triggers the syntax highlighting.

gajus commented 7 years ago

Turns out this is already possible using babel-language package, https://github.com/gandm/language-babel#javascript-tagged-template-literal-grammar-extensions.