「Visual Studio Code」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) 細 (→設定: 空行を削除) |
Kusanaginoturugi (トーク | 投稿記録) (→Wayland でのネイティブ実行: ic テンプレートを修正) |
||
67行目: | 67行目: | ||
{{Accuracy|The flags in standard electron-flags.conf are ignored|section=Enabling wayland through electron-flags.conf}} |
{{Accuracy|The flags in standard electron-flags.conf are ignored|section=Enabling wayland through electron-flags.conf}} |
||
− | [[Wayland]] ベースの WM や DE を使用している場合、コマンドラインオプションに、{{ic|1=--enable-features=UseOzonePlatform --ozone-platform=wayland |
+ | [[Wayland]] ベースの WM や DE を使用している場合、コマンドラインオプションに、{{ic|1=--enable-features=UseOzonePlatform --ozone-platform=wayland}} を追加することで、Visual Studio Code を XWayland ではなく、Wayland でネイティブに実行させることができます。例えば、次のようにして、VSCode を起動してみてください。 |
$ code --enable-features=UseOzonePlatform --ozone-platform=wayland |
$ code --enable-features=UseOzonePlatform --ozone-platform=wayland |
2022年2月14日 (月) 13:09時点における版
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上 または テキストエディタの中 から参照できます。
目次
- 1 インストール
- 2 使用方法
- 3 設定
- 4 トラブルシューティング
- 4.1 KDE/Plasma でグローバルメニューが機能しない
- 4.2 Unable to move items to trash
- 4.3 Unable to debug C#
- 4.4 Unable to open .csproj with OmniSharp server, invalid Microsoft.Common.props location
- 4.5 Error from OmniSharp that MSBuild cannot be located
- 4.6 Saving with "Retry as Sudo" does not work
- 4.7 Keyboard variants or keymappings do not map
- 4.8 Command "..." not found
- 4.9 Git: ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
- 4.10 No extensions found
- 4.11 Cutoff characters in integrated Terminal
- 4.12 Blurry text under Wayland
- 4.13 No such interface“org.freedesktop.Secret.Collection”
- 4.14 Authentification with Github failed while using VSCodium
インストール
VSCode は以下のフレーバーが提供されています。
- Code - OSS — code-oss リポジトリからビルドされたオープンソースリリース 。
- Visual Studio Code — Microsoft ブランドのバイナリリリース。
- VSCodium — コミュニティ主導の MIT ランセンスのバイナリリリース。
- https://vscodium.com/ || vscodiumAUR, vscodium-binAUR, vscodium-gitAUR
"Code - OSS"(オープンソース)と "Visual Studio Code"(マイクロソフトのクローズドソースビルド)の違いについては、こちらをご覧ください。
機能拡張のサポート
機能拡張のための Microsoft marketplace の使用は、Visual Studio Code ファミリーの製品に制限されています。したがって、Code-OSS では使用できません。( FS#67780 を参照)
code と vscodium-binAUR/vscodiumAUR/vscodium-gitAUR パッケージは、Eclipse Foundation が保守する Open VSX レジストリを使用するよう設定されています。これは、Code-OSS が特定の拡張機能を見つけられないように見える理由を説明しています。
既知の回避策は次の通りです。
- manually install the extension from its
.vsix
file, which can be obtained from the Microsoft Visual Studio Code Marketplace; - ask the maintainer to upload its extension to the Open VSX registry;
- add the Microsoft Visual Studio Code Marketplace by using the one of the following packages relative to the build you are using: code-marketplaceAUR/vscodium-bin-marketplaceAUR/vscodium-marketplaceAUR. Those packages installs a Pacman hook that patches the file
product.json
as shown in this Github comment after every package update. Note that using the Microsoft Marketplace in this way would not comply with the its terms of use.
使用方法
code
を実行してください。
何らかの理由で Visual Studio Code のインスタンスを複数起動したい場合、-n
フラグを使ってください。
設定
code の設定は ~/.config/Code - OSS/User/settings.json
に保存されます。
visual-studio-code-binAUR の設定は ~/.config/Code/User/settings.json
に保存されます。
vscodiumAUR 及びその他 Codium の設定は ~/.config/VSCodium/User/settings.json
に保存されます。
Code から Codium (またはその逆) へ設定を移行する場合、設定ディレクトリはコピーまたは移動できます。殆どのコードベースを共有しているため設定には互換性があります。
統合ターミナル
View > Integrated Terminal
や Ctrl + `
で統合されたターミナルが開きます。デフォルトでは、何も引数が指定されないと 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"
Wayland でのネイティブ実行
Wayland ベースの WM や DE を使用している場合、コマンドラインオプションに、--enable-features=UseOzonePlatform --ozone-platform=wayland
を追加することで、Visual Studio Code を XWayland ではなく、Wayland でネイティブに実行させることができます。例えば、次のようにして、VSCode を起動してみてください。
$ code --enable-features=UseOzonePlatform --ozone-platform=wayland
これらのオプションは、${XDG_CONFIG_HOME}/electron-flags.conf
ファイルに追加することで、Visual Studio Code が起動するたびに自動的に適用されます。現在の vscode バイナリがビルドされている electron のバージョンによっては正確な electron バージョン用の別の設定ファイル (例: ${XDG_CONFIG_HOME}/electron13-flags.conf
) が必要になることがあります。(Wayland#Electron を参照)。
トラブルシューティング
KDE/Plasma でグローバルメニューが機能しない
Visual Studio Code は DBus を使用してメニューを Plasma に渡します。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:
- make sure
setxkbmap -query
returns as the first keyboard layout the one you want to work with in VS Code. - 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.
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.