Coder Social home page Coder Social logo

toolbox-vscode's Introduction

Toolbox Visual Studio Code integration

This repository is intended for scripts and hooks to integrate Toolbox with Visual Studio Code.

In particular, it provides a code.sh script that:

  • If necessary, prompts to install the Flatpak of Visual Studio Code
  • If necessary, configures the current toolbox container to work with the Remote Containers Visual Studio Code extension.
  • Opens a VSCode window using the remaining command line arguments

Installation

git clone https://github.com/owtaylor/toolbox-vscode.git
cd toolbox-vscode
[ -d ~/.local/bin ] || mkdir ~/.local/bin
ln -s "$PWD/code.sh" ~/.local/bin/code

Usage

toolbox enter
cd ~/Source/myproject
code .

To recreate the container configuration (perhaps after updating this repository)

code --toolbox-reset-configuration .

Credits

The configuration that code.sh sets up was largely figured out by Laércio de Sousa (lbssousa)

Related issues

toolbox-vscode's People

Contributors

lbssousa avatar maxdevjs avatar owtaylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toolbox-vscode's Issues

When starting code recently after closing : error exec: code not found

Thanks for taking the time to thoroughly make Code in Toolbox a pleasant experience. I've had no problems with the script other than this one:

If I start code after closing it (which I sometimes do to reset an LSP, or I installed an extension that requires restart)

I get this :

/var/home/me/my-project-dir: line 3: exec: code: not found

If I wait 60 or so seconds, not sure on the exact time, then it works just fine.
I haven't been able to trace the line of code that originates the error, it seems to come from nowhere :)
I wonder if this is related to : flathub/com.visualstudio.code#210
Where the script is finding the previous IPC channel that hasn't yet closed. After the channel is cleaned up, then the script launches "from scratch" again. Just a guess.

Package this as an rpm

I've just been trying this out on Silverblue 34. Happily enough it works, which means VS Code is actually viable in the Toolbox workflow :)

Would you be able to package it into an rpm and distribute it? That way we'd only need to do rpm-ostree install <thing> to get it. This would be an easier sell to people thinking of moving to Silverblue.

Dynamic dockerPath?

Hello and thanks for this project!

Right now, remote.containers.dockerPath is replaced directly in the settings.json. However, I would like to use the Docker of my system in order to do some development inside containers (podman have some incompatibilities). It is possible to use podman-host just for the current session and then restore old values? Or I had to manually change each time?

Btw: using grep and sed could make some problems (like, if I have duplicated that string and commented it would not detect it propery). Maybe switching to jq would make sure detection of the configuration is properly done.

Br,
Valentin

Shell server terminated due to syntax error after running 'code .'

About My Setup

I'm running Ubuntu 22.04. Since toolbox isn't packaged for Ubuntu, I manually compiled it using the instructions here. Toolbox seems to be working correctly; I created a Fedora 34 container, updated it, and even ran Firefox inside of it.

What I did

  1. I compiled toolbox for my system using the instructions and rebooted my system
  2. I created a Fedora 34 toolbox and updated it
  3. I followed toolbox-vscode's install instructions, git cloned the repository into ~/.local/share and ran the other commands
  4. Went to my program's directory and ran code .
  5. Was prompted to install VSCodium, installed it, installed Remote Container Extension
  6. Tried rebooting to see if that solved the issue

Result

Image of VSCode and Error

[34 ms] Remote-Containers 0.234.0 in VS Code 1.67.0 (57fd6d0195bb9b9d1b49f6da5db789060795de47).
[34 ms] Start: Resolving Remote
[35 ms] Setting up container: fedora-toolbox-34
[39 ms] Start: Run: /home/evan/.local/bin/podman-host inspect --type container fedora-toolbox-34
[164 ms] Start: Check Docker is running
[164 ms] Start: Run: /home/evan/.local/bin/podman-host version --format {{.Server.APIVersion}}
[287 ms] Server API version: 3.4.4
[288 ms] Start: Inspecting container
[288 ms] Start: Run: /home/evan/.local/bin/podman-host inspect --type container 223bedeca7beef658f3421bf189bed7c2d5f9af725bcd40e3870ee8d6273f3c1
[411 ms] Start: Run in container: /bin/sh
[413 ms] Start: Run in container: uname -m
[420 ms] Start: Run in container: cat /etc/passwd
[420 ms] Stdin closed!
[422 ms] Shell server terminated (code: 2, signal: null)

-: 2: Syntax error: "(" unexpected

Possible causes

  • I get a "F: Filesystem suffix "create" is not applicable for --nofilesystem" message after running 'code .'
  • After installing locate using DNF, I saw a message that says "System has not been booted with systemd as init system (PID 1). Can't operate.... Failed to connect to bus: Host is down"

Search among workspace files doesn't work

Fedora 38
VScode 1.76.2 (Flatpack)

Not sure where to dig but while opening my project with the dev container I can't search among the project files.

image

Does anyone else having this issue?

Tasks with -c in args get mangled (was: deprecated parameters in settings.json)

  • terminal.integrated.shell.linux
  • terminal.integrated.shellArgs.linux

https://github.com/owtaylor/toolbox-vscode/blob/main/code.sh#L371-L381

