cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Cells highlighter for VS Code?

Dimitry
Valued Contributor

Hi all

I've recently had to switch to VS Code to run some Claude coding over my notebooks and python libraries.

I stumbled on highlighting cells for notebooks with SQL injection. It seems to be nowhere documented how to fix.

I use Databricks issued "IDE support for Databricks" extension, which back in 2023 was named "Databricks for Visual Studio Code" - https://www.databricks.com/blog/2023/02/14/announcing-a-native-visual-studio-code-experience-for-dat...

Unfortunately Databricks changed file format from .py to .ipynb and had not updated extension, neither provided any searchable documentation, on how to get VS code to work with the new notebook format, when it comes to SQL parts of it. I can get neither spark.sql() nor %sql cells to highlight correctly (the first is displayed as plain text, the second if treated as broken python code).

Although it is not critical, but it is annoying.
Did anyone solve it with their VS code?   

1 ACCEPTED SOLUTION

Accepted Solutions

Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @Dimitry,

From the public docs, this looks more like a limitation of the current VS Code experience.

As you stated, Databricks now defaults notebooks to .ipynb format. However, you can still switch or convert notebooks between Jupyter (.ipynb) and source format if that better fits your workflow (Manage notebook format).

On the VS Code side, Databricks does support running and debugging .ipynb notebooks cell by cell with Databricks Connect, and %sql is supported in the sense that it executes via spark.sql (Run and debug notebook cells with Databricks Connect).

That said, the main extension docs also explicitly say that while the extension supports running R, Scala, and SQL notebooks as jobs, it does not provide deeper support for those languages within VS Code (Databricks extension for Visual Studio Code).

So based on that, I would not expect proper SQL-aware highlighting for %sql cells in Databricks .ipynb notebooks.I did come across references to third-party VS Code extensions, such as python-string-sql, that aim to highlight SQL within Python strings, which may help a bit with spark.sql(...) readability. That said, I would treat those as optional workarounds rather than the main answer here, and they are not a fix for %sql notebook cells.

If the goal is better SQL authoring in VS Code, the public Databricks path is to use SQLTools + the Databricks driver for SQL-centric work rather than relying on the main Databricks extension for SQL editing (Run SQL Queries on Databricks From Visual Studio Code).

Hope this helps.

If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.

 

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***

View solution in original post

1 REPLY 1

Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @Dimitry,

From the public docs, this looks more like a limitation of the current VS Code experience.

As you stated, Databricks now defaults notebooks to .ipynb format. However, you can still switch or convert notebooks between Jupyter (.ipynb) and source format if that better fits your workflow (Manage notebook format).

On the VS Code side, Databricks does support running and debugging .ipynb notebooks cell by cell with Databricks Connect, and %sql is supported in the sense that it executes via spark.sql (Run and debug notebook cells with Databricks Connect).

That said, the main extension docs also explicitly say that while the extension supports running R, Scala, and SQL notebooks as jobs, it does not provide deeper support for those languages within VS Code (Databricks extension for Visual Studio Code).

So based on that, I would not expect proper SQL-aware highlighting for %sql cells in Databricks .ipynb notebooks.I did come across references to third-party VS Code extensions, such as python-string-sql, that aim to highlight SQL within Python strings, which may help a bit with spark.sql(...) readability. That said, I would treat those as optional workarounds rather than the main answer here, and they are not a fix for %sql notebook cells.

If the goal is better SQL authoring in VS Code, the public Databricks path is to use SQLTools + the Databricks driver for SQL-centric work rather than relying on the main Databricks extension for SQL editing (Run SQL Queries on Databricks From Visual Studio Code).

Hope this helps.

If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.

 

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***