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

prepareEditorCommand doesn't accept arguments #98

Open
davidvasandani opened this issue Apr 20, 2024 · 4 comments
Open

prepareEditorCommand doesn't accept arguments #98

davidvasandani opened this issue Apr 20, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@davidvasandani
Copy link

https://github.com/plandex-ai/plandex/blob/a8f88a961e55f7d29ea7e52ce87ff01267349f7b/app/cli/cmd/tell.go#L103C1-L132C1

To diagnose why the provided code snippet doesn't accept zed --wait as an editor parameter when setting the EDITOR or VISUAL environment variables, we need to consider how the prepareEditorCommand function is implemented. You haven't provided the implementation details for this function, so I will make an educated guess based on common practices.

Potential Issues

  1. Tokenization and Parsing Issue:

    • If prepareEditorCommand simply splits the editor command based on spaces or uses only the first token, it might not correctly recognize parameters like --wait. When a command with spaces is set (e.g., "zed --wait"), it must be properly parsed into an executable part ("zed") and its arguments ("--wait").
  2. Environment Variables Just Read Executable:

    • It's possible that prepareEditorCommand is designed only to execute the editor without any arguments. This could mean it doesn't split the string and treats it as a whole executable name, which is not correct because "zed --wait" is not a single executable but rather an executable with an option.

Suggested Solution

Here is how you might want to adjust the prepareEditorCommand function to handle the executable and its arguments properly.

You’d want your prepareEditorCommand to:

  • Split the editor string by spaces to get the first part as the command and the remaining as its arguments.
  • Setup the command using the split results to correctly initialize both the executable and its arguments.

Here's a basic approach in Go:

import (
	"os/exec"
	"strings"
)

func prepareEditorCommand(editor string, filename string) *exec.Cmd {
	parts := strings.Fields(editor) // Splits the editor command by spaces
	cmd := exec.Command(parts[0], append(parts[1:], filename)...) // parts[0] is the command, parts[1:] are the args, added filename
	return cmd
}

This modification takes the entire contents of editor, splits them into a slice where parts[0] is the executable (e.g., "zed") and parts[1:] are all arguments provided (e.g., ["--wait"]). This way, it also appends the filename as the last argument, aligning with usual usage like vim filename.

Verification

After implementing this, ensure that you either directly pass "zed --wait" or set your environment variable correctly (export EDITOR="zed --wait" on Unix-like systems) before running your program to verify that the editor opens as expected with the provided parameters.

@davidvasandani
Copy link
Author

I generated the issue with ChatGPT and believe it correctly interpreted the problem and solution. Thanks!

@danenania
Copy link
Contributor

@davidvasandani Thanks! This makes sense... want to make a PR for it by any chance?

@danenania danenania added enhancement New feature or request good first issue Good for newcomers labels Apr 25, 2024
@ADTmux
Copy link

ADTmux commented Apr 30, 2024

I would like to work on this issue :)

@danenania
Copy link
Contributor

@ADTmux Thank you! Assigned it to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants