diff --git a/CHANGELOG.md b/CHANGELOG.md index a183620..f497267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,57 +3,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog] (http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +### [1.2.0] - 2023-11-06 +- Added support for mysql by allowing a space after -- -## [1.0.0] - 2018-02-02 -### Added -- Syntax highlighting for html in es6 multiline strings - -## [1.1.0] - 2018-03-08 -### Fixed -- Compatibility with Prettier - -## [1.2.0] - 2018-03-12 -### Added -- Commands and keybindings +### [1.1.0] - 2019-06-04 +- Added support for f-strings -## [1.3.0] - 2018-03-17 -### Added -- Syntax highlight without a comment -- Follow semver - -### [1.4.0] - 2018-03-22 -### Added -- JS Syntax highlight -- Single-line comment support +### [1.0.0] - 2019-03-29 +- Added snippet and keybinding -### [1.5.0] - 2018-03-22 -### Fixed -- Compatibility with Prettier +### [0.1.0] - 2019-03-28 +- Published on VS Code marketplace -### [1.6.0] - 2018-08-13 +## [0.0.1] - 2018-03-28 ### Added -- SQL support. Beta - -### [1.7.0] - 2018-08-14 -### Fixed -- Improve html function support - -### [1.7.1] - 2018-08-15 -### Fixed -- Improve single-line comments support -- Disable hotkeys - -### [1.8.1] - 2018-08-18 -### Added -- Unquoted attributes support -### Fixed -- Js-in-attributes support - -### [1.8.2] - 2018-08-19 -### Fixed -- Fix missing `${}` syntax support in sql - -### [1.8.3] - 2018-08-25 -### Fixed -- Fix broken multiline support for jquery \ No newline at end of file +- First working version diff --git a/LICENSE b/LICENSE index 26cf3ae..31f06ad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Tobimori +Copyright (c) 2018 ptweir Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c82f33f..0cc04c1 100644 --- a/README.md +++ b/README.md @@ -1,95 +1,61 @@ -# ES6 String HTML -> [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html) +# SQL highlighting in Python multiline strings for VS Code -Adds syntax highlight support for code, placed in es6 multiline strings: -- HTML (incl. html quoted and unquoted attrs) -- SQL - -## Community -- [es6-string-css](https://github.com/bashmish/es6-string-css) - Highlight CSS in ES6 template literals +Adds syntax highlight support for python multiline SQL strings in VS Code. ## Installation -- Install `es6-string-html` from extensions (`ctrl + shift + x`) +Install `python-string-sql` from extensions (`ctrl + shift + x` or `cmd + shift + x` on mac). +> Also available on [marketplace.visualstudio.com](https://marketplace.visualstudio.com/items?itemName=ptweir.python-string-sql) ## Example -![Example](docs/demo.png) +[![Example](docs/demo.png)](docs/demo.py) ## Usage -Simply insert the comment /\*html\*/ or `html` (or sql instead of html) before the string -(see Requirements "section" for possible values) or select -`Insert es6-string-html comment/template` from the commands menu -(`ctrl+shift+p` or `f1`) +Insert `--sql`, `--beginsql`, or `--begin-sql` at the beginning of the part of the string you would like highlighted (with or without a space after --, e.g. `-- sql`) and a semicolon, `--endsql`, or `--end-sql` at the end of the highlighted section. -> Tip: Comment in the beginning of es6 string is required +### Snippets +begin typing `sql` and the autocomplete snippet will appear: -## Requirements +![Snippet](docs/snippet.gif) -- Visual Studio Code v1.19.0 recommended -- Comment `/*html*/` before the string. Possible values: -- - `/*html*/` -- - `/*inline-html*/` -- - `/*template*/` -- - `/*inline-template*/` -- Or -- - `html` before the string +### Keybindings -## Keybindings -- `ctrl+shift+h` - Insert `/*html*/` -- `ctrl+k h` - Insert `/*html*/` \`\` +cmd+s (or ctrl+s on mac) - Insert the following snippet: +``` +""" +--sql +SELECT +; +""" +``` -## Donation +## Requirements -If this project help you reduce time to develop, you can give me a cup of coffee :) +- Visual Studio Code v1.32.0 recommended +- Comments at beginning and end of highlighted section in the string (see Usage section). -[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=68P8BFSZPG5H2) +## Community +- 2018-09-04 forked from [es6-string-css](https://github.com/bashmish/es6-string-css) ## Release Notes -### [1.0.0] - 2018-02-02 -- Syntax highlighting for html in es6 multiline strings - -### [1.1.0] - 2018-03-08 -- Compatibility with Prettier - -### [1.2.0] - 2018-03-12 -- Commands and keybindings - -### [1.3.0] - 2018-03-17 -- Syntax highlight without a comment -- Follow semver - -### [1.4.0] - 2018-03-22 -- JS Syntax highlight -- Single-line comment support - -### [1.5.0] - 2018-03-22 -- Compatibility with Prettier - -### [1.6.0] - 2018-08-13 -- Add SQL support. Beta - -### [1.6.0] - 2018-08-13 -- Improve support for html function +### [1.2.0] - 2023-11-06 +- Added support for mysql by allowing a space after -- -### [1.7.0] - 2018-08-14 -- Improve html function support +### [1.1.0] - 2019-06-04 +- Added support for f-strings -### [1.7.1] - 2018-08-15 -- Improve single-line comments support -- Disable hotkeys +### [1.0.0] - 2019-03-29 +- Added snippet and keybinding -### [1.8.1] - 2018-08-18 -- Unquoted attributes support -- Fix js-in-attributes support +### [0.1.0] - 2019-03-28 +- Published on VS Code marketplace -### [1.8.2] - 2018-08-19 -- Fix missing `${}` syntax support in sql +### [0.0.1] - 2019-03-28 +- Got it working based on [these instructions](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide) -### [1.8.3] - 2018-08-25 -- Fix broken multiline support for jquery ------------------------------------------------------------------------------------------------------------ +### [0.0.0] - 2018-09-04 +- Forked from es6-string-html -**Enjoy!** diff --git a/docs/demo.png b/docs/demo.png index 522a407..8b7036d 100644 Binary files a/docs/demo.png and b/docs/demo.png differ diff --git a/docs/demo.py b/docs/demo.py new file mode 100644 index 0000000..2d38ec1 --- /dev/null +++ b/docs/demo.py @@ -0,0 +1,19 @@ +import psycopg2 + +conn = psycopg2.connect("dbname=test user=postgres") +cur = conn.cursor() + +query = """ +--begin-sql +SELECT last_name, + start_day, + COUNT(*) AS num_entries +FROM schema.table -- great name! +WHERE start_day >= '2019-01-01' +GROUP BY last_name, start_day +ORDER BY num_entries DESC +LIMIT 10; +""" + +cur.execute(query) +first_row = cur.fetchone() diff --git a/docs/logo.png b/docs/logo.png index a33e195..2744264 100644 Binary files a/docs/logo.png and b/docs/logo.png differ diff --git a/docs/python-string-sql-1.1.0.vsix b/docs/python-string-sql-1.1.0.vsix new file mode 100644 index 0000000..14a230d Binary files /dev/null and b/docs/python-string-sql-1.1.0.vsix differ diff --git a/docs/snippet.gif b/docs/snippet.gif new file mode 100644 index 0000000..502ddda Binary files /dev/null and b/docs/snippet.gif differ diff --git a/package-lock.json b/package-lock.json index 676b08a..31acf09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "es6-string-html", - "version": "1.5.0", + "name": "python-string-sql", + "version": "1.2.0", "lockfileVersion": 1 } diff --git a/package.json b/package.json index f00ec83..acdcf19 100644 --- a/package.json +++ b/package.json @@ -1,99 +1,62 @@ { - "name": "es6-string-html", - "displayName": "es6-string-html", - "description": "Syntax highlighting in es6 multiline strings", - "version": "1.8.3", - "publisher": "Tobermory", - "icon": "docs/logo.png", - "engines": { - "vscode": "^1.19.0" - }, - "galleryBanner": { - "color": "#dedede", - "theme": "light" - }, - "repository": { - "url": "https://github.com/mydesireiscoma/es6-string-html" - }, - "bugs": { - "url": "https://github.com/mydesireiscoma/es6-string-html/issues" - }, - "main": "./scripts/main", - "categories": [ - "Languages" - ], - "keywords": [ - "javascript", - "es6", - "es6-string-html", - "html", - "sql" - ], - "activationEvents": [ - "onCommand:es6stringhtml.insertComment", - "onCommand:es6stringhtml.insertTemplate" - ], - "contributes": { - "commands": [ - { - "command": "es6stringhtml.insertComment", - "title": "Insert es6-string-html comment", - "category": "HTML" - }, - { - "command": "es6stringhtml.insertTemplate", - "title": "Insert es6-string-html template", - "category": "HTML" - } + "name": "python-string-sql", + "displayName": "python-string-sql", + "description": "highlight python strings as sql", + "version": "1.2.0", + "publisher": "ptweir", + "icon": "docs/logo.png", + "repository": { + "url": "https://github.com/ptweir/python-string-sql" + }, + "engines": { + "vscode": "^1.32.0" + }, + "categories": [ + "Programming Languages", + "Snippets" ], - "grammars": [ - { - "injectTo": [ - "source.js", - "source.js.jsx", - "source.jsx", - "source.ts", - "source.tsx", - "source.sql", - "text.html.basic" + "contributes": { + "grammars": [ + { + "path": "./syntaxes/highlight-sql-string.json", + "scopeName": "python-sql.injection", + "injectTo": [ + "source.python", + "source.coconut" + ], + "embeddedLanguages": { + "meta.embedded.sql": "sql" + } + }, + { + "path": "./syntaxes/highlight-html-string.json", + "scopeName": "python-html.injection", + "injectTo": [ + "source.python", + "source.coconut" + ], + "embeddedLanguages": { + "meta.embedded.block.html": "html" + } + } ], - "scopeName": "inline.es6-js-injection", - "path": "./syntaxes/es6-js-injection.json", - "embeddedLanguages": { - "meta.template.expression.ts": "typescript", - "meta.template.expression.js": "javascript" - } - }, - { - "injectTo": [ - "source.js", - "source.js.jsx", - "source.jsx", - "source.ts", - "source.tsx", - "text.html.basic" + "snippets": [ + { + "language": "python", + "path": "./snippets/python.json" + } ], - "scopeName": "inline.es6-html", - "path": "./syntaxes/es6-inline-html.json", - "embeddedLanguages": { - "meta.embedded.block.html": "html" - } - }, - { - "injectTo": [ - "source.js", - "source.js.jsx", - "source.jsx", - "source.ts", - "source.tsx", - "source.sql" - ], - "scopeName": "inline.es6-sql", - "path": "./syntaxes/es6-inline-sql.json", - "embeddedLanguages": { - "meta.embedded.sql": "sql" - } - } - ] - } -} \ No newline at end of file + "keybindings": [ + { + "command": "editor.action.insertSnippet", + "key": "cmd+s", + "mac": "ctrl+s", + "when": "editorTextFocus", + "args": { + "langId": ["python", "coconut"], + "name": "SQL_highlighted_string" + } + } + ] + } +} diff --git a/scripts/main.js b/scripts/main.js deleted file mode 100644 index 302c5d5..0000000 --- a/scripts/main.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -var vscode = require('vscode') - -function activate(context) { - context.subscriptions.push( - vscode.commands.registerCommand("es6stringhtml.insertComment", () => insertString()), - vscode.commands.registerCommand("es6stringhtml.insertTemplate", () => insertString(true)), - ) -} - -function deactivate() { - // nothing to dispose -} - -/** - * Insert comment or comment with string in editor - * @param {boolean} full - */ -function insertString (full) { - const string = full ? '/*html*/ ``' : '/*html*/' - const editor = vscode.window.activeTextEditor - const selections = editor.selections - - editor.edit((editBuilder) => { - selections.forEach((selection) => { - editBuilder.replace(selection, '') - editBuilder.insert(selection.active, string) - }) - }) -} - -module.exports = { - activate: activate, - deactivate: deactivate -} diff --git a/snippets/python.json b/snippets/python.json new file mode 100644 index 0000000..8d3f04f --- /dev/null +++ b/snippets/python.json @@ -0,0 +1,13 @@ +{ + "SQL_highlighted_string": { + "prefix": "sql", + "body": [ + "\"\"\"", + "--sql", + "${1| ,SELECT,WITH|}", + ";", + "\"\"\"" + ], + "description": "SQL highlighted string" + } +} \ No newline at end of file diff --git a/syntaxes/es6-inline-html.json b/syntaxes/es6-inline-html.json deleted file mode 100644 index 8a18ffd..0000000 --- a/syntaxes/es6-inline-html.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], - "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.js.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string", - "injections": { - "L:source": { - "patterns": [ - { - "match": "<", - "name": "invalid.illegal.bad-angle-bracket.html" - } - ] - } - }, - "patterns": [ - { - "begin": "(.?(html|template))(`)", - "end": "(`)", - "beginCaptures": { - "1": { - "name": "variable.parameter" - } - }, - "patterns": [ - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "text.html.basic" - } - ] - }, - { - "begin": "(\\s?\\/?\\*?\\s?(html|template|inline-html|inline-template)\\s?\\*?\\/?\\s?)(`)", - "beginCaptures": { - "1": { - "name": "comment.block" - } - }, - "end": "(`)", - "patterns": [ - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "text.html.basic" - }, - { - "include": "inline.es6-htmlx#template" - } - ] - }, - { - "begin": "(?<=\\=|\\:|\\$\\()\\s+(\\/\\/\\s?(html|template|inline-html|inline-template)\\s?$)", - "beginCaptures": { - "1": { - "name": "comment.line" - } - }, - "end": "(`)", - "patterns": [ - { - "begin": "(\\G)", - "end": "(`)" - }, - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "text.html.basic" - } - ] - }, - { - "begin": "(\\${)", - "end": "(})", - "beginCaptures": { - "1": { - "name": "entity.name.tag" - } - }, - "endCaptures": { - "1": { - "name": "entity.name.tag" - } - }, - "patterns": [ - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "source.js" - } - ] - } - ], - "scopeName": "inline.es6-html" -} \ No newline at end of file diff --git a/syntaxes/es6-inline-sql.json b/syntaxes/es6-inline-sql.json deleted file mode 100644 index fe57dab..0000000 --- a/syntaxes/es6-inline-sql.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], - "injectionSelector": "L:source.js -comment -string, L:source.jsx -comment -string, L:source.js.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string", - "injections": { - "L:source": { - "patterns": [ - { - "match": "<", - "name": "invalid.illegal.bad-angle-bracket.html" - } - ] - } - }, - "patterns": [ - { - "begin": "(.?(sql))(`)", - "end": "(`)", - "beginCaptures": { - "1": { - "name": "variable.parameter" - } - }, - "patterns": [ - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "source.sql" - } - ] - }, - { - "begin": "(\\s?\\/?\\*?\\s?(sql|inline-sql)\\s?\\*?\\/?\\s?)(`)", - "beginCaptures": { - "1": { - "name": "comment.block" - } - }, - "end": "(`)", - "patterns": [ - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "source.sql" - } - ] - }, - { - "begin": "(?<=\\=|\\:|\\$\\()\\s+(\\/\\/\\s?(sql|inline-sql)\\s?$)", - "beginCaptures": { - "1": { - "name": "comment.line" - } - }, - "end": "(`)", - "patterns": [ - { - "begin": "(\\G)", - "end": "(`)" - }, - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "source.sql" - } - ] - }, - { - "begin": "(\"?'?\\${)", - "end": "(}\"?'?)", - "beginCaptures": { - "1": { - "name": "entity.name.tag" - } - }, - "endCaptures": { - "1": { - "name": "entity.name.tag" - } - }, - "patterns": [ - { - "include": "source.ts#template-substitution-element" - }, - { - "include": "source.js" - } - ] - } - ], - "scopeName": "inline.es6-sql" -} \ No newline at end of file diff --git a/syntaxes/es6-js-injection.json b/syntaxes/es6-js-injection.json deleted file mode 100644 index fac25dc..0000000 --- a/syntaxes/es6-js-injection.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "fileTypes": [ - "js", - "jsx", - "ts", - "tsx" - ], - "injectionSelector": "L:source.js (string.quoted.double.html, string.quoted.single.html), L:source.jsx (string.quoted.double.html, string.quoted.single.html), L:source.js.jsx (string.quoted.double.html, string.quoted.single.html), L:source.ts (string.quoted.double.html, string.quoted.single.html), L:source.tsx (string.quoted.double.html, string.quoted.single.html)", - "patterns": [ - { - "include": "source.ts#template-substitution-element" - } - ], - "scopeName": "inline.es6-js-injection" -} \ No newline at end of file diff --git a/syntaxes/highlight-html-string.json b/syntaxes/highlight-html-string.json new file mode 100644 index 0000000..aecaf03 --- /dev/null +++ b/syntaxes/highlight-html-string.json @@ -0,0 +1,60 @@ +{ + "fileTypes": [ + "py", + "coc", + "coco", + "coconut" + ], + "injectionSelector": "L:string.quoted.multi.python, L:meta.fstring.python - (comment.line.number-sign.python, punctuation.definition.comment.python)", + "repository": { + "keep-variables": { + "patterns": [ + { + "begin": "\\{", + "end": "\\}", + "beginCaptures": { + "1": { + "name": "punctuation.section.embedded.begin.py" + }, + "2": { + "name": "punctuation.section.embedded" + } + }, + "endCaptures": { + "1": { + "name": "punctuation.section.embedded.end.py" + }, + "2": { + "name": "punctuation.section.embedded" + } + }, + "patterns": [ + { + "include": "text.html.derivative" + } + ] + } + ] + } + }, + "patterns": [ + { + "begin": "( *--html| *--beginhtml| *--begin-html)", + "end": "( *--\\!html| *--endhtml| *--end-html)", + "captures": { + "1": { + "name": "variable.parameter" + } + }, + "patterns": [ + { + "include": "text.html.derivative" + }, + { + "include": "#keep-variables" + } + ] + } + ], + "scopeName": "python-html.injection" +} diff --git a/syntaxes/highlight-sql-string.json b/syntaxes/highlight-sql-string.json new file mode 100644 index 0000000..0ad1aab --- /dev/null +++ b/syntaxes/highlight-sql-string.json @@ -0,0 +1,26 @@ +{ + "fileTypes": [ + "py", + "coc", + "coco", + "coconut" + ], + "injectionSelector": "L:string.quoted.multi.python, L:meta.fstring.python - (comment.line.number-sign.python, punctuation.definition.comment.python)", + "patterns": [ + { + "begin": "( *--sql| *--beginsql| *--begin-sql| *-- sql| *-- beginsql| *-- begin-sql)", + "end": "( *;| *--endsql| *--end-sql| * ;| *-- endsql| *-- end-sql)", + "captures": { + "1": { + "name": "variable.parameter" + } + }, + "patterns": [ + { + "include": "source.sql" + } + ] + } + ], + "scopeName": "python-sql.injection" +}