Description
Disclaimer: beware, wall of text ahead.
Abstract
Command line usage is pretty much ingrained in my workflows, as I suspect is for most vim users. Currently, the oni command lacks much of what would make it good for such usage.
I'm new to both neovim and oni, but I've used vim for more than 12 years and I want to switch to a modern version of vim. I tried both atom and vscode with vim emulation extensions, but it doesn't live up to expectations.
I have installed the rpm release package in Fedora, and everything I say here is in regards to using oni from the command line when installing it from release packages (not the npm package, neither from a dev checkout).
Motivation
I always start editors from the command line, mostly because:
a) I use the terminal when working on a project. I have tmux setup with sessions spawning panes and windows accordingly for each project. There's also a myriad of other command line tools that are used in development workflows.
b) To use the same environment in the editor as the environment set up in a). For example, variables set up according to several environment managers (pyenv, rbenv, nvm, gimme, rustup, etc). This enables development tools (debuggers, linters, language servers, etc) to be correctly detected, on a per-project basis.
Concerns
The release package installs a symlink to the electron binary in the system $PATH, bypassing cli/oni and spawning the electron app directly.
So my main issues are:
- Regardless of
cli/onibeing changed to spawn the electron process in the background, it's never used and the editor is always launched in the foreground; - Command line options seem to be ignored or don't exist at all (correct if I'm wrong);
- Workspace detection seems non-intuitive
Proposal
Starting the editor from command line should be treated as a separate concern from the regular app launch. When starting from the command line, it should:
- Dettach to background by default, since it's not a terminal application;
- Provide command line options with help;
- Provide a command line option to keep in the foreground (named
foregroundfor reference), likegvim -f. This makes it possible foronito be used in command line workflows that requires spawning an editor and waiting for termination (likegit mergetoolor settingVISUAL=oni -f); - Provide command line option to open a buffer at a specific location (named
gotofor reference), similar tovim +line <file>; - Apply specific workspace detection (see below);
Workspace detection
When detecting workspaces, $PWD should be taken into consideration. Therefore, detection logic could be:
- if no arguments are given: open an empty buffer, detect workspace using
$PWD. If it fails, don't use any workspace - if a directory is given as argument: detect workspace using the given directory. If it succeeds, open empty buffer. If it fails, open netrw's listing in a buffer
- if a file is given as argument: open the file in a buffer, detect workspace for the given file. If it fails, don't use any workspace
Then when respecting workspace configuration:
"workspace.autoDetectWorkspace": "noworkspace":- if previous workspace is available: activate it
- if no previous workspace is available: use detection logic
"workspace.autoDetectWorkspace": "always": always use detection logic"workspace.autoDetectWorkspace": "never":- if previous workspace is available: activate it
- if no previous workspace is available: do nothing
Implementation proposal
Most of the proposed points are taken from VSCode's code, with the exception that it also ignores $PWD when detecting workspaces.
Investigating more about the code command, the release package installs a symlink to a platform-specific launch script, which then runs the node cli script:
$ file $(which code)
/usr/bin/code: symbolic link to /usr/share/code/bin/code
$ file /usr/share/code/bin/code
/usr/share/code/bin/code: Bourne-Again shell script, ASCII text executable
Tail of the Linux launch script:
ELECTRON="$VSCODE_PATH/code"
CLI="$VSCODE_PATH/resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
vscode's platform-specific launch scripts: linux, win32, darwin
vscode's CLI script: https://github.com/Microsoft/vscode/blob/8c37fa806d3044f5a3eeb2edea276c6aa66e56bc/src/vs/code/node/cli.ts
So steps for accomplishing the proposals would be (correct me if I missed something):
- Create platform-specific launch scripts that runs
cli/oniusing the electron binary - Change packaging to install a symlink to the launch script
- Change
cli/onito:- extract CLI-specific options from argv (from proposal:
foreground) - add a command line option to the main process that indicates it was started from the command line or manipulate the environment (named
is_clifor reference) - be aware of both invocations (node or electron), which is mostly re-spawning its own process (the platform-specific launch script already decided in cases of release-installed invocations and is node itself in case of development invocations)
- pass the rest of argv to the child process
- wait for child process to exit if the
foregroundoption was given
- extract CLI-specific options from argv (from proposal:
- Change the main/browser processes to:
- parse command line options (from proposal:
goto,is_cliif a command line) - change file opening to check for
goto - change workspace detection to check
is_cliand apply proposed detection logic if it's enabled
- parse command line options (from proposal:
Additional Proposals
These are additional proposals for command line usage, which I think would require new features:
- Provide instance management command line options (new instance, reuse existing instance)
- Provide a diff mode command line option