gpt4 book ai didi

bash - 在 WSL Ubuntu 中使用 Chocolatey VS Code

转载 作者:行者123 更新时间:2023-12-04 18:43:25 30 4
gpt4 key购买 nike

我无法获取 VS 代码 code.exe在 WSL 中正常运行。 (我在这里找到了一个相关的问题,但它不能解决这个问题 - Launch VS Code from WSL Bash)。
在 WSL(任何发行版)中,我们可以访问 Windows 上的任何可执行文件。例如

alias chrome="\"/mnt/c/Program Files/Google/Chrome/Application/chrome.exe\""  # Open Chrome from WSL
alias notepad++="\"/mnt/c/Program Files/Notepad++/notepad++.exe\"" # Open Notepad++
打字 chrome在 bash 中将打开 Chrome 和 notepad++ ~/.bashrc将在 Notepad++ 中打开 .bashrc
这一切都很好。
但是,我遇到了 code.exe 的问题。由 choco inst VisualStudioCode 提供安装。当我尝试: alias vscode="\"/mnt/c/ProgramData/chocolatey/bin/code.exe\""这非常失败。
[main 2021-01-24T18:44:17.966Z] update#setState idle
(node:20404) Electron: Loading non-context-aware native module in renderer: '\\?\C:\tools\vscode\resources\app\node_modules.asar.unpacked\vscode-sqlite3\build\Release\sqlite.node'. This is deprecated, see https://github.com/electron/electron/issues/18397.
(node:20404) Electron: Loading non-context-aware native module in renderer: '\\?\C:\tools\vscode\resources\app\node_modules.asar.unpacked\spdlog\build\Release\spdlog.node'. This is deprecated, see https://github.com/electron/electron/issues/18397.
(node:18692) Electron: Loading non-context-aware native module in renderer: '\\?\C:\tools\vscode\resources\app\node_modules.asar.unpacked\spdlog\build\Release\spdlog.node'. This is deprecated, see https://github.com/electron/electron/issues/18397.
所以,我可以忽略它,直接使用 code.exe在 Ubuntu 中(因为 WSL 将扫描可执行文件的路径)。这种工作,但有以下错误:
'\\wsl$\Ubuntu-20.04\home\boss'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
VS Code 确实打开了,但如果将文件名作为参数,文件将无法打开(同时注意对于 notepad++ 示例,所有打开的文件都使用上述别名完美运行)。
似乎是在说 code.exe 不支持 UNC 路径,但它确实支持 UNC 路径,正如我从 PowerShell 中看到的那样。 code.exe \\HPEnvy\Drive-D\test.txt完美打开。
它真的会完善我的 WSL 设置,以便能够打开我正在使用 VS Code 无缝处理的代码。有谁知道为什么会发生这种情况/如何解决?

最佳答案

我的安装有一个用于在 ../Microsoft VS Code/bin/code 中启动 VSCode 的 shell 脚本。 .我相当肯定它是随 VSCode 一起安装的,但它有可能来自“Remote - WSL”扩展。
您的安装中是否存在这种情况?如果是这样,请添加 bin目录到您的路径(完整的安装程序会自动执行此操作)。然后只需使用 code而不是 code.exe从 WSL 中启动。
如果没有,首先确保在 VSCode 中安装了“Remote - WSL”扩展(或者更好的是,包含 WSL 支持的“Remote Development”扩展包)。如果在那之后它仍然不存在,这里是应该存在于 VSCode/bin/code 中的脚本内容:

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
set -x
fi

COMMIT="ea3859d4ba2f3e577a159bc91e3074c5d85c0523"
APP_NAME="code"
QUALITY="stable"
NAME="Code"
DATAFOLDER=".vscode"
VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"

IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
IN_WSL=true
else
WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
if [ -n "$WSL_BUILD" ]; then
if [ "$WSL_BUILD" -ge 17063 ]; then
# WSLPATH is available since WSL build 17046
# WSLENV is available since WSL build 17063
IN_WSL=true
else
# If running under older WSL, don't pass cli.js to Electron as
# environment vars cannot be transferred from WSL to Windows
# See: https://github.com/microsoft/BashOnWindows/issues/1363
# https://github.com/microsoft/BashOnWindows/issues/1494
"$ELECTRON" "$@"
exit $?
fi
fi
fi
if [ $IN_WSL = true ]; then

export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

# use the Remote WSL extension if installed
WSL_EXT_ID="ms-vscode-remote.remote-wsl"

ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt)

if [ -n "$WSL_EXT_WLOC" ]; then
# replace \r\n with \n in WSL_EXT_WLOC
WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$DATAFOLDER" "$@"
exit $?
fi

elif [ -x "$(command -v cygpath)" ]; then
CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
该文件的权限是 0777。而且,如上所述,它应该在您的路径中。

关于bash - 在 WSL Ubuntu 中使用 Chocolatey VS Code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65874775/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com