Screenshot from 2021-10-22 21-53-46

Also, these parameters causing errors for some tasks.
Example:

> Executing task: func host start <

func host start: No such file or directory
The terminal process "/usr/sbin/capsh '--caps=', '--', '-c', 'exec "$@"', '/bin/sh', '/usr/bin/fish', '-l', 'func host start'" failed to launch (exit code: 127).

not opening folder when exec in dot directory

When code . is executed in a dot directory like .config code will not be able to open the folder by itself. It will just started with an empty page complaing that .config is a directory and cannot be opened.

I am not sure if it is a vscode bug or a bug in this script.

Unterminated quoted string bug

After rebasing F35 to F36 I'm no longer able to open vscode in toolbox.

Steps to reproduce:

$ podman --version
podman version 4.0.0-rc4

$ toolbox enter
$ code .
ERRO[0000] Printing inspect output: template: all inspect:1: unterminated quoted string 
$HOME in container config is: '' - don't know how to handle this

Failed to create link no such file or directory

I tried the installation as follows.

  1. Install vscode as flatpak
  2. run through the install steps:
    1. git clone https://github.com/owtaylor/toolbox-vscode.git
    2. cd toolbox-vscode
    3. ln -s "$PWD/code.sh" ~/.local/bin/code

The last step produces the error message in the title because the directory ~/.local/bin does not exist.

Therefore adding a step for creating that folder if it doesn't exist sounds like a good idea.

Latest Fedora 39 Update Breaks code script

😢 it looks like the latest set of Fedora 39 updates breaks this script. The following error occurs when running code.sh on a fresh Fedora 39 machine and toolbox:

[27 ms] Start: Resolving Remote
[28 ms] Setting up container: dev-toolbox
[35 ms] Start: Run: podman-remote inspect --type container dev-toolbox
[16821 ms] Start: Run: podman-remote version --format {{.Server.APIVersion}}
[16836 ms] spawn podman-remote ENOENT
[16837 ms] CLI host's PATH: /app/bin:/app/bin:/app/bin:/usr/bin:/home/adkaplan/.var/app/com.visualstudio.code/data/node_modules/bin

Version info:

  • Fedora 39
  • Podman 4.8.2
  • VSCode Dev Containers 0.327.0 in VS Code 1.85.1

podman-host symlink created wrong when code.sh is invoked through a double symlink

Cannot attach to container name/id rust-development, it no longer exists

This was working the first time I used it. I later tried again after restarting and it failed.

You asked for as much detail as possible, but I'm honestly not sure what else to add.

If there's anything commands you would like me to know or logs you would like, please let me know :)

The script fails on first run, due to missing directories

I've tried your script in a new Toolbox container created from scratch. It fails to run in the first time because of missing directories $HOME/.var/app/com.visualstudio.code/config/Code/User/globalStorage/ms-vscode-remote.remote-containers/nameConfigs and /root/.vscode-server/data/Machine, which are not yet created automatically.

Better support when outside of toolbox env

Suggestion

When outside of a toolbox env, display a message that you need to be in a toolbox container for the script to properly execute. Another approach is to launch Code normally, on the host.

Currently, it prompts that Code Flatpak is not installed, but it is installed on the host.

A possible solution could look like this:

variant_id="$(grep -oP '(?<=^VARIANT_ID=).+' /etc/os-release | tr -d '"')"

if [ ! $variant_id = "container" ] ; then 
    echo "Execute from inside a container" 1>&2
    exit 1
fi

Edit: just check that an existing pull request explores this same issue. Will mark this as closed since it was already on the radar.

Cannot open multiple vscode instances

Once vscode is opened by code . I cannot open another instance of it:

toolbox-vscode: Creating /root/.vscode-server/data/Machine/settings.json
/var/home/someuser/.local/bin/code: line 382: /root/.vscode-server/data/Machine/settings.json: Permission denied

Support VSCode's RPM/tarball installation as well

Current toolbox-vscode implementation is primarily focused on Flatpak installation of VSCode, but I believe that it could support RPM/tar.xz installation of VSCode as well. The main reason one may prefer this approach rather than the Flatpak one is the fact that VSCode updates from Microsoft repository usually come faster than from Flathub (at the time I'm writting, the Flathub latest version is 3 releases behind the official RPM/tar.xz one).

An eventual RPM support needs to take the following details into account (I will edit the list as needed):

  • Support VSCode config location at ${HOME}/.config/Code/User/globalStorage as well as ${HOME}/.var/app/com.visualstudio.code/config/Code/User/globalStorage
  • The podman-host.sh script needs to be adapted to spawn podman directly rather than flatpak-spawn --host podman, but settings the same environment variables.
  • The ~/.local/bin/code symlink may conflict with default code binary path, depending on how user's PATH variable is set.
  • Maybe provide a way to automatically download VSCode RPM from official repository and install it with dnf / rpm-ostree / whatever.
  • Maybe support VSCode's tar.xz automatic download and uncompress at /usr/local or /opt folder as well (for ones worried about polluting their Fedora Silverblue/Kinoite installations with layered RPMs). In this case, toolbox-vscode could also check for updates for the tar.xz case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.