VSCode Extensions and Settings
This page explains how to leverage VSCode extensions and settings.
Installing Extensions
VSCode extensions add additional features to the editor. In the quickstart guide, we installed the VSCode Remote - Containers extension. Additional extensions will be instaleld automatically when the local contianer is built.
To specify which extensions are installed, you can add the extension id to the devcontainer.json
(as specified in the devcontain.json reference) under the propery "customizations": "vscode": "extensions"
. You can use the VSCode UI to find an extension's id. Moreover, extensions can be added to the devcontainer.json
file through the VSCode UI.
In addition, you can specify general VSCode settings under the propery "customizations": "vscode": "settings"
. In particular, you can specify extension settings.
Extension Locations
The final piece of information to be specified is where the extension will run; either in "ui" (i.e. the host machine) or "workspace"(inside the container). Not all extensions have the flexibility to run in both, and running in the "ui" reduces latency. However, if latency is not an issue and the extension supports it, then it's recommended to install the extension in "workspace" so that any binaries the extension requires are not installed in the host machine's default environment.
To specify a running location edit the property "remote.extensionKind"
as explained in the official documentation. A more detailed explanation is provided in VSCode API documentation.
Installing Binaries
In order for an extension to run, it may require the installation of additional packages. Separating out these packages from the packages needed to run the Data Science project itself, is one of the main reasons behind separating local development from dev and prod environments.
If additional python packages are required, then they must be added to the local requirements file. See the section on editing the requirements file for more information.
Changing Extension Settings
Rebuilding the Container After Changing devcontainer.json
You can add additional extension settings by creating and editing the file .vscode/settings.json
. This file is not git tracked.
Moreover, any changes to extension settings in the devcontainer.json
file are not enacted until the container is rebuilt.
Alternatively, one can install extensions on the local host and mount them on the container.
Note Jupyter always installed locally
As of September 2022, the Jupyter extension will always be installed when the python extension is. See this GitHub issue for further information. If you would like to uninstall jupyter after building the local container, run the command
code --uninstall-extension ms-toolsai.jupyter
Note, one cannot rely on using the Lifecycle Scripts to execute this command because these trigger before VSCode begins installing extensions.
Data Science Project Template Default Extensions
The Data Science Project Template main branch includes the id and settings for several extensions that are useful in the development of a Data Science application, though like most of the template this reflects personal taste and is not supposed to be prescriptive.
These extensions are:
- RunOnSave: The RunOnSave extension coordinates command line actions that are taken upon file save. Different commands are run depending on the file extension.
-
Python: The default python extension provided by Microsoft. The settings file uses mostly default values, with a few exceptions. The main configuration decisions are:
- pylance is the language server. Problems identified by pylance appear in the PROBLEMS tab in the VSCode UI.
- pylint and pydocstyle are enabled. Problems identified by these static code checkers appear in the PROBLEMS tab in the VSCode UI.
- autoDocstring is enabled and provides shortcuts to generate
google
style docstrings. - Upon save, both isort and black are run on all python files. Moreover notifications raised by pylance, pylint and pydocstyle are also refreshed.
- All code checkers will ignore unresolved imports. This is because heavyweight libraries should be installed in a dev and prod environments, the local environment should be as lightweight as possible.
- Telemetry is disabled.
- VSCode UI for unit testing are disabled. Tests can be run from the command line.
- Rulers are drawn at 79 and 99 characters as a visual guide to help stay within the pep8 recommended line length.
- Requirements files are automatically sorted.
-
SQLFluff: SQLFluff is run on every file with a sql extension upon file save. Note, that you must specify a dialect in the RunOnSave command.
-
VSCode: Several settings are also imposed on the VSCode editor. These can be overwritten directly in the
devcontainer.json
file, or by adding.vscode/settings.json
file to the local repository.- Quick suggestions are disabled.
- Popups for recommended extensions are disabled.
- The Cobalt2 theme is the default color theme.
-
Markdown Lint: Markdown files are automatically linted with an indent set to
4
by Markdown Lint. - TODO Tree:
TODO
statements are tracked and highlighted using TODO tree.
Links
- Settings for the VSCode python extension.
- Settings for the VSCode editor.