Skip to content

Commit

Permalink
feat: add support for VSCodium (#1603)
Browse files Browse the repository at this point in the history
Signed-off-by: hunnywar <[email protected]>
  • Loading branch information
hunnywar authored Jan 9, 2025
1 parent e019048 commit 179f59a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/daytona/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func GetIdeList() []Ide {
{"vscode", "VS Code"},
{"browser", "VS Code - Browser"},
{"cursor", "Cursor"},
{"codium", "VSCodium"},
{"ssh", "Terminal SSH"},
{"jupyter", "Jupyter"},
{"fleet", "Fleet"},
Expand Down
2 changes: 1 addition & 1 deletion docs/daytona_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ daytona code [WORKSPACE] [PROJECT] [flags]
### Options

```
-i, --ide string Specify the IDE (vscode, browser, cursor, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
-i, --ide string Specify the IDE (vscode, browser, cursor, codium, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
-y, --yes Automatically confirm any prompts
```

Expand Down
2 changes: 1 addition & 1 deletion docs/daytona_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ daytona create [REPOSITORY_URL | PROJECT_CONFIG_NAME]... [flags]
--devcontainer-path string Automatically assign the devcontainer builder with the path passed as the flag value
--env stringArray Specify environment variables (e.g. --env 'KEY1=VALUE1' --env 'KEY2=VALUE2' ...')
--git-provider-config string Specify the Git provider configuration ID or alias
-i, --ide string Specify the IDE (vscode, browser, cursor, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
-i, --ide string Specify the IDE (vscode, browser, cursor, codium, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
--manual Manually enter the Git repository
--multi-project Workspace with multiple projects/repos
--name string Specify the workspace name
Expand Down
2 changes: 1 addition & 1 deletion hack/docs/daytona_code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ options:
- name: ide
shorthand: i
usage: |
Specify the IDE (vscode, browser, cursor, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
Specify the IDE (vscode, browser, cursor, codium, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
- name: "yes"
shorthand: "y"
default_value: "false"
Expand Down
2 changes: 1 addition & 1 deletion hack/docs/daytona_create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ options:
- name: ide
shorthand: i
usage: |
Specify the IDE (vscode, browser, cursor, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
Specify the IDE (vscode, browser, cursor, codium, ssh, jupyter, fleet, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
- name: manual
default_value: "false"
usage: Manually enter the Git repository
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ var ideCmd = &cobra.Command{
switch chosenIde.Id {
case "vscode":
ide_util.CheckAndAlertVSCodeInstalled()
case "codium":
_, err := ide_util.GetCodiumBinaryPath()
if err != nil {
log.Error(err)
}
case "cursor":
_, err := ide_util.GetCursorBinaryPath()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/workspace/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ func openIDE(ideId string, activeProfile config.Profile, workspaceId string, pro
return ide.OpenTerminalSsh(activeProfile, workspaceId, projectName, gpgKey, nil)
case "browser":
return ide.OpenBrowserIDE(activeProfile, workspaceId, projectName, projectProviderMetadata, gpgKey)
case "codium":
return ide.OpenVScodium(activeProfile, workspaceId, projectName, projectProviderMetadata, gpgKey)
case "cursor":
return ide.OpenCursor(activeProfile, workspaceId, projectName, projectProviderMetadata, gpgKey)
case "jupyter":
Expand Down
82 changes: 82 additions & 0 deletions pkg/ide/vscodium.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2024 Daytona Platforms Inc.
// SPDX-License-Identifier: Apache-2.0

package ide

import (
"errors"
"fmt"
"os/exec"
"strings"

"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/internal/util"
"github.com/daytonaio/daytona/pkg/build/devcontainer"
)

const requiredExtension = "jeanp413.open-remote-ssh"

func OpenVScodium(activeProfile config.Profile, workspaceId string, projectName string, projectProviderMetadata string, gpgkey string) error {
path, err := GetCodiumBinaryPath()
if err != nil {
return err
}
// Install the extension if not installed
err = installExtension(path, requiredExtension)
if err != nil {
return err
}
projectHostname := config.GetProjectHostname(activeProfile.Id, workspaceId, projectName)

projectDir, err := util.GetProjectDir(activeProfile, workspaceId, projectName, gpgkey)
if err != nil {
return err
}

commandArgument := fmt.Sprintf("vscode-remote://ssh-remote+%s/%s", projectHostname, projectDir)

codiumCommand := exec.Command(path, "--disable-extension", "ms-vscode-remote.remote-containers", "--folder-uri", commandArgument)

err = codiumCommand.Run()
if err != nil {
return err
}

if projectProviderMetadata == "" {
return nil
}

return setupVSCodeCustomizations(projectHostname, projectProviderMetadata, devcontainer.Vscode, "*/.vscodium-server/*/bin/codium-server", "$HOME/.vscodium-server/data/Machine/settings.json", ".daytona-customizations-lock-codium")
}

func GetCodiumBinaryPath() (string, error) {
path, err := exec.LookPath("codium")
if err == nil {
return path, err
}

redBold := "\033[1;31m" // ANSI escape code for red and bold
reset := "\033[0m" // ANSI escape code to reset text formatting

errorMessage := "Please install VScodium from https://vscodium.com/ and ensure it's in your PATH.\n"

return "", errors.New(redBold + errorMessage + reset)
}

func installExtension(binaryPath string, extensionName string) error {
// Check if the required extension is installed
output, err := exec.Command(binaryPath, "--list-extensions").Output()
if err != nil {
return err
}

if !strings.Contains(string(output), extensionName) {
fmt.Printf("Installing %s extension...\n", extensionName)
err = exec.Command(binaryPath, "--install-extension", extensionName).Run()
if err != nil {
return err
}
fmt.Printf("%s extension successfully installed\n", extensionName)
}
return nil
}

0 comments on commit 179f59a

Please sign in to comment.