Extension authoring · code.visualstudio.com

Update 1.57.1: The update addresses these issues.

The Workspace Trust feature addresses CVE-2021-34529.

Downloads: Windows: x64 Arm64 | Mac: Universal Intel silicon | Linux: deb rpm tarball Arm snap


Welcome to the May 2021 release of Visual Studio Code. There are a number of updates in this version that we hope you will like, some of the key highlights include:

If you'd like to read these release notes online, go to Updates on code.visualstudio.com.

Watch a highlight of the new features in this version in the VS Code team's release party. You can find the recording of the event on our YouTube channel.

Insiders: Want to try new features as soon as possible? You can download the nightly Insiders build and try the latest updates as soon as they are available.

Workbench

Workspace Trust

Visual Studio Code takes security seriously and wants to help you safely browse and edit code no matter the source or authors. The Workspace Trust feature lets you decide whether your project folders should allow or restrict automatic code execution.

Trust this folder dialog

Note: When in doubt, leave a folder in Restricted Mode. You can always enable trust later.

Safe code browsing

It's great that there is so much source code available on public repositories and file shares. No matter the coding task or problem, there is probably already a good solution available somewhere. However, using open-source code and tools does have risks and you can leave yourself open to malicious code execution and exploits.

Workspace Trust provides an extra layer of security when working with unfamiliar code by preventing automatic code execution when a workspace is open in Restricted Mode.

Note: If you want to disable the Workspace Trust feature, you can set security.workspace.trust.enabled to false. Only disable Workspace Trust if you are confident that you know the source and integrity of the files you are working with.

Restricted Mode

When prompted by the Workspace Trust dialog, if you choose No, I don't trust the authors, VS Code will go into Restricted Mode to prevent code execution. The workbench will display a banner at the top with links to Manage your folder via the Workspace Trust editor and Learn More taking you to the Workspace Trust user guide.

Workspace Trust Restricted Mode banner

You will also see a Restricted Mode badge in the Status bar.

Workspace Trust Restricted Mode Status bar badge

Restricted Mode tries to prevent automatic code execution by disabling or limiting the operation of several VS Code features: tasks, debugging, workspace settings, and extensions.

To see the full list of features disabled in Restricted Mode, you can open the Workspace Trust editor via the Manage link in the banner or by clicking the Restricted Mode badge in the Status bar.

Workspace Trust editor

Trusting a workspace

If you trust the authors and maintainers of a project, you can trust the project's folder on your local machine. For example, it is usually safe to trust repositories from well-known GitHub organizations such as github.com/microsoft or github.com/docker. The initial Workspace Trust prompt when you open a new folder allows you to trust that folder and its subfolders.

You can also bring up the Workspace Editor and quickly toggle a folder's trusted state. There are several ways to bring up the Workspace Editor dialog.

When in Restricted Mode:

  • Restricted Mode banner Manage link
  • Restricted Mode Status bar item

You can also at any time use:

  • Workspaces: Manage Workspace Trust command from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P))
  • Manage Workspace Trust from the Manage gear in the Activity bar

Manage Workspace Trust command in the Manage gear context menu

Selecting folders

When you trust a folder, it is added to the Trusted Folders & Workspaces list displayed in the Workspace Trust editor.

Workspace Trust editor Trusted Folders and Workspaces list

You can manually add, edit, and remove folders from this list and the active folder enabling trust is highlighted in bold.

You also have the option to trust the parent folder. This will apply trust to the parent folder and all subfolders. This can be helpful if you have many folders with trusted content collocated under one folder.

Enabling extensions

What happens if you want to use Restricted Mode but your favorite extension doesn't support Workspace Trust? This can happen if an extension, while useful and functional, isn't being actively maintained and hasn't declared their Workspace Trust support. To handle this scenario, you can override the extension's trust state with the extensions.supportUntrustedWorkspaces setting.

Note: Be careful overriding an extension's Workspace Trust support. It may be that the extension author has a good reason for disabling their extension in Restricted Mode.

Below you can see the user settings.json entry for the Prettier extension.

{
  "key": "cmd+w",
  "command": "workbench.action.closeWindow",
  "when": "!editorIsOpen && !multipleEditorGroups"
}

Windows/Linux

document.body.addEventListener('contextmenu', e => {
  e.preventDefault(); // cancel the built-in context menu
});

Editor

Suggestion preview

With the new setting editor.suggest.preview enabled, a preview of the selected suggestion or snippet is shown at the cursor position.

Suggestion preview showing smart completions for the letter 'i'

Theme: Dark+ (default dark)

Hide deprecated suggestions

There is a new setting editor.suggest.showDeprecated, which defaults to on, but when turned off, suggestions will not show items that are marked as deprecated.

Integrated Terminal

Terminal tabs

Terminal tabs were introduced as a preview feature in 1.56 and are now enabled by default. The new tabs view will only show by default when there are at least two terminals. For single terminals, the tab is "inlined" into the panel title. This also introduces the concept of terminal statuses such as whether a task is running, succeeded, or failed:

Single inlined terminal tab, terminal tabs with status, and collapsed terminal tabs

Below are some of the highlights in this release:

If you're not a fan of the new UX, you can go back to the dropdown by setting "terminal.integrated.tabs.enabled": false, the plan is to continue to support this as an option going forward.

Terminal profile improvements

The terminal profile system has many improvements in this release, here are some highlights:

  • defaultProfile will be respected if the terminal is restored upon launching VS Code and will be used for tasks and debugging.
  • Intellisense now works in settings.json for icon and defaultProfile.
  • overrideName now works for the default profile.
  • defaultProfile can now be set in workspace settings. This is also now controlled by the new Workspace Trust feature.
  • If defaultProfile and shell or shellArgs settings are used, you will now be asked to migrate the deprecated settings to the profiles system.
  • color can now be set on a profile.

Title sequence support

The setting terminal.integrated.experimentalUseTitleEvent setting has been promoted to stable as terminal.integrated.titleMode. By default, this setting will be executable, which names terminals based on the detected foreground process:

Running 'git show' will result in the terminal's title changing to 'git'

When this is set to sequence, the title will be based on what the shell sets it to. This needs shell support to work, an example of this in action is oh-my-zsh's default prompt, which shows additional information about the session:

The oh-my-zsh default prompt will show the computer's name and current working directory

Improved launching with clean environment

The setting terminal.integrated.inheritEnv has been available since the v1.36 but the implementation had some flaws where it could fail due to permissions issues on Linux and may not work as expected on macOS.

Due to improvements to how VS Code sets up its underlying environment, it's now possible to access the initial environment it was launched with, which is how most terminals work. When inheritEnv is set to true, VS Code will now use the initial environment and, when false, use the sourced "shell environment". This setting can help the terminal act more like a regular terminal. However, you may run into problems if your profile/rc configuration is not set up correctly.

Native line wrapping support on Windows

Line wrapping in the terminal drives task problem matchers and link detection. Historically, the Windows terminal has used a heuristic to flag lines as wrapped since the emulation technology that simulates a Unix pty didn't support wrapping. This changed on recent versions of Windows, and when updating to Windows 10 21376+ (currently Insiders only), this heuristic will be disabled and wrapped lines should work correctly as in Windows Terminal.

Tasks

Task status on terminal tab

The status of a task is now shown in its terminal tab. For background tasks, the status is only shown when there is an associated problem matcher.

Task status on a terminal tab

Automatically close task terminals

The task presentation property has a new close property. Setting close to true will cause the terminal to close when the task exits.

"editor.codeActionsOnSave": {
    "source.sortImports": true
}

Infer function return type Quick Fix

The Infer function return type refactoring for TypeScript adds explicit return type annotations to functions:

The Infer function return type refactoring in action

This is useful if you want to add more explicit typings. This refactoring can also save time when you want to extract the return type to a named type/interface, or if you need to modify a function's return type.

Prompt to disable TS Server logging

VS Code now prompts you if you have TypeScript server logging enabled for a prolonged period of time:

TS server logging enabled notification

Logging can significantly impact performance so it's best to keep it disabled unless you are actively trying to diagnose an issue.

Contributions to extensions

Remote Development

Work continues on the Remote Development extensions, which allow you to use a container, remote machine, or the Windows Subsystem for Linux (WSL) as a full-featured development environment.

Feature highlights in 1.57 include:

  • Control desired protocol for forwarded ports.
  • Optional watch for forwarded port collision.
  • Dev Containers supports Workspace Trust security feature.
  • Better environment variable detection in dev containers.

You can learn about new extension features and bug fixes in the Remote Development release notes.

Notebook API

We have finalized most of the notebooks API. The API is structured into three separate parts:

  1. The NotebookSerializer API that, in combination with the notebooks contribution point, enables VS Code to open, modify, and save notebook documents.
  2. Notebook renderers that present cell output. They are added via the notebookRenderer contribution point of your extensions package.json file.
  3. The NotebookController API to generate output for code cells.

Sample of a simple notebook serializer and an echo controller. The serializer uses JSON.parse and stringify with special handling for empty files. The controller returns the upper-case variant of the cell text - once as plain text and once as html.

"contributes": {
  "notebooks": [{
      "type": "echobook",
      "displayName": "Echobook",
      "selector": [{
        "filenamePattern": "*.echobook"
      }]
  }]
}

Status bar item 'id' and 'name' properties

We finalized the API for StatusBarItem identifier and name properties. The identifier can be passed from the new overload of the createStatusBarItem method while the name property can change dynamically on the StatusBarItem itself.

These new properties are used for the context menu on the Status bar to give individual entries a name and for allowing a user to show and hide entries. If you do not provide these properties, the menu will aggregate all status entries from one extension under a single entry.

Status bar item menu

If your extension contributes to the Status bar, consider updating to the new API.

Print a message in new terminals

When creating a terminal using window.createTerminal, it's now possible to set a message via TerminalOptions.message that is printed at the top of the terminal. This message supports ANSI escape sequences to enable text styles:

"typeAcquisition": {
  "include": [
    "@types/vscode-webview"
  ]
}

Or add a triple-slash reference in your code:

"engines": {
  "vscode": "^1.57.0",
}

If the extension targets VS Code 1.57+, then typed arrays should be recreated on the receiver side and the transfer of large typed arrays to and from webviews should be much more efficient.

parentSession on Debug Sessions

Some time ago, VS Code added support for hierarchical debug sessions, but no information about the hierarchy was exposed in the extension APIs. To address this, there is a new property on the DebugSession interface that references the parent session, if any. A session's parent will never change.

"engines": {
  "vscode": "^1.56.0-20210428",
}

Tree hovers support command URIs

When a TreeItem has a trusted Markdown tooltip, that tooltip can contain commands of the format [this is a link](command:workbench.action.quickOpenView). This follows the same format as all other places where command links are supported in Markdown.

Proposed extension APIs

Every milestone comes with new proposed APIs and extension authors can try them out. As always, we want your feedback. This is what you have to do to try out a proposed API:

  • You must use Insiders because proposed APIs change frequently.
  • You must have this line in the package.json file of your extension: "enableProposedApi": true.
  • Copy the latest version of the vscode.proposed.d.ts file into your project's source location.

You cannot publish an extension that uses a proposed API. There may be breaking changes in the next release and we never want to break existing extensions.

Testing

We intended to finalize the first parts of the testing APIs this iteration, but it was deferred due to the number of other in-flight features. While there were no breaking changes to the testing APIs this iteration, we continued to make progress on its editor experience. For example, the Peek view gained a split view that allows you to browse the results of current and past test runs.

Image of a Peek view with a references-style tree shown on the right side of a split view Theme: Codesong

Testing gained a new set of keybindings as chords starting with Ctrl+;, the Peek view now has better support for Markdown messages, and many bugs were fixed.

If you use the Test Explorer UI extension for tests, you can toggle on the setting testExplorer.useNativeTesting to switch to the new, native UI. In the next iteration, we plan to increase socialization of this setting and begin adoption with partner extension teams.

Terminal profile contributions

This API will enable extensions to contribute to the terminal profile system. An extension needs to do a few things to get this to work. First contribute the profile in the package.json:

"activationEvents": [
  "onTerminalProfile:my-ext.terminal-profile"
]

Lastly, register the provider in the activation event:

readonly iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;

Change title of Pseudoterminal

The new event Pseudoterminal.onDidChangeName enabled control of Pseudoterminal-based terminals:

const uri = await vscode.env.asExternalUri('file:///Users/john/work/code');

The resulting uri can be opened by the operating system and VS Code will open that workspace.

Engineering

Progress for Electron sandbox support

This milestone we continued to make the VS Code window ready for enabling Electron's sandbox and context isolation features.

Specifically:

  • We removed Node.js dependencies from more code that is used in the renderer.
  • We continued investigating dropping webview usage entirely and switching to iframe for our custom views and editors.

Documentation

VS Code at Build 2021

If you missed the Microsoft Build 2021 developer event, you can still watch the sessions on-demand. Check out the Visual Studio Code at Build 2021 blog post, where we've put together a list of sessions we think will be of interest to VS Code users.

What's New in VS Code Build 2021 session on YouTube

Browser debugging

A new topic Browser debugging in VS Code describes the built-in debugging support for the Edge and Chrome browsers. You can configure VS Code to either launch a new browser debugging session (via the Debug: Open Link command) or attach to a running browser.

PyTorch

There is a new topic on how to use the PyTorch machine learning framework within VS Code. In the PyTorch support in VS Code article, you'll learn how Jupyter Notebooks can be extended with PyTorch and TensorFlow data types.

PyTorch logo

Notable fixes

  • 71966: Often getting full window hangs
  • 85332: Windows: freeze on file delete
  • 95077: Terminal "word" link provider does not support wrapping
  • 108804: Do not wait for shell environment resolution before opening window
  • 120004: Weird letter spacing in Integrated Terminal for VS Code
  • 125035: Debug Console filter text should be preserved across reloads
  • iOS/iPadOS: Several fixes were made for the iOS/iPadOS platform

Thank you

Last but certainly not least, a big Thank You to the following people who contributed this month to VS Code:

Contributions to our issue tracking:

Contributions to vscode:

Contributions to vscode-css-languageservice:

Contributions to vscode-eslint:

Contributions to vscode-js-debug:

Contributions to vscode-languageserver-node:

Contributions to vscode-pull-request-github:

Contributions to vscode-vsce:

Contributions to language-server-protocol:

Contributions to monaco-languages:

Contributions to monaco-typescript:

Read the original on code.visualstudio.com ↗