「Visual Studio Code」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎外部ターミナル: 記事を追加)
53行目: 53行目:
 
"terminal.external.linuxExec": "gnome-terminal"
 
"terminal.external.linuxExec": "gnome-terminal"
 
}}
 
}}
  +
  +
=== Running natively under Wayland ===
  +
  +
If you are using a [[Wayland]]-based WM or DE, you can force Visual Studio Code to run natively under Wayland (instead of under XWayland) by adding command-line options {{ic|1=--enable-features=UseOzonePlatform --ozone-platform=wayland|2==}}. For example, you can try launching VSCode using
  +
  +
$ code --enable-features=UseOzonePlatform --ozone-platform=wayland
  +
  +
These options can be automatically applied every time Visual Studio Code is launched by adding them to the file {{ic|${XDG_CONFIG_HOME}/electron-flags.conf}}. (See [[Wayland#Electron]].)
  +
  +
== Troubleshooting ==
  +
  +
=== Global menu not working in KDE/Plasma ===
  +
  +
Visual Studio Code uses DBus to pass the menu to Plasma, try installing {{Pkg|libdbusmenu-glib}}.
  +
  +
=== Unable to move items to trash ===
  +
  +
By default, [https://electron.atom.io/ Electron] apps use {{ic|gio}} to delete files. {{ic|kioclient5}} is automatically selected instead if [[Plasma]] is detected. Different trash implementations can be used by setting the {{ic|ELECTRON_TRASH}} [[environment variable]].
  +
  +
For example, for deleting files using {{Pkg|trash-cli}}:
  +
  +
$ ELECTRON_TRASH=trash-cli code
  +
  +
At the time of writing, Electron supports {{ic|kioclient5}}, {{ic|kioclient}}, {{ic|trash-cli}}, {{ic|gio}} (default) and {{ic|gvfs-trash}} (deprecated). More info is available at this [https://github.com/electron/electron/blob/master/docs/api/environment-variables.md#electron_trash-linux documentation page].
  +
  +
=== Unable to debug C# ===
  +
  +
If you want to debug C#[[.NET_Core|.NET]] (using the [https://www.omnisharp.net 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 this github discussion].
  +
  +
When using the open-source package, debugging fails fairly quietly. The debug console will just show the initial message:
  +
  +
{{bc|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.}}
  +
  +
For debugging with the open-source package {{AUR|netcoredbg}} can be used. To run it in VS Code, add this configuration to .NET Core launch configuration of the project:
  +
  +
{{hc|./.vscode/launch.json|
  +
"configurations": [
  +
{
  +
...
  +
"pipeTransport": {
  +
"pipeCwd": "${workspaceFolder}",
  +
"pipeProgram": "/usr/bin/bash",
  +
"pipeArgs": ["-c"],
  +
"debuggerPath": "/usr/bin/netcoredbg"
  +
}
  +
...
  +
}}
  +
  +
=== Unable to open .csproj with OmniSharp server, invalid Microsoft.Common.props location ===
  +
  +
You have to switch from mono to proper SDK version props.
  +
  +
{{hc|/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props|
  +
$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props
  +
}}
  +
  +
Modify import to look like this:
  +
  +
{{hc|/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props|
  +
/opt/dotnet/sdk/{VERSION}/Current/Microsoft.Common.props
  +
}}
  +
  +
=== Error from OmniSharp that MSBuild cannot be located ===
  +
  +
It is noted in the [https://github.com/OmniSharp/omnisharp-roslyn#introduction OmniSharp introduction] that Arch Linux users should install the {{Pkg|mono-msbuild}} package. Without it, you might get an error like:
  +
  +
{{hc|1=OmniSharp Log|2=
  +
[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 {{Pkg|mono}} installed too).
  +
  +
Omnisharp ships with its own mono version, so, if it is unable to locate the installed one, if you want to tell omnisharp to look for a "global" mono installed in your machine, put this in your settings.json:
  +
{{hc|1=settings.json|2="omnisharp.useGlobalMono:"always"}}
  +
  +
=== Saving with "Retry as Sudo" does not work ===
  +
  +
This feature does not work in the {{Pkg|code}} package, because Microsoft does not support the way the Arch package is packaged (native instead of bundled Electron). See {{Bug|61516}} and the [https://github.com/Microsoft/vscode/issues/70403 upstream bug report] for more information.
  +
  +
The binary release {{AUR|visual-studio-code-bin}} does not have this issue, and the feature works there.
  +
  +
=== Keyboard variants or keymappings do not map ===
  +
  +
As per the [https://github.com/Microsoft/vscode/wiki/Keybinding-Issues#troubleshoot-linux-keybindings wiki on GitHub]:
  +
  +
: Switching keyboard layouts under some Linux window managers does not result in a change in the low level X window APIs VS Code uses to read the current keyboard layout. This means that VS Code ends up sometimes reading one of the other configured keyboard layouts and not the current active one. PR welcome...
  +
  +
Per the wiki, there are two possible solutions:
  +
  +
# make sure {{ic|setxkbmap -query}} returns as the first keyboard layout the one you want to work with in VS Code.
  +
# use {{ic|"keyboard.dispatch": "keyCode"}} in your settings and restart VS Code. This will prevent VS Code from trying to determine your keyboard layout whatsoever.
  +
  +
=== Command "..." not found ===
  +
  +
In the official build of VS Code, a {{ic|product.json}} file lists the extensions that are allowed to use certain proposed APIs accessed by extensions. However, the {{ic|product.json}} is absent in the OSS build {{Pkg|code}}. [https://docs.microsoft.com/en-us/visualstudio/liveshare/reference/linux#vs-code-oss-issues]
  +
  +
In the related issues below, some flags may be required to enable certain APIs. [https://github.com/Microsoft/vscode-pull-request-github/wiki#3-why-isnt-the-extension-starting] You may either run {{Pkg|code}} with these flags, or you can add the relevant entries to the {{ic|extensionAllowedProposedApi}} section in the {{ic|product.json}} file ({{Pkg|code}} installs this to {{ic|/usr/lib/code/product.json}}).
  +
  +
{{bc|"extensionAllowedProposedApi": [
  +
"ms-vsliveshare.vsliveshare",
  +
"ms-vscode.node-debug",
  +
"ms-vscode.node-debug2"
  +
]}}
  +
  +
This can also be resolved by installing the {{AUR|code-features}} package, which installs a pacman hook that patches the file on every package update. Alternatively, you may also consider installing the Microsoft branded packages: {{AUR|visual-studio-code-bin}}, {{AUR|visual-studio-code-insiders-bin}}.
  +
  +
==== VS Live Share missing API ====
  +
  +
Use either the solution above by editing the {{ic|product.json}}, or open VS Code with:
  +
  +
$ code --enable-proposed-api ms-vsliveshare.vsliveshare
  +
  +
==== Command 'remote-containers.openFolder' not found ====
  +
  +
Open VS Code enabling remote-containers API as commented in {{bug|63374}}:
  +
  +
$ code-oss --enable-proposed-api ms-vscode-remote.remote-containers
  +
  +
==== Command 'GitHub Pull Requests: Configure Remotes...' resulted in an error (command 'pr.configureRemotes' not found) ====
  +
  +
Open VS Code with:
  +
  +
$ code --enable-proposed-api GitHub.vscode-pull-request-github
  +
  +
=== Git: ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory ===
  +
  +
This error is a result of an encrypted ssh-key, and can be solved by installing a dialogue provider like [[SSH keys#x11-ssh-askpass]] or the alternatives listed there like {{Pkg|ksshaskpass}} for KDE.
  +
  +
One thing to note is that for e.g. ksshaskpass you would need to link it from {{ic|/usr/lib/ssh/ssh-askpass}} to get VSCode to find it:
  +
  +
# ln /usr/bin/ksshaskpass /usr/lib/ssh/ssh-askpass
  +
  +
=== No extensions found ===
  +
  +
There exist several differences between "vscode" (open-source) and "Visual Studio Code" (Microsoft product based on vscode), see: [https://github.com/microsoft/vscode/wiki/Differences-between-the-repository-and-Visual-Studio-Code Differences between the repository and Visual Studio Code]. The usage of [https://marketplace.visualstudio.com/vscode Microsoft marketplace] for extensions is restricted to products of the Visual Studio Code's family. Consequently, it cannot be used by vscode (see {{Bug|67780}}). The {{Pkg|code}} and {{AUR|vscodium-bin}}/{{AUR|vscodium}}/{{AUR|vscodium-git}} packages are configured to use [https://open-vsx.org/ the Open VSX registry] instead of the Microsoft one. This explains why some extensions are missing from the vscode explorer while they appear to be listed online.
  +
  +
The workaround is to either install the {{AUR|visual-studio-code-bin}} package instead, manually download and install the {{ic|.vsix}} file from the web marketplace page, or ask the maintainer to upload its extension to OpenVSX.
  +
  +
Technically, one could also edit the {{ic|product.json}} as shown in [https://github.com/VSCodium/vscodium/issues/418#issuecomment-643664182 this Github comment], but that would not comply with the Microsoft Marketplace Terms of Use. Additionally, the changes would be overwritten during package update. This can be overcome by installing {{AUR|code-marketplace}} package, which installs a pacman hook that patches the file on every package update.
  +
  +
=== Cutoff characters in integrated Terminal ===
  +
  +
Characters that are too wide can end up clipping. For example the italic bold text of Deno stack-traces.
  +
  +
This can be avoided by setting "terminal.integrated.rendererType" to "experimentalWebgl".
  +
  +
=== Blurry text under Wayland ===
  +
  +
Visual Studio Code defaults to run under XWayland, which may cause blurry text if you are using HiDPI screens. To fix this issue, try forcing Electron to run under Wayland—see [[#Running natively under Wayland]].
  +
  +
=== No such interface“org.freedesktop.Secret.Collection” ===
  +
  +
See [https://code.visualstudio.com/docs/editor/settings-sync#_troubleshooting-keychain-issues settings-sync#_troubleshooting-keychain-issues]
  +
  +
=== Authentification with Github failed while using VSCodium ===
  +
When connecting a Github account, change "vscodium" to "vscode" in the URL as seen in [https://github.com/VSCodium/vscodium/issues/401#issuecomment-631502370 this comment]. Then copy the identification token into VSCodium. Should it still fail, install a keyring like {{pkg|gnome-keyring}} or create a new keyring as mentioned here [https://code.visualstudio.com/docs/editor/settings-sync#_troubleshooting-keychain-issues in the Visual Studio Code docs] and here [https://github.com/microsoft/vscode/issues/92972#issuecomment-625751232 on Github].

2021年8月18日 (水) 12:23時点における版

Visual Studio Code は Microsoft によって開発されている、クロスプラットフォームのプロプライエタリテキストエディタ (End-User License Agreement に基づくライセンス) です。JavaScript と TypeScript で書かれた、Codium というフリーのオープンソースプロジェクト(MIT License に基づくライセンス)の上に構築されています。Codium と Visual Studio Code の関係は、Chromium と Google Chrome の関係とほぼ同じです。混合ライセンスの説明については、この GitHub コメントを参照してください。Visual Studio Code は Electron フレームワーク上に構築されており、エクステンションによる拡張ができます。拡張は web上 または テキストエディタの中 から参照できます。

インストール

VSCode には以下のパッケージが存在します:

  • code (オープンソースリリース)
  • code-gitAUR (オープンソース開発版)
  • visual-studio-code-binAUR (Microsoft ブランドのリリース)
  • visual-studio-code-insiders-binAUR (Microsoft ブランドのリリース、毎日更新)
  • vscodium-binAUR (コミュニティ主導の完全オープンソース版の VSCode、Microsoft テレメトリをすべて取り除いたもの - 最新リリース、バイナリパッケージ)
  • vscodiumAUR (コミュニティ主導の完全オープンソース版の VSCode、Microsoft テレメトリをすべて取り除いたもの - 最新リリース、git ビルド)
  • vscodium-gitAUR (コミュニティ主導の完全オープンソース版の VSCode、Microsoft テレメトリをすべて取り除いたもの - ブランチマスター の最新のコミット、git ビルド)

Microsoft の ptvsd (Python Tools for Visual Studio Debug) サーバー/モジュール は python-ptvsdAUR にあります。

C# のデバッグ

C# のコードをデバッグするには icu55AUR をインストールする必要があります。インストールしないと 'Debug adapter process has terminated unexpectedly' というエラーが発生します。

使用方法

code を実行してください。

何らかの理由で Visual Studio Code のインスタンスを複数起動したい場合、-n フラグを使ってください。

設定

Visual Studio Code の設定は ~/.config/Code/User/settings.json に保存されます。

統合ターミナル

View > Integrated TerminalCtrl + ` で統合されたターミナルが開きます。デフォルトでは、何も引数が指定されないと Bash が使われますが、使用されるシェルは変更できます。terminal.integrated.shell.linux は使用するデフォルトシェルを設定し、terminal.integrated.shellArgs.linux はシェルに渡される引数を設定します。

例:

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

外部ターミナル

Arch のデフォルトターミナルとして Terminator を使っている場合、Visual Studio Code で次のようなエラーが発生します: Unable to launch debugger worker process (vsdbg) through the terminal. spawn truecolor ENOENT。Visual Studio で使用するターミナルを別のターミナルに変更することで解決します (例: gnome-terminal)。

"terminal.external.linuxExec": "Yours alternative terminal" で実行・デバッグのときに使用するデフォルトのターミナルを設定します。

例:

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

Running natively under Wayland

If you are using a Wayland-based WM or DE, you can force Visual Studio Code to run natively under Wayland (instead of under XWayland) by adding command-line options <code=>--enable-features=UseOzonePlatform --ozone-platform=wayland. For example, you can try launching VSCode using

$ code --enable-features=UseOzonePlatform --ozone-platform=wayland

These options can be automatically applied every time Visual Studio Code is launched by adding them to the file ${XDG_CONFIG_HOME}/electron-flags.conf. (See Wayland#Electron.)

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 gio to delete files. kioclient5 is automatically selected instead if Plasma is detected. Different trash implementations can be used by setting the ELECTRON_TRASH environment variable.

For example, for deleting files using trash-cli:

$ ELECTRON_TRASH=trash-cli code

At the time of writing, Electron supports kioclient5, kioclient, trash-cli, gio (default) and gvfs-trash (deprecated). More info is available at this documentation 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 this github discussion.

When using the open-source package, debugging fails fairly quietly. The debug console will just show the initial message:

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.

For debugging with the open-source package netcoredbgAUR can be used. To run it in VS Code, add this configuration to .NET Core launch configuration of the project:

./.vscode/launch.json
"configurations": [
    {
...
    "pipeTransport": {
        "pipeCwd": "${workspaceFolder}",
        "pipeProgram": "/usr/bin/bash",
        "pipeArgs": ["-c"],
        "debuggerPath": "/usr/bin/netcoredbg"
    }
...

Unable to open .csproj with OmniSharp server, invalid Microsoft.Common.props location

You have to switch from mono to proper SDK version props.

/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props

Modify import to look like this:

/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
/opt/dotnet/sdk/{VERSION}/Current/Microsoft.Common.props

Error from OmniSharp that MSBuild cannot be located

It is noted in the OmniSharp introduction that Arch Linux users should install the mono-msbuild 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).

Omnisharp ships with its own mono version, so, if it is unable to locate the installed one, if you want to tell omnisharp to look for a "global" mono installed in your machine, put this in your settings.json:

settings.json
"omnisharp.useGlobalMono:"always"

Saving with "Retry as Sudo" does not work

This feature does not work in the code package, because Microsoft does not support the way the Arch package is packaged (native instead of bundled Electron). See FS#61516 and the upstream bug report for more information.

The binary release visual-studio-code-binAUR does not have this issue, and the feature works there.

Keyboard variants or keymappings do not map

As per the wiki on GitHub:

Switching keyboard layouts under some Linux window managers does not result in a change in the low level X window APIs VS Code uses to read the current keyboard layout. This means that VS Code ends up sometimes reading one of the other configured keyboard layouts and not the current active one. PR welcome...

Per the wiki, there are two possible solutions:

  1. make sure setxkbmap -query returns as the first keyboard layout the one you want to work with in VS Code.
  2. use "keyboard.dispatch": "keyCode" in your settings and restart VS Code. This will prevent VS Code from trying to determine your keyboard layout whatsoever.

Command "..." not found

In the official build of VS Code, a product.json file lists the extensions that are allowed to use certain proposed APIs accessed by extensions. However, the product.json is absent in the OSS build code. [1]

In the related issues below, some flags may be required to enable certain APIs. [2] You may either run code with these flags, or you can add the relevant entries to the extensionAllowedProposedApi section in the product.json file (code installs this to /usr/lib/code/product.json).

"extensionAllowedProposedApi": [
    "ms-vsliveshare.vsliveshare",
    "ms-vscode.node-debug",
    "ms-vscode.node-debug2"
]

This can also be resolved by installing the code-featuresAUR package, which installs a pacman hook that patches the file on every package update. Alternatively, you may also consider installing the Microsoft branded packages: visual-studio-code-binAUR, visual-studio-code-insiders-binAUR.

VS Live Share missing API

Use either the solution above by editing the product.json, or open VS Code with:

$ code --enable-proposed-api ms-vsliveshare.vsliveshare

Command 'remote-containers.openFolder' not found

Open VS Code enabling remote-containers API as commented in FS#63374:

$ code-oss --enable-proposed-api ms-vscode-remote.remote-containers

Command 'GitHub Pull Requests: Configure Remotes...' resulted in an error (command 'pr.configureRemotes' not found)

Open VS Code with:

$ code --enable-proposed-api GitHub.vscode-pull-request-github

Git: ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory

This error is a result of an encrypted ssh-key, and can be solved by installing a dialogue provider like SSH keys#x11-ssh-askpass or the alternatives listed there like ksshaskpass for KDE.

One thing to note is that for e.g. ksshaskpass you would need to link it from /usr/lib/ssh/ssh-askpass to get VSCode to find it:

# ln /usr/bin/ksshaskpass /usr/lib/ssh/ssh-askpass

No extensions found

There exist several differences between "vscode" (open-source) and "Visual Studio Code" (Microsoft product based on vscode), see: Differences between the repository and Visual Studio Code. The usage of Microsoft marketplace for extensions is restricted to products of the Visual Studio Code's family. Consequently, it cannot be used by vscode (see FS#67780). The code and vscodium-binAUR/vscodiumAUR/vscodium-gitAUR packages are configured to use the Open VSX registry instead of the Microsoft one. This explains why some extensions are missing from the vscode explorer while they appear to be listed online.

The workaround is to either install the visual-studio-code-binAUR package instead, manually download and install the .vsix file from the web marketplace page, or ask the maintainer to upload its extension to OpenVSX.

Technically, one could also edit the product.json as shown in this Github comment, but that would not comply with the Microsoft Marketplace Terms of Use. Additionally, the changes would be overwritten during package update. This can be overcome by installing code-marketplaceAUR package, which installs a pacman hook that patches the file on every package update.

Cutoff characters in integrated Terminal

Characters that are too wide can end up clipping. For example the italic bold text of Deno stack-traces.

This can be avoided by setting "terminal.integrated.rendererType" to "experimentalWebgl".

Blurry text under Wayland

Visual Studio Code defaults to run under XWayland, which may cause blurry text if you are using HiDPI screens. To fix this issue, try forcing Electron to run under Wayland—see #Running natively under Wayland.

No such interface“org.freedesktop.Secret.Collection”

See settings-sync#_troubleshooting-keychain-issues

Authentification with Github failed while using VSCodium

When connecting a Github account, change "vscodium" to "vscode" in the URL as seen in this comment. Then copy the identification token into VSCodium. Should it still fail, install a keyring like gnome-keyring or create a new keyring as mentioned here in the Visual Studio Code docs and here on Github.