4

Currently, I name my files as .py while working on them, and then change them to .sage when I need to execute. Is there a way to get the python colour scheme for sage files on VS code?

There is an extension called SAGE enterprise management that claims to do it, but the instructions are a bit unclear:

It says:

Create a x3-code named folder inside your ~/.vscode/extensions/; Copy all files in yours recent created folder; Reload VS Code and enjoy;

I tried both copying my sage files into the folder, and the contents of the x3-extension into the folder, both of which didn't work.

Mahathi Vempati
  • 1,238
  • 1
  • 12
  • 33

2 Answers2

3

The instructions referred to in the question are for Sage the accounting software, not for SageMath the Sage mathematics software system.

In the case of SageMath, we need to tell VS Code to apply Python formatting not only to files ending in .py, but also to files ending in .sage. One way to do that is to use the "file to language association" setting:

One would add associations from "*.sage" to "python".

This related question has answers explaining where Visual Studio Code's language extension files are located on macOS and Windows:

Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
  • I think it should be noted that this is done in `settings.json`. For me, on Windows 10, the file was located at `C:\Users\\AppData\Roaming\Code\User`. If using the settings window inside the editor instead (as in @qwyster's answer) - drop the quotation marks. – et_l Feb 09 '21 at 10:17
3

Following the first link provided in the prior answer, I got it worked. In details, go to Settings, type "files.associations" in the search box for Search settings.

It shows you a list of (item, value) in which you can add a new item (*.sage, python). See my screenshot below

enter image description here

Hope it works for you!

nam_ngn
  • 79
  • 4