Skip to content

Commit

Permalink
fix: code command opening wrong directory
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <toma.puljak@hotmail.com>
  • Loading branch information
Tpuljak committed Jan 27, 2025
1 parent e5158d6 commit 3cbb769
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions internal/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetHomeDir(activeProfile config.Profile, workspaceId string, gpgKey *string
return strings.TrimRight(string(homeDir), "\n"), nil
}

func GetWorkspaceDir(activeProfile config.Profile, workspaceId string, gpgKey *string) (string, error) {
func GetWorkspaceDir(activeProfile config.Profile, workspaceId, repoName string, gpgKey *string) (string, error) {
err := config.EnsureSshConfigEntryAdded(activeProfile.Id, workspaceId, gpgKey)
if err != nil {
return "", err
Expand All @@ -49,5 +49,5 @@ func GetWorkspaceDir(activeProfile config.Profile, workspaceId string, gpgKey *s
return "", err
}

return path.Join(homeDir, workspaceId), nil
return path.Join(homeDir, repoName), nil
}
26 changes: 13 additions & 13 deletions pkg/cmd/common/open_ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ import (
log "github.com/sirupsen/logrus"
)

func OpenIDE(ideId string, activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, yesFlag bool, gpgKey *string) error {
func OpenIDE(ideId string, activeProfile config.Profile, workspaceId, repoName, workspaceProviderMetadata string, yesFlag bool, gpgKey *string) error {
var err error
switch ideId {
case "vscode":
err = ide.OpenVSCode(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenVSCode(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "code-insiders":
err = ide.OpenVSCodeInsiders(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenVSCodeInsiders(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "ssh":
err = ide.OpenTerminalSsh(activeProfile, workspaceId, gpgKey, nil)
case "browser":
err = ide.OpenBrowserIDE(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenBrowserIDE(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "codium":
err = ide.OpenVScodium(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenVScodium(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "codium-insiders":
err = ide.OpenVScodiumInsiders(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenVScodiumInsiders(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "cursor":
err = ide.OpenCursor(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenCursor(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "jupyter":
err = ide.OpenJupyterIDE(activeProfile, workspaceId, workspaceProviderMetadata, yesFlag, gpgKey)
err = ide.OpenJupyterIDE(activeProfile, workspaceId, repoName, workspaceProviderMetadata, yesFlag, gpgKey)
case "fleet":
err = ide.OpenFleet(activeProfile, workspaceId, gpgKey)
err = ide.OpenFleet(activeProfile, workspaceId, repoName, gpgKey)
case "positron":
err = ide.OpenPositron(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenPositron(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
case "zed":
err = ide.OpenZed(activeProfile, workspaceId, gpgKey)
err = ide.OpenZed(activeProfile, workspaceId, repoName, gpgKey)
case "windsurf":
err = ide.OpenWindsurf(activeProfile, workspaceId, workspaceProviderMetadata, gpgKey)
err = ide.OpenWindsurf(activeProfile, workspaceId, repoName, workspaceProviderMetadata, gpgKey)
default:
_, ok := jetbrains.GetIdes()[jetbrains.Id(ideId)]
if ok {
err = ide.OpenJetbrainsIDE(activeProfile, ideId, workspaceId, gpgKey)
err = ide.OpenJetbrainsIDE(activeProfile, ideId, workspaceId, repoName, gpgKey)
} else {
return errors.New("invalid IDE. Please choose one by running `daytona ide`")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/workspace/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var CodeCmd = &cobra.Command{
yesFlag, _ := cmd.Flags().GetBool("yes")
ideList := config.GetIdeList()
ide_views.RenderIdeOpeningMessage(ws.TargetId, ws.Name, ideId, ideList)
return common.OpenIDE(ideId, activeProfile, ws.Id, providerMetadata, yesFlag, gpgKey)
return common.OpenIDE(ideId, activeProfile, ws.Id, ws.Repository.Name, providerMetadata, yesFlag, gpgKey)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return common.GetWorkspaceNameCompletions()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/workspace/create/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ var CreateCmd = &cobra.Command{

views.RenderCreationInfoMessage(fmt.Sprintf("Opening the workspace in %s ...", chosenIde.Name))

return cmd_common.OpenIDE(chosenIdeId, activeProfile, createWorkspaceDtos[0].Name, *createdWorkspaces[0].ProviderMetadata, YesFlag, gpgKey)
return cmd_common.OpenIDE(chosenIdeId, activeProfile, createWorkspaceDtos[0].Id, createWorkspaceDtos[0].Source.Repository.Name, *createdWorkspaces[0].ProviderMetadata, YesFlag, gpgKey)
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/workspace/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var StartCmd = &cobra.Command{

if codeFlag {
ide_views.RenderIdeOpeningMessage(ws.TargetId, ws.Name, ideId, ideList)
err = common.OpenIDE(ideId, activeProfile, ws.Id, workspaceProviderMetadata, yesFlag, gpgKey)
err = common.OpenIDE(ideId, activeProfile, ws.Id, ws.Repository.Name, workspaceProviderMetadata, yesFlag, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const startVSCodeServerCommand = "$HOME/vscode-server/bin/openvscode-server --start-server --port=63000 --host=0.0.0.0 --without-connection-token --disable-workspace-trust --default-folder="

func OpenBrowserIDE(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgKey *string) error {
func OpenBrowserIDE(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgKey *string) error {
// Download and start IDE
err := config.EnsureSshConfigEntryAdded(activeProfile.Id, workspaceId, gpgKey)
if err != nil {
Expand All @@ -42,7 +42,7 @@ func OpenBrowserIDE(activeProfile config.Profile, workspaceId string, workspaceP
return err
}

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
"github.com/daytonaio/daytona/pkg/build/devcontainer"
)

func OpenCursor(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgKey *string) error {
func OpenCursor(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgKey *string) error {
path, err := GetCursorBinaryPath()
if err != nil {
return err
}

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
log "github.com/sirupsen/logrus"
)

func OpenFleet(activeProfile config.Profile, workspaceId string, gpgKey *string) error {
func OpenFleet(activeProfile config.Profile, workspaceId, repoName string, gpgKey *string) error {
if err := CheckFleetInstallation(); err != nil {
return err
}

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/jetbrains.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"github.com/pkg/browser"
)

func OpenJetbrainsIDE(activeProfile config.Profile, ide, workspaceId string, gpgKey *string) error {
func OpenJetbrainsIDE(activeProfile config.Profile, ide, workspaceId, repoName string, gpgKey *string) error {
err := IsJetBrainsGatewayInstalled()
if err != nil {
return err
}

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/ide/jupyter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
const startJupyterCommand = "notebook --no-browser --port=8888 --ip=0.0.0.0 --NotebookApp.token='' --NotebookApp.password=''"

// OpenJupyterIDE manages the installation and startup of a Jupyter IDE on a remote target.
func OpenJupyterIDE(activeProfile config.Profile, workspaceId, workspaceProviderMetadata string, yesFlag bool, gpgKey *string) error {
func OpenJupyterIDE(activeProfile config.Profile, workspaceId, repoName, workspaceProviderMetadata string, yesFlag bool, gpgKey *string) error {
// Ensure SSH config entry is added
err := config.EnsureSshConfigEntryAdded(activeProfile.Id, workspaceId, gpgKey)
if err != nil {
Expand All @@ -51,7 +51,7 @@ func OpenJupyterIDE(activeProfile config.Profile, workspaceId, workspaceProvider
}

// Start Jupyter Notebook server
if err := startJupyterServer(workspaceHostname, activeProfile, workspaceId, gpgKey); err != nil {
if err := startJupyterServer(workspaceHostname, activeProfile, workspaceId, repoName, gpgKey); err != nil {
return err
}

Expand Down Expand Up @@ -216,8 +216,8 @@ func ensureJupyterInstalled(hostname string) error {
}

// startJupyterServer starts the Jupyter Notebook server on the remote target.
func startJupyterServer(hostname string, activeProfile config.Profile, workspaceId string, gpgKey *string) error {
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
func startJupyterServer(hostname string, activeProfile config.Profile, workspaceId, repoName string, gpgKey *string) error {
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/positron.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
"github.com/daytonaio/daytona/pkg/views"
)

func OpenPositron(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgkey *string) error {
func OpenPositron(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgkey *string) error {
path, err := GetPositronBinaryPath()
if err != nil {
return err
}

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgkey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgkey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/vscode-insiders.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/daytonaio/daytona/pkg/build/devcontainer"
)

func OpenVSCodeInsiders(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgKey *string) error {
func OpenVSCodeInsiders(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgKey *string) error {
path, err := GetVSCodeInsidersBinaryPath()
if err != nil {
return err
Expand All @@ -25,7 +25,7 @@ func OpenVSCodeInsiders(activeProfile config.Profile, workspaceId string, worksp

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
log "github.com/sirupsen/logrus"
)

func OpenVSCode(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgKey *string) error {
func OpenVSCode(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgKey *string) error {
CheckAndAlertVSCodeInstalled()
err := installRemoteSSHExtension("code")
if err != nil {
Expand All @@ -28,7 +28,7 @@ func OpenVSCode(activeProfile config.Profile, workspaceId string, workspaceProvi

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/vscodium-insiders.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/daytonaio/daytona/pkg/build/devcontainer"
)

func OpenVScodiumInsiders(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgkey *string) error {
func OpenVScodiumInsiders(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgkey *string) error {
path, err := GetCodiumInsidersBinaryPath()
if err != nil {
return err
Expand All @@ -26,7 +26,7 @@ func OpenVScodiumInsiders(activeProfile config.Profile, workspaceId string, work

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgkey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgkey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/vscodium.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

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

func OpenVScodium(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgkey *string) error {
func OpenVScodium(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgkey *string) error {
path, err := GetCodiumBinaryPath()
if err != nil {
return err
Expand All @@ -29,7 +29,7 @@ func OpenVScodium(activeProfile config.Profile, workspaceId string, workspacePro

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgkey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgkey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/windsurf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
"github.com/daytonaio/daytona/pkg/build/devcontainer"
)

func OpenWindsurf(activeProfile config.Profile, workspaceId string, workspaceProviderMetadata string, gpgkey *string) error {
func OpenWindsurf(activeProfile config.Profile, workspaceId, repoName string, workspaceProviderMetadata string, gpgkey *string) error {
path, err := GetWindsurfBinaryPath()
if err != nil {
return err
}

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)

workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgkey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgkey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ide/zed.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/daytonaio/daytona/pkg/views"
)

func OpenZed(activeProfile config.Profile, workspaceId string, gpgKey *string) error {
func OpenZed(activeProfile config.Profile, workspaceId, repoName string, gpgKey *string) error {
path, err := GetZedBinaryPath()
if err != nil {
return err
}

workspaceHostname := config.GetHostname(activeProfile.Id, workspaceId)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, gpgKey)
workspaceDir, err := util.GetWorkspaceDir(activeProfile, workspaceId, repoName, gpgKey)
if err != nil {
return err
}
Expand Down

0 comments on commit 3cbb769

Please sign in to comment.