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 CUSTOM_EDITOR escape hatch for advanced configuration #39
Conversation
I have an odd but specific use case in mind that I think this would definitely be the solution for, so 👍🏼 |
Could you share your |
sure! it's as simple as # ~/.zsh/mvim
nvr --remote "$@" and # ~/.zshrc
export VISUAL="mvim"
# then I use this to open up my project.
# "h(ost)vim" => wrapper around nvim that listens to neovim-remote's standard server location
hvim() {
nvim --listen /tmp/nvimsocket "$@"
} |
or not |
Thanks! I finally got the time to read through the issues and PRs. And I've discussed this one with Evan. One nitpick: considering this environment variable is only used for this package, the name |
👍🏼 +1 to LAUNCH_EDITOR which seems more specific. |
I agree, |
@@ -76,6 +76,11 @@ module.exports = function guessEditor (specifiedEditor) { | |||
// Ignore... | |||
} | |||
|
|||
// Check if user chose the LAUNCH_EDITOR escape hatch | |||
if (process.env.LAUNCH_EDITOR) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be done at the beginning of "guess" or even outside of it, it isn't a guess if the user specified an explicit command to use.
In fact if a different editor was found in the process list it would still be preferred over LAUNCH_EDITOR in the current implementation
(sorry for not asking this sooner)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it like this to have the changes be as low profile as possible. This way it would definitely not disturb how launch-editor operated before and be non-breaking.
I guess the amount of people who use this tool already and happen to have a LAUNCH_EDITOR environment variable set is pretty negligible though...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it would be a breaking change either way for people that already have the environment variable set. a google search for "LAUNCH_EDITOR" did turn up very few results (<3k) and skimming them i didn't find documented use of it as an env variable
For extra safety, LAUNCH_EDITOR_COMMAND
has 3 results and all of them seem to point at one python lib config option from 2018.
Another question. Should get-args"be used to try and pass args to known editors before resorting to 3 different args? That would allow |
minimal changes would be like this: https://github.com/yyx990803/launch-editor/compare/master...dominikg:launch-editor:feat/launch-editor-env?expand=1 Q: Do we need to call shell-quote on the content of LAUNCH_EDITOR? (not done on the content of EDITOR or VISUAL, but was wondering since it is used for specifiedEditor, which is basically the js equivalent of LAUNCH_EDITOR) Q: Would specifiedEditor or LAUNCH_EDITOR have precedence |
Btw. here is another fork of react-dev-utils functionality as a vite plugin (and uses the VUE_EDITOR env variable): |
Do you want to suggest that vite (or others using this lib) should define their own env variables for custom support? |
see #49 for the changes i suggested above. Obviously i prefer the added flexibility it brings but would be fine with the implementation here too. |
No, I don't care about that, @dominikg. Not sure where you get that from. What I would be concerned about, is discoverability of this feature when used e.g. in vite. |
Thanks for the helpful discussions! As for the unanswered questions:
I think we don't need to bother until there are users complaining.
The current implementation looks good to me, i.e. |
Note: This feature (now implemented by #49) will be included in the upcoming vite 3.1.0 release, which is currently in beta. |
TL;DR: Provide an escape hatch for more customization, via a
CUSTOM_EDITOR
environment variable that points to a script, which is passed fileName, lineNumber and columnNumber.First of all: thank you for creating this package, I started using it as an upstream dependency of vite-plugin-svelte-inspector today and am amazed by how cool this is!
Since neovim is my editor of choice, I started tinkering away and ended up with an implementation that works okay-ish for me, but is very hacky.
Just by setting
VISUAL="nvim"
it already sort of works, and node spawns a subprocess with nvim opening the correct file, but everything breaks on subsequent clicks, because having multiple instances of nvim run as subprocesses is obviously not optimal and even when usingVISUAL="vim"
, which should be better as launch-editor detects that it's a terminal editor and kills the process once before spawning it again, after a few edits everything breaks in ugly ways.So I put a script into my path that uses neovim-remote (https://github.com/mhinz/neovim-remote) to remotely open the file in a specific neovim instance that was listening for remote commands (nvim --listen /tmp/nvimsocket) like this
nvr --remote "$@" and again it sort of worked, opening the correct file provided by Inspector-click in the "server" neovim instance, but not supporting line/column number. (As this being passed on depends on a hardcoded list of editors in
get-args.js
and the script name I picked obviously wasn't in this hardcoded list.)Since I don't use mvim (one of the arbitrarily chosen supported editors) I just decided to call my command to open the neovim remote mvim, and this resulted in line number and character positions being accurately passed to my script.
Now, this is hacky and not nice on two levels: 1. VISUAL/EDITOR have to be set to a command that is not necessarily the same command one would use for git operations for example 2. I had to resort to naming my command
mvim
to receive the correct arguments, which is only possible because I don't use mvim and I happened to need the arguments in the same manner.Since it is impossible to support every conceivable editors in this package, it might be nice to provide an escape hatch for people to write custom scripts to open the editor they want, in the way they want.
This PR proposes introducing an escape hatch for more customization in form of a
CUSTOM_EDITOR
environment variable that can specify a command to be called with fileName, lineNumber and columnNumber passed in as arguments, which can then be used however the user wishes.