Jump to content

Visual Studio Code: Difference between revisions

m
Fix typo.
imported>Yinfeng
m (→‎nix-ld: remove NIX_LD and NIX_LD_LIBRARY_PATH envronment variables, which will be set in the nixos module of nix-ld)
m (Fix typo.)
 
(8 intermediate revisions by 5 users not shown)
Line 37: Line 37:
Some examples here: [https://github.com/search?q=extensionFromVscodeMarketplace&type=code GitHub search for "extensionFromVscodeMarketplace"]
Some examples here: [https://github.com/search?q=extensionFromVscodeMarketplace&type=code GitHub search for "extensionFromVscodeMarketplace"]


{{ic|extensionsFromVscodeMarketplace}} is a manual way to fetch extensions. However, to keep updated from upstream, [https://github.com/nix-community/nix-vscode-extensions nix-community/nix-vscode-extensions] provides the Nix expressions for the majority of available extensions from Open VSX and VSCode Marketplace. A GitHub Action updates the extensions daily.
Note: For fetching the sha256 string you can use the following command. Make sure to replace the author, the package name and version!<syntaxhighlight lang="bash">
nix-prefetch-url https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-vscode-remote/vsextensions/remote-ssh-edit/0.47.2/vspackage
</syntaxhighlight>{{ic|extensionsFromVscodeMarketplace}} is a manual way to fetch extensions. However, to keep updated from upstream, [https://github.com/nix-community/nix-vscode-extensions nix-community/nix-vscode-extensions] provides the Nix expressions for the majority of available extensions from Open VSX and VSCode Marketplace. A GitHub Action updates the extensions daily.


It's also possible to install VS Code via [[Home Manager]]:
It's also possible to install VS Code via [[Home Manager]]:
Line 147: Line 149:


Take the output from this command and input it where your placeholder was.
Take the output from this command and input it where your placeholder was.
== Creating development environments using nix-shell ==
Instead of using configuration.nix to add packages (e.g. Python or NodeJS) for developing code on VSCode, you can instead use nix-shell. This will allow you to seamlessly create development environments with the correct packages for your project, without rebuilding and restarting NixOS. See [[Development_environment_with_nix-shell | this page]] for further instructions in building nix-shell development environments.
=== Automatically switch nix shells when switching projects ===
You can do this by using [https://github.com/nix-community/nix-direnv nix-direnv] and [https://marketplace.visualstudio.com/items?itemName=mkhl.direnv the VSCode extension direnv] for integration. View the nix-direnv github page linked for a guide on setting it up.
=== Alternative for manually switching shells ===
The extension [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector nix-env-selector] will make switching between different nix-shell environments within VSCode so you can switch between different coding projects easily and manually. It has a guide for setting up nix-shell environments for VSCode.


== Wayland ==
== Wayland ==
Line 238: Line 249:




As a workaround, search for the following text in all files under the directory <code>$HOME\.vscode\extension\</code>
As a workaround, search for the following text in all files under the directory <code>$HOME\.vscode\extensions\</code>


{{file|wslDaemon.js|js|<nowiki>
{{file|wslDaemon.js|js|<nowiki>
[e,"-e",`const net = require('net');
.push("sh","-c"
</nowiki>}}
</nowiki>}}


Line 248: Line 259:


{{file|wslDaemon.js|js|<nowiki>
{{file|wslDaemon.js|js|<nowiki>
["sh","-l","-c","exec \"$0\" \"$@\"",e,"-e",`const net = require('net');
.push("sh","-l","-c"
</nowiki>}}
</nowiki>}}


Line 255: Line 266:
See https://github.com/nix-community/NixOS-WSL/issues/222 for the discussion about <code>wsl --exec</code> issue on NixOS-WSL.
See https://github.com/nix-community/NixOS-WSL/issues/222 for the discussion about <code>wsl --exec</code> issue on NixOS-WSL.
See https://github.com/microsoft/vscode-remote-release/issues/8305#issuecomment-1661396267 about the workaround.
See https://github.com/microsoft/vscode-remote-release/issues/8305#issuecomment-1661396267 about the workaround.
== Using nix-shell ==
Some features of VS Code, like the Python package, require linters or other dependencies. The package [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector nix-env-selector] makes this easy and does not require overrides on VS Code itself to add dependencies.


== Troubleshooting ==
== Troubleshooting ==
Line 321: Line 329:
fi
fi
</syntaxHighlight>
</syntaxHighlight>
[[Category:Applications]]
1

edit