Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Vim IDE #1698

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/daytona/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GetIdeList() []Ide {
{"codium", "VSCodium"},
{"codium-insiders", "VSCodium Insiders"},
{"ssh", "Terminal SSH"},
{"vim", "Vim"},
{"jupyter", "Jupyter"},
{"fleet", "Fleet"},
{"positron", "Positron"},
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, code-insiders, browser, cursor, codium, codium-insiders, ssh, jupyter, fleet, positron, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
-i, --ide string Specify the IDE (vscode, code-insiders, browser, cursor, codium, codium-insiders, ssh, vim, jupyter, fleet, positron, 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, code-insiders, browser, cursor, codium, codium-insiders, ssh, jupyter, fleet, positron, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
-i, --ide string Specify the IDE (vscode, code-insiders, browser, cursor, codium, codium-insiders, ssh, vim, jupyter, fleet, positron, 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, code-insiders, browser, cursor, codium, codium-insiders, ssh, jupyter, fleet, positron, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
Specify the IDE (vscode, code-insiders, browser, cursor, codium, codium-insiders, ssh, vim, jupyter, fleet, positron, 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, code-insiders, browser, cursor, codium, codium-insiders, ssh, jupyter, fleet, positron, zed, windsurf, clion, goland, intellij, phpstorm, pycharm, rider, rubymine, webstorm)
Specify the IDE (vscode, code-insiders, browser, cursor, codium, codium-insiders, ssh, vim, jupyter, fleet, positron, 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 @@ -66,6 +66,11 @@ var ideCmd = &cobra.Command{
if err != nil {
log.Error(err)
}
case "vim":
_, err := ide_util.GetEditorBinaryPath("Vim")
if err != nil {
log.Error(err)
}
case "fleet":
if err := ide_util.CheckFleetInstallation(); err != nil {
log.Error(err)
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 @@ -187,6 +187,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 "vim":
return ide.OpenEditor("Vim", activeProfile, workspaceId, projectName, gpgKey)
case "codium":
return ide.OpenVScodium(activeProfile, workspaceId, projectName, projectProviderMetadata, gpgKey)
case "codium-insiders":
Expand Down
63 changes: 63 additions & 0 deletions pkg/ide/vim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2024 Daytona Platforms Inc.
// SPDX-License-Identifier: Apache-2.0

package ide

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

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

// OpenEditor opens the specified editor (vim/nvim) for a given project
func OpenEditor(editorBinary string, activeProfile config.Profile, workspaceId, projectName, gpgKey string) error {
path, err := GetEditorBinaryPath(editorBinary)
if err != nil {
return err
}

printEditorDisclaimer(editorBinary)
projectHostname := config.GetProjectHostname(activeProfile.Id, workspaceId, projectName)
projectDir, err := util.GetProjectDir(activeProfile, workspaceId, projectName, gpgKey)
if err != nil {
return err
}
// Suppresses "Permanently added ... to the list of known hosts" message and reduces file listing errors
editorConfig := fmt.Sprintf(`:let g:netrw_list_cmd = "ssh -o LogLevel=QUIET %s ls -Fa"`, projectHostname)

// Both scp and sftp are supported by Vim/Nvim's built-in netrw plugin
editorCmd := exec.Command(path, "-c", editorConfig, fmt.Sprintf("scp://%s/%s/", projectHostname, projectDir))
editorCmd.Stdin = os.Stdin
editorCmd.Stdout = os.Stdout
editorCmd.Stderr = os.Stderr

return editorCmd.Run()
}

// GetEditorBinaryPath returns the path to the specified editor binary
func GetEditorBinaryPath(editorBinary string) (string, error) {
path, err := exec.LookPath(strings.ToLower(editorBinary))
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 := fmt.Sprintf("Please install %s and ensure it's in your PATH.\n", editorBinary)

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

// printEditorDisclaimer displays a disclaimer message for the specified editor
func printEditorDisclaimer(editorName string) {
views.RenderTip(fmt.Sprintf(`Note: %s only allows you to edit remote files using Netrw.
For a better experience, consider using a dedicated IDE.
If you need to run commands, please use the 'daytona ssh' command instead.`, editorName))
}
Loading