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

debug adapter: running under zellij prints out a tmux error (but it works under tmux, and under no multiplexer?) #1699

Closed
colemickens opened this issue Feb 22, 2022 · 2 comments
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@colemickens
Copy link

Reproduction steps

I'm testing head of Helix on NixOS with codelldb. I'm making some progress, and I think I even "have it working" when I run helix under tmux.

However, when I run hx under zellij and start the debug process, when the DAP calls to run in terminal, it tries to execute tmux, and fails with this getting dumped into the open zellij buffer:

error connecting to /run/user/1000/tmux-1000/default (No such file or directory)

Strangely, if I execute hx outside of zellij and tmux, it seems to work (the process just seems to open in the background [or maybe another buffer, I'm not sure]).

My tmux config is:

[cole@porty:~/code/zellij]$ cat ~/.config/tmux/tmux.conf
# ============================================= #
# Start with defaults from the Sensible plugin  #
# --------------------------------------------- #
run-shell /nix/store/y2ipj5pb7309p09gz5i9mla87cspkdb0-tmuxplugin-sensible-unstable-2017-09-05/share/tmux-plugins/sensible/sensible.tmux
# ============================================= #

set  -g default-terminal "screen"
set  -g base-index      0
setw -g pane-base-index 0

new-session



set -g status-keys vi
set -g mode-keys   vi







setw -g aggressive-resize off
setw -g clock-mode-style  12
set  -s escape-time       0
set  -g history-limit     100000

set -g mouse on

[cole@porty:~/code/zellij]$ cat /nix/store/y2ipj5pb7309p09gz5i9mla87cspkdb0-tmuxplugin-sensible-unstable-2017-09-05/share/tmux-plugins/sensible/sensible.tmux
#!/nix/store/4nmqxajzaf60yjribkgvj5j54x9yvr1r-bash-5.1-p12/bin/bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# used to match output from `tmux list-keys`
KEY_BINDING_REGEX="bind-key[[:space:]]\+\(-r[[:space:]]\+\)\?\(-T prefix[[:space:]]\+\)\?"

is_osx() {
        local platform=$(uname)
        [ "$platform" == "Darwin" ]
}

iterm_terminal() {
        [[ "$TERM_PROGRAM" =~ ^iTerm ]]
}

command_exists() {
        local command="$1"
        type "$command" >/dev/null 2>&1
}

# returns prefix key, e.g. 'C-a'
prefix() {
        tmux show-option -gv prefix
}

# if prefix is 'C-a', this function returns 'a'
prefix_without_ctrl() {
        local prefix="$(prefix)"
        echo "$prefix" | cut -d '-' -f2
}

option_value_not_changed() {
        local option="$1"
        local default_value="$2"
        local option_value=$(tmux show-option -gv "$option")
        [ "$option_value" == "$default_value" ]
}

server_option_value_not_changed() {
        local option="$1"
        local default_value="$2"
        local option_value=$(tmux show-option -sv "$option")
        [ "$option_value" == "$default_value" ]
}

key_binding_not_set() {
        local key="$1"
        if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then
                return 1
        else
                return 0
        fi
}

key_binding_not_changed() {
        local key="$1"
        local default_value="$2"
        if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
                # key still has the default binding
                return 0
        else
                return 1
        fi
}

main() {
        # OPTIONS

        # enable utf8 (option removed in tmux 2.2)
        tmux set-option -g utf8 on 2>/dev/null

        # enable utf8 in tmux status-left and status-right (option removed in tmux 2.2)
        tmux set-option -g status-utf8 on 2>/dev/null

        # address vim mode switching delay (http://superuser.com/a/252717/65504)
        if server_option_value_not_changed "escape-time" "500"; then
                tmux set-option -s escape-time 0
        fi

        # increase scrollback buffer size
        if option_value_not_changed "history-limit" "2000"; then
                tmux set-option -g history-limit 50000
        fi

        # tmux messages are displayed for 4 seconds
        if option_value_not_changed "display-time" "750"; then
                tmux set-option -g display-time 4000
        fi

        # refresh 'status-left' and 'status-right' more often
        if option_value_not_changed "status-interval" "15"; then
                tmux set-option -g status-interval 5
        fi

        # required (only) on OS X
        if is_osx && command_exists "reattach-to-user-namespace" && option_value_not_changed "default-command" ""; then
                tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL"
        fi

        # upgrade $TERM, tmux 1.9
        if option_value_not_changed "default-terminal" "screen"; then
                tmux set-option -g default-terminal "screen-256color"
        fi
        # upgrade $TERM, tmux 2.0+
        if server_option_value_not_changed "default-terminal" "screen"; then
                tmux set-option -s default-terminal "screen-256color"
        fi

        # emacs key bindings in tmux command prompt (prefix + :) are better than
        # vi keys, even for vim users
        tmux set-option -g status-keys emacs

        # focus events enabled for terminals that support them
        tmux set-option -g focus-events on

        # super useful when using "grouped sessions" and multi-monitor setup
        if ! iterm_terminal; then
                tmux set-window-option -g aggressive-resize on
        fi

        # DEFAULT KEY BINDINGS

        local prefix="$(prefix)"
        local prefix_without_ctrl="$(prefix_without_ctrl)"

        # if C-b is not prefix
        if [ $prefix != "C-b" ]; then
                # unbind obsolete default binding
                if key_binding_not_changed "C-b" "send-prefix"; then
                        tmux unbind-key C-b
                fi

                # pressing `prefix + prefix` sends <prefix> to the shell
                if key_binding_not_set "$prefix"; then
                        tmux bind-key "$prefix" send-prefix
                fi
        fi

        # If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows.
        # Works for any prefix character.
        if key_binding_not_set "$prefix_without_ctrl"; then
                tmux bind-key "$prefix_without_ctrl" last-window
        fi

        # easier switching between next/prev window
        if key_binding_not_set "C-p"; then
                tmux bind-key C-p previous-window
        fi
        if key_binding_not_set "C-n"; then
                tmux bind-key C-n next-window
        fi

        # source `.tmux.conf` file - as suggested in `man tmux`
        if key_binding_not_set "R"; then
                tmux bind-key R run-shell ' \
                        tmux source-file ~/.tmux.conf > /dev/null; \
                        tmux display-message "Sourced .tmux.conf!"'
        fi
}
main

@colemickens colemickens added the C-bug Category: This is a bug label Feb 22, 2022
@archseer
Copy link
Member

runInTerminal still needs some work, I had it hardcoded to use tmux split-window while testing:

let process = std::process::Command::new("tmux")
.arg("split-window")
.arg(arguments.args.join(" ")) // TODO: first arg is wrong, it uses current dir
.spawn()
.unwrap();

We should make this configurable in config.toml: editor.terminal = { cmd = "tmux", args = ["split-window"] }

@kirawi kirawi added the A-helix-term Area: Helix term improvements label Feb 24, 2022
@schoenenberg
Copy link
Contributor

I just tried out the debugging adapter and got always the error No such file or directory. It took me some time to find out, that not the debug executable is meant by that, but tmux 😆

I would also prefer to use my usual multiplexer (zellij), but for now it should be atleast somewhere in the docs, that tmux is required for debug. Or maybe catch the unwrap() in https://github.com/helix-editor/helix/blob/master/helix-view/src/handlers/dap.rs#L314.

AlexanderBrevig pushed a commit to AlexanderBrevig/helix that referenced this issue Aug 29, 2022
thomasskk pushed a commit to thomasskk/helix that referenced this issue Sep 9, 2022
thomasskk pushed a commit to thomasskk/helix that referenced this issue Sep 9, 2022
jdrst pushed a commit to jdrst/helix that referenced this issue Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

4 participants