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

Bring back some way to enable hybrid sync and async plugins #2407

Open
2 of 3 tasks
dawsers opened this issue Feb 27, 2025 · 3 comments
Open
2 of 3 tasks

Bring back some way to enable hybrid sync and async plugins #2407

dawsers opened this issue Feb 27, 2025 · 3 comments
Labels
feature New feature request

Comments

@dawsers
Copy link

dawsers commented Feb 27, 2025

yazi --debug output

Yazi
    Version: 25.2.26 (6b0a530 2025-02-26)
    Debug  : false
    Triple : x86_64-unknown-linux-gnu (linux-x86_64)
    Rustc  : 1.85.0 (4d91de4e 2025-02-17)

Ya
    Version: 0.3.3 (81ce040 2024-11-06)

Emulator
    TERM                : Some("xterm-kitty")
    TERM_PROGRAM        : None
    TERM_PROGRAM_VERSION: None
    Brand.from_env      : Some(Kitty)
    Emulator.detect     : Emulator { kind: Left(Kitty), light: false, cell_size: Some((11, 25)) }

Adapter
    Adapter.matches: Kgp

Desktop
    XDG_SESSION_TYPE           : Some("wayland")
    WAYLAND_DISPLAY            : Some("wayland-1")
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: Some("882f7ad7d2bbfc7440d0ccaef93b1cdd78e8e3ff_1740648054_265186191")
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL           : Some("/usr/bin/bash")
    EDITOR          : Some("/usr/bin/nvim")
    VISUAL          : Some("/usr/bin/nvim")
    YAZI_FILE_ONE   : None
    YAZI_CONFIG_HOME: None
    YAZI_ZOXIDE_OPTS: None
    FZF_DEFAULT_OPTS: Some("--no-mouse --height 50% -1 --reverse --multi --inline-info --preview=\'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (bat --color always {} || cat {}) 2> /dev/null | head -300\' --preview-window=\'up:70%:hidden:wrap\' --bind=\'f3:toggle-preview\'")

Text Opener
    default     : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR (block)", for_: None, spread: true })
    block-create: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR (block)", for_: None, spread: true })
    block-rename: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR (block)", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file          : 5.46
    ueberzugpp    : No such file or directory (os error 2)
    ffmpeg/ffprobe: 7.1 / 7.1
    pdftoppm      : 25.02.0
    magick        : 7.1.1-44
    fzf           : 0.60.2
    fd/fdfind     : 10.2.0 / No such file or directory (os error 2)
    rg            : 14.1.1
    chafa         : 1.14.5
    zoxide        : 0.9.7
    7zz/7z        : No such file or directory (os error 2) / 24.09
    jq            : 1.7.1

Clipboard
    wl-copy/paste: 2.2.1 / 2.2.1
    xclip        : No such file or directory (os error 2)
    xsel         : No such file or directory (os error 2)


See https://yazi-rs.github.io/docs/plugins/overview#debugging on how to enable logging or debug runtime errors.

Please describe the problem you're trying to solve

Before yazi 0.4, plugins could be called in synchronous or asynchronous mode.

Some functionality, like UI needs to be synchronous. Creating the UI needs to happen in sync mode because it updates global variables (like Root etc.). Trying to call any ya.manager_emit() function that updates the UI and causes redraw doesn't work in async mode (it happens in the background and the UI isn't updated correctly.

On the other hand, functions like ya.input() or Command only work in asynchronous mode.

So a plugin that wants to create some UI and also be able to interact with the user (input) and call external commands, cannot work as things are now after #1891

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

There could be several ways to add this feature without bringing back the old interface:

  1. Allow some way of calling asynchronous functions from a sync context (in the event loop)
  2. The proposed solution in feat!: deprecate --sync option for the plugin command #1891: multi-file plugins where each file can be sync or async. It seems that was a complicated solution and didn't get much traction.
  3. ...?

Additional context

I have a plugin that is not viable any more. I tried to re-write it several times in full asynchronous mode, and it doesn't work. It is either sync and some functionality won't be available (input, shell commands), or async, and then UI redraw doesn't work. Even if I put all the UI creation in ya.sync() functions, then redraw doesn't happen correctly, as the plugin is executed in the async context and the UI doesn't update correctly.

Before archiving the plugin I would like to give it a last effort if you tell me there is any solution to this.

Checklist

  • I have searched the existing issues/discussions
  • The latest nightly build doesn't already have this feature
@dawsers dawsers added the feature New feature request label Feb 27, 2025
Copy link

Hey @dawsers, I noticed that you did not correctly follow the issue template. Please ensure that:

  • The requested feature does not exist in the newest nightly build.
  • The debug information (yazi --debug) is updated for the newest nightly.
  • All required fields in the checklist have been checked.

Issues with needs info will be marked ready once edited with the proper content, or closed after 2 days of inactivity.

@sxyazi
Copy link
Owner

sxyazi commented Feb 27, 2025

I will add multi-entry support in the next release, at which point you'll be able to specify different runtimes for different plugin entry points.

In the meantime, could you let me know what kind of issues you encountered during the rewrite? I'll see if I can offer any help; a minimal reproduction of the problem would be incredibly helpful!

Here are some asynchronous plugins that involve UI rendering, which might provide some inspiration:

@sxyazi sxyazi removed the needs info label Feb 27, 2025
@dawsers
Copy link
Author

dawsers commented Feb 27, 2025

I don't know if it makes any difference, but those plugins add UI on top of Yazi's. My plugin replaces Yazi's UI by overriding Root. Does it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants