Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Throw a warning prompt if "Open in Editor" fails. #203

Open
joshwcomeau opened this issue Sep 2, 2018 · 8 comments
Open

Throw a warning prompt if "Open in Editor" fails. #203

joshwcomeau opened this issue Sep 2, 2018 · 8 comments
Labels
bug Something isn't working good first issue Good for newcomers upcoming feature New feature or request

Comments

@joshwcomeau
Copy link
Owner

Is your feature request related to a problem? Please describe.
In #171, I added a couple new options to the Application Menu:

  • Open Folder
  • Open in Editor

The latter, "Open in Editor", is supposed to open the current project in VS Code, or Sublime Text, or Atom, whatever.

It relies on the existence of an "EDITOR" environment variable that should be present after you've installed an editor, but may not be.

Right now, if no EDITOR is found, it just silently fails.

Describe the solution you'd like
We should pop a warning prompt, something like:

No editor found

Have you installed a code editor, like Visual Studio Code?

If so, you may have an issue with your PATH.

Learn more:

Additional context
We should use dialog.showMessageBox from Electron, to use system prompts. We should also write up some quick documentation to explain how to fix this issue (and how PATH works more broadly)

This is a great first issue for new contributors! Especially for folks who are already a little familiar with PATH.

@joshwcomeau joshwcomeau added bug Something isn't working upcoming feature New feature or request good first issue Good for newcomers labels Sep 2, 2018
@shockry
Copy link

shockry commented Sep 13, 2018

I'm looking into this and from what I see, react-dev-utils returns undefined anyway, for success or failure.

Because of this, we can't know for sure if there is a problem with PATH, meaning if we check for the existence of EDITOR then delegate the call to react-dev-utils, if it happens thatEDITOR's value is incorrect or not in the PATH, it would still fail silently.

I'm not sure how often does that happen but from the discussion in #171, I can see that it does happen.

Is that something we should be considering?

@joshwcomeau
Copy link
Owner Author

Hi @shockry!

Because of this, we can't know for sure if there is a problem with PATH, meaning if we check for the existence of EDITOR then delegate the call to react-dev-utils, if it happens thatEDITOR's value is incorrect or not in the PATH, it would still fail silently.

Yeah, I think this is what I was imagining. Check for EDITOR (or, do whatever react-dev-utils uses to try and find it), and if it's not present, throw a prompt instead of calling launchEditor

@shockry
Copy link

shockry commented Sep 15, 2018

Great! I still have a question though, react-div-utils's launchEditor does a good chunk of work in its guessEditor function, part of that work is scanning through currently running processes to try and find a known editor between them, handling that for different platforms.

Rest of the work is just checking for environment variables.

The question is, detecting running editors is a pretty complex piece of logic that we would have to maintain if we're doing it in pre-checks, so should we copy that behavior over as well, or just settle for env. variable checks (while making sure they're in the PATH)?

@joshwcomeau
Copy link
Owner Author

Sorry @shockry! Missed this question.

Ah I see. This is surprisingly tricky then! It's really a shame that launchEditor doesn't expose what it finds.

I wonder if it'd be worth opening a PR on react-dev-utils to make launchEditor return a Promise that resolves if it finds an editor and rejects if it doesn't? Are you interested in opening an issue there and seeing if this is functionality they're interested in?

That would really be the best case, since as you say, we wouldn't have to maintain our own fork, as new editors are released.

If that fails, I think we can just copy launchEditor.js to our repo (maybe in vendor/launchEditor.js), with a comment at the top that explains where it comes from (with a link back), including the version of react-dev-utils it was taken from.

Let us know! Sorry again for the delay in our response =(

@shockry
Copy link

shockry commented Sep 24, 2018

No worries, the first response was super fast though ^^

I have just opened an issue there so let's see how that goes. If you have suggestions on the formatting of the issue, tell me and I'll go edit it.

@Timer
Copy link

Timer commented Sep 24, 2018

We're in progress of inheriting the launch-editor package and will be more than happy to implement this change.

@joshwcomeau
Copy link
Owner Author

We're in progress of inheriting the launch-editor package and will be more than happy to implement this change.

Woohoo! Thanks @Timer :D

@AWolf81
Copy link
Collaborator

AWolf81 commented Feb 22, 2019

After a fresh Windows installation I'm getting the following output if I'm trying to open editor (Guppy v0.3.0).

grafik

So it's only visible in development console.

If one instance of VS code is running the project is opening correctly. Adding REACT_EDITOR=code to system env. vars is not working for me. I need to check why this is not working.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers upcoming feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants