Visual Studio Code

From ArchWiki
Jump to navigation Jump to search

Visual Studio Code is a cross-platform, free and open-source (licensed under the MIT License) text editor developed by Microsoft and written in JavaScript and TypeScript. It is built on the Electron framework and is extensible using extensions, which can be browsed on the web or from within the text editor itself. While the project is open-source, a proprietary build (licensed under an End-User License Agreement) is also provided by Microsoft. For an explanation of the mixed licensing, see this GitHub comment.

Installation

The following packages provide VSCode:

Usage

Run code to start the application (or code-git when using code-gitAUR).

If for any reason you wish to launch multiple instances of Visual Studio Code, the -n flag can be used.

Configuration

code stores settings in ~/.config/Code - OSS/User/settings.json.

visual-studio-code-binAUR stores settings in ~/.config/Code/User/settings.json.

Integrated Terminal

View > Integrated Terminal or Ctrl + ` opens up an integrated terminal. By default, Bash is used with no additional arguments, although this can be changed. terminal.integrated.shell.linux sets the default shell to be used and terminal.integrated.shellArgs.linux sets the arguments to be passed to the shell.

Example:

~/.config/Code/User/settings.json
"terminal.integrated.shell.linux": "/usr/bin/fish",
"terminal.integrated.shellArgs.linux": ["-l","-d 3"]

External Terminal

If you are using Terminator as default terminal for Arch and you have an error on Visual Studio Code: Unable to launch debugger worker process (vsdbg) through the terminal. spawn truecolor ENOENT, you can change the terminal that will be used by Visual Studio to another terminal (eg gnome-terminal).

"terminal.external.linuxExec": "Yours alternative terminal" sets the default terminal to be used for exec debug.

Example:

~/.config/Code/User/settings.json
"terminal.external.linuxExec": "gnome-terminal"

Troubleshooting

Global menu not working in KDE/Plasma

Visual Studio Code uses DBus to pass the menu to Plasma, try installing libdbusmenu-glib

Unable to move items to trash

By default, Electron apps use gvfs-trash to delete files. This command is deprecated and no longer exists, so the ELECTRON_TRASH environment variable must be used instead to specify which trash utility should be used.

For example, for deleting files under Plasma:

$ ELECTRON_TRASH=kioclient5 code

At the time of writing, Electron supports kioclient5, kioclient, trash-cli, gio and gvfs-trash (default). More info is available at this Github pull request page.

Unable to debug C#

If you want to debug C#.NET (using the OmniSharp extension) then you need to install the Microsoft branded release (from the AUR). This is apparently because the .NET Core debugger is only licensed to be used with official Microsoft products - see https://github.com/OmniSharp/omnisharp-vscode/issues/1431#issuecomment-297578930

Using the the open-source package, debugging fails fairly quietly. The debug console will just show the initial message and nothing more:

You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.

Error from OmniSharp that MSBuild cannot be located

It's noted in the OmniSharp introduction that Arch Linux users should install the msbuild-stableAUR package. Without it, you might get an error like:

OmniSharp Log
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin"
            MSBuildExtensionsPath = /usr/lib/mono/xbuild
            BypassFrameworkInstallChecks = true
            CscToolPath = ~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
            MSBuildToolsPath = ~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
System.TypeLoadException: Could not load type of field 'OmniSharp.MSBuild.ProjectManager:_queue' (13) due to: Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
...

You might be able to build anyway (possibly depending whether you have mono installed too)