VS code server使用
前言
發現了一個可以遠程debug代碼的神奇,VS code的在線版,code server https://github.com/cdr/code-server
遠程服務器上的代碼,通過在遠程服務器上建一個server,在本地用瀏覽器即可以用vs code寫代碼和debug。
install
參考 https://github.com/cdr/code-server/blob/master/doc/install.md即可, 非常簡單。
可以選用腳本來安裝,也可以用編譯好的deb包等。
例如,對於ubuntu:
curl -fOL https://github.com/cdr/code-server/releases/download/v3.4.1/code-server_3.4.1_amd64.deb
sudo dpkg -i code-server_3.4.1_amd64.deb
systemctl --user enable --now code-server
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
服務器上打開一個終端,運行
code-server
即出現
info Using config file ~/.config/code-server/config.yaml
info Using user-data-dir ~/.local/share/code-server
info code-server 3.4.1 48f7c2724827e526eeaa6c2c151c520f48a61259
info HTTP server listening on http://xx.xx.xx.xx:8889
info - Using password from ~/.config/code-server/config.yaml
info - To disable use `--auth none`
info - Not serving HTTPS
可以在配置文件~/.config/code-server/config.yaml
中修改對應的ip,端口,和訪問密碼。修改後重新運行code-server。
接下來在本地瀏覽器中打開http://xx.xx.xx.xx:8889
就可以進入vscode的在線版了。
python插件
在線版使用與離線版VS code幾乎一樣,就是有一個坑,裝python插件ms-python之後,想切換anaconda的環境,會報錯
Python:command 'python.setInterpreter' not found
想手動切換環境,也依然會報別的錯。
解決方案:
參考 https://github.com/Microsoft/vscode-python/issues/5440
Either install the previous version of the extension or do the following:
【I remove last extra comma from “C:\Users[username].vscode\extensions\ms-python.python-2019.4.11881\package.nls.[language].json.”
and restart vs code.】
vscode的extensions環境,linux與windows路徑不一樣。linux的路徑其實在運行code-server的時候就提示了,例如
info Using user-data-dir ~/.local/share/code-server
嘗試了第二種方法,去掉多餘的逗號,但是沒有效果。
後來裝了一箇舊版本的(越舊越好), 問題就解決了。
切換版本的方式如下,