.sas
file in VS Code.files
, then click Files (19)
in the left menu.sas
or ${activeEditorLanguage}
into "Files: Default Language" box..txt
file instead of .sas
Open a .sas
file in VS Code.
ctrl + , to open settings UI.
Search workbench.settings
Change Settings: Editor to json
Close the editor
ctrl + , to open settings file in JSON.
Become surprized because I see so few settings to modify (I would have expected more settings in this file):
{
"editor.insertSpaces": false,
"editor.wordWrap": "on",
"workbench.settings.editor": "json"
}
Add lines to the file to try to dictate that new files should open with sas
syntax highlighting and with the .sas
extension, save and close:
{
"editor.insertSpaces": false,
"editor.wordWrap": "on",
"workbench.settings.editor": "json",
"files.associations": {
"*.sas": "sas"
},
"files.defaultLanguage": "SAS"
}
Press ctrl + n to open a new file.
Bang head on desk since the new file is still a .txt
file instead of .sas
When using ctrl + , to open the settings editor in json
, where are the rest of my settings including the default language settings?
I looked at this link, but the solution did not help.
I do not think it matters, but I am using the SAS-Syntax extension for my syntax highlighting.
Looking through the SAS language extension repository, the extension provides the following language in the package.json
"languages": [
{
"id": "SAS",
// the rest of the language entry
}
]
This means the language ID inside Code is indeed "SAS"
. Since the IDs are case-sensitive, using "sas"
will not work. You can also see the ID in parentheses when changing the language mode of a file:
That means your settings entry "files.defaultLanguage": "SAS"
is correct. I have tested it on a clean VS Code installation, and it worked as expected.
Also because of this, your file association will not work. When Code doesn't find the specified ID, it will fall back to plain text. You need to change your "files.associations"
settings to
"files.associations": {
"*.sas": "SAS"
}
File's language mode determines how Code handles syntax highlighting and code snippets.
Note that the language mode is not indicated by the icon displayed on the file's tab. The SAS extension doesn't support a custon icon and will use the icon of plain text files. The current language mode is displayed on the status bar in the bottom right:
You can manually select a language for a file with the "Change Language Mode" command, which is by default bound to the Ctrl + K, M shortcut.
The Code's settings.json
file is so small for you, because Code stores only the settings that are changed over the default ones. There is no default settings file, as the settings are hard-coded in the source code, but you can have Code generate the file for you.
Press Ctrl + Shift + P or F1 to open the Command Palette
Type in "default settings"
Select "Preferences: Open Default Settings (JSON)" from the list
Speaking of the Code's Command Palette, it is an incredibly powerful tool that I recommend looking into. You can use it to perform nearly any action in the editor just by searching for its name. For example, you can quickly open both the UI and JSON settings with the appropriate command.
To address the question in the comments, Code uses 3 levels of settings:
%AppData%\Code\User\settings.json
file (for other systems see the Code's documentation) and apply to all files and projects opened inside Code..vscode\settings.json
file and apply to all files when a workspace with the workspace settings file is opened.The settings are applied sequentially from default to workspace. If any key is set in multiple files, only the last one will take effect.
How would I specify the language for a specific projects instead of the entire workbench?
Create a .vscode\settings.json
file in the project's root and place your settings there. If you prefer to use the UI settings instead, you can select the "Workspace" tab to save your settings to the workspace settings file instead.
How would I open a similar file in a way to make changes?
Unfortunately, Code doesn't allow editing or saving the defaultSettings.json
file, so the only way to copy it is by copy-pasting the contents. Fortunately, that isn't needed - you can override any of the default settings in the user or workspace settings files.