Visual Studio Code SQL Syntax Highlighting in .py Files

I am switching over from atom to VSCode and finding it to be a way better experience for (mostly) python.

One thing I can't seem to work out is that the python syntax highlighting on atom recognised SQL in strings and highlighted it.

I can't seem to find an extension for VSCode to do the same thing.

Does one exist or is there a way to get this highlighting in VSCode?


The best solution I found so far is this extension: https://github.com/ptweir/python-string-sql

It highlights multi quoted strings that start with --sql and end with ;, such as this one:

query = f"""--sql
SELECT * FROM mytable;
"""

Right now it doesn't support f-strings but there is (as of the time writing) an un-merged pull-request to fix it. So there may be f-string support soon.

Language Support in Visual Studio Code, MagicPython correctly highlights all Python 3 syntax features, or directly by adding "Python" to "ignored_packages" in the settings file). They should be no more difficult to read at a glance than other code or comments. Terminal Color and Style Highlighting for VS Code. This extension provides highlighting for terminal color escape sequences in the editor. The colors and styles can be customized via the configuration and light / dark theming is supported. The included preview feature can be used to view the source file like it would be shown in a terminal.


Unfortunately, this doesn't seem possible yet. But vote here: https://github.com/MagicStack/MagicPython/issues/27

MagicPython, Extension for Visual Studio Code - Highlight string as SQL, HTML, CSS or JS in most languages. 高亮内嵌的SQL 在代码中,高亮 SQL、HTML、CSS 或者 JavaScript 代码。 Documents The idea is for python and shell , but works for any language now. syntax-highlight-guide � language identifiers. I'm using Visual Studio Code for development of PHP and would like to style the background color of the different embedded languages HTML/PHP/JavaScript differently, and to trigger the use of hered


Similarly to @Rotareti's suggested extension, I am working on my own twist of it, that fits my personal needs. It activates sql highlighting when sees one of the three starting keywords in multiline string (multiline starting with """ or f"""). Highlighting is deactivated when multiline string ends. Only real limitation is that the keyword has to be in first line of string.

I have not published my package yet, but you can find it here: https://github.com/uogiukas/python-string-sql

Having --sql to start highlight just does not fit me since I have to go through a lot of other peoples' or my own old code where no such comment exists.

Highlight String Code, The extension makes VS Code an excellent Python editor, and works on any In the text editor: right-click anywhere in the editor and select Run Python File in� Any custom file extension can be associated with standard syntax highlighting with custom files association in User Settings as follows. Note that this will be a permanent setting. In order to set for the current session alone, type in the preferred language in Select Language Mode box (without changing file association settings)


Python in Visual Studio Code, in the settings, for example, when associating file extensions to a language: through the languages configuration point in the extension's package.json file: Python, python SCSS, scss (syntax using curly brackets), sass (indented syntax ) SQL, sql. Swift, swift. TypeScript, typescript. TypeScript React, typescriptreact. Connect to SQL databases, type T-SQL code, execute T-SQL code, view results, and save results as JSON or CSV files. While typing T-SQL code, you get rich T-SQL language features like T-SQL IntelliSense (code completion), syntax highlighting, linting, code navigation and code snippets.


Visual Studio Code language identifiers, SQL highlighting in Python multiline strings for VS Code. Adds syntax highlight support for python multiline SQL strings in VS Code. Install the mssql extension. The mssql extension for Visual Studio Code lets you connect to a SQL Server, query with Transact-SQL (T-SQL), and view the results.. In Visual Studio Code, select View > Command Palette, or press Ctrl+Shift+P, or press F1 to open the Command Palette.


python-string-sql, Environment data VS Code version: 1.33.1 Extension version (available Create or open a file with Python syntax; Type a string containing a� Python Django tutorial demonstrating IntelliSense, code navigation, and debugging for both code and templates in Visual Studio Code, the best Python IDE.