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

fix: execute login before starting login shell #2405

Merged
merged 56 commits into from
Mar 29, 2024
Merged

Conversation

falcucci
Copy link
Member

@falcucci falcucci commented Mar 7, 2024

This must solve most problems when neovide interact as a NON tty from the macOS application perspective persisting user sessions.

The following changes has been made:

  • execute a non interactive login shell properly;

    After some research, using /usr/bin/login is the proper way for tty creation (hello alacrity, kitty), this is also important for script creation which depends from different conditions to be applied in case of tty command execution. I could avoid for example some mistakes at my scripts after identify this improvement.

    This also fixes feat: launch neovide as --cwd $HOME if not given directory path on macOS #2407 which is a desirable behavior for macOS users to apply when they launch Neovide from the Finder or the Dock without any neovim setup changes to work out of the box.

    It forks a login shell with the user environment correctly such as its PATH values and uses the default macOS shell /bin/zsh in case we miss the shell common identification instead of /bin/sh to be spawned.

  • update neovide installation instructions for macOS users;

    mainly homebrew users are getting confused about it afterwards, regarding to their shell setup, this instruct them better and avoid possible open issues like Failed launching neovide on macOS from brew #1373;

  • update neovim_ok function to handle errors properly;

    in the previous implementation the function wasn't working as expect after some debugging scenarios, such as returning OK when stderr is empty and stdout is succeed but also empty.

    The dynamic of the function was also simplified for a better maintainability.

What kind of change does this PR introduce?

  • Fix

Did this PR introduce a breaking change?

  • No

fixes #2407 #1373 #1604 #2112 #1859 #1679

- change the error message when `nvim` is not found in `command.rs`
- add a new command in `create_platform_shell_command` in `command.rs`
- print command output in `launch` async function in `mod.rs`
- uncomment and implement the `fmt::debug` trait for `neovimsession` struct in `session.rs`
- add `error_handling::resultpanicexplanation` to the imports in `command.rs`
- add the `setup_env` function definition in `command.rs`
- add setup environment variables for `term` and `colorterm` in `command.rs`
- modify the `create_platform_shell_command` to use the `user` environment variable in `command.rs`
- update `nvim_cmd_impl` function to use the `user` environment variable in `command.rs`
- move the `command` module to be public in `mod.rs`
- update imports in `main.rs` to include `setup_env` from `command` in `main.rs`
- update error message for neovim not found
- improve error message clarity in build_nvim_cmd function
- remove unnecessary line in create_platform_shell_command function
- modify neovim command for version check in src/bridge/mod.rs
- remove unnecessary code checking neovim version in `src/bridge/mod.rs`
- add checking for nvim existence and return an error if not found
- update comment to remove mention of macos as the command is used on other platforms as well
- remove commented out field in `neovimsession` debug implementation
- simplify `create_platform_shell_command` by removing duplicate code
- refactor argument handling for `result.args` in `create_platform_shell_command`
- change default shell to `/bin/zsh`
- add command execution with a login shell for macos
- update command structure for nvim_cmd_impl function
- remove the `setup_env` function from `command.rs`
- remove the call to `setup_env` in `main.rs`
Copy link

github-actions bot commented Mar 7, 2024

Test Results

  3 files  ±0    3 suites  ±0   9s ⏱️ +2s
107 tests ±0  107 ✅ ±0  0 💤 ±0  0 ❌ ±0 
315 runs  ±0  315 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 49625a6. ± Comparison against base commit 9bdf50a.

♻️ This comment has been updated with latest results.

- update the build_nvim_cmd function to use settings.get::<&lt;cmdlinesettings>>().neovim_bin directly
- move `command` module declaration to be non-public
- remove unnecessary import of `path::pathbuf` in `command.rs` in the bridge directory
- update neovide installation instructions in `installation.md`
- update `neovim_ok` function to handle errors properly
- improve error message generation in `create_error_message` function
- refactor `neovim_ok` to use a unified error handling approach
- add logic to handle unexpected output in `neovim_ok` function
- add comment explaining lossy conversion for non-utf8 output
- edit comment regarding windows specific output issues
- fix typo in a comment about using the `login` command on macos
- update comment about `login` command to clarify tty session appearance
- add a debug trait implementation for `neovimsession` module
@falcucci falcucci marked this pull request as ready for review March 7, 2024 16:44
@falcucci falcucci requested a review from fredizzimo March 7, 2024 16:53
website/docs/installation.md Outdated Show resolved Hide resolved
- fix a typo in the neovide text to user
- fix the typo by changing `users` to `user's`
- add a check if a terminal is available on macos before executing a command
- setup a startup directory on macos before executing commands
- set the `neovide_tty` variable in neovim based on terminal availability
- remove unused import for `is_tty` in `src/bridge/setup.rs`
- reorganize imports in `src/bridge/setup.rs` to group related items together
- remove `use std::io::isterminal` from the `src/bridge/command.rs` file
- add a conditional import of `use std::io::isterminal` for `macos` in `src/bridge/command.rs`
- remove setting of `neovide_tty` variable outside of macos target
- add setting of `neovide_tty` variable inside macos target
- refactor code to properly handle platform-specific settings
src/bridge/command.rs Outdated Show resolved Hide resolved
src/bridge/command.rs Outdated Show resolved Hide resolved
src/bridge/command.rs Outdated Show resolved Hide resolved
src/bridge/command.rs Outdated Show resolved Hide resolved
src/bridge/setup.rs Outdated Show resolved Hide resolved
@falcucci falcucci self-assigned this Mar 12, 2024
@falcucci falcucci added the macos Specific to macOS and not investigable on other platforms label Mar 12, 2024
- add a new file `lua/cmd.lua`
- initialize `args` as a table
- set `vim.g.cmd` to `args.cmd`
- create an autocmd for `vimenter`
- import `cmd_lua` from `cmd.lua` in `mod.rs`
- add functions `handle_command_arg` and `handle_arg_as_path_or_default`
- comment on the setup conditions in `setup_tty_startup_directory`
- use the `command` module in `setup_tty_startup_directory`
- remove redundant code in `setup_tty_startup_directory`
- execute `cmd.lua` in `neovim.exec_lua`
- add macos-specific condition for `handle_command_arg` function
- add macos-specific condition for `handle_arg_as_path_or_default` function
- change the function name from `handle_arg_as_path_or_default` to `handle_command_arg_as_path_or_default`
- modify `build_login_cmd_args` function to properly handle and join command arguments
- update `exec` variable to include joined command and args without additional join statement
- remove the `cmd_lua` constant from `mod.rs`
- replace `nvim.exec_lua` with `nvim.command` in `mod.rs`
src/bridge/command.rs Outdated Show resolved Hide resolved
src/bridge/command.rs Outdated Show resolved Hide resolved
@Kethku
Copy link
Member

Kethku commented Mar 22, 2024

The last thing that stands out to me is a bit of a nitpick, but theres enough macos specific code here that I wonder if those functions should get pulled out into their own module that is conditionally compiled as a group. Up to you

- fix the condition for `is_tty` in `platform_which` function
- change the variable name `neovide_tty` to `neovide_ntty` in `handle_command_arg_as_path_or_default` function
- update the condition in the comment for `setup_tty_startup_directory` function
- in `setup_neovide_specific_state` function, change the variable name from `neovide_tty` to `neovide_ntty`
@falcucci
Copy link
Member Author

@Kethku regarding to the macOS specific code I strongly agree. I suggest we create a specific technical issue for that so we can split it up all together in another PR so we can review that separately.

I like the idea of platform tree structure just like winit did here

src/bridge/mod.rs Outdated Show resolved Hide resolved
src/bridge/mod.rs Outdated Show resolved Hide resolved
src/bridge/mod.rs Show resolved Hide resolved
- modify the `neovim_ok` function to handle command output differently
- remove the `tty_startup_directory` constant from `mod.rs`
- update the `setup_tty_startup_directory` function to use the `home` directory instead of `tty_startup_directory`
- update the `get_startup_directory` function to use the `home` directory instead of `tty_startup_directory`
@Kethku
Copy link
Member

Kethku commented Mar 24, 2024

@Kethku regarding to the macOS specific code I strongly agree. I suggest we create a specific technical issue for that so we can split it up all together in another PR so we can review that separately.

I like the idea of platform tree structure just like winit did here

#2439

@fredizzimo fredizzimo merged commit afed2aa into main Mar 29, 2024
16 checks passed
@fredizzimo
Copy link
Member

Thanks you!

@falcucci
Copy link
Member Author

falcucci commented Apr 14, 2024

NOTE: the custom startup dir feature has been reverted due to possible macOS incompatibilities or bugs to determine the non-tty instance of itself. This feature is not also desirable as neovide should always be launched and recognized as non-tty as default.

Some specific nvim commands regressions were also found during the usability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macos Specific to macOS and not investigable on other platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: launch neovide as --cwd $HOME if not given directory path on macOS
3 participants