Skip to content

get_hint() returns nil for pink hydras due to util.deepcopy breaking _G.Hydra assignment #71

Description

@jeanprbt

Description

require("hydra.statusline").get_hint() returns nil for pink hydras, even though is_active() returns true.

Root cause

In commits 394744a / f4ad21b ("fix: tbl_deep_extend error"), vim.tbl_deep_extend('force', getfenv(), {...}) was replaced with util.deepcopy(getfenv()) in lua/hydra/layer/init.lua to fix compatibility with newer Neovim versions.

The problem is that util.deepcopy deep-copies the self-referencing _G key in the environment table (using seen to handle cycles), creating a new table. When setfenv is then applied to the on_enter callbacks, the function that does _G.Hydra = self writes to the copied _G, not the real global table.

Previously, vim.tbl_deep_extend only created new sub-tables for overlapping keys (vim.o, vim.bo, etc.) — _G stayed as a reference to the real global table, so _G.Hydra = self worked correctly.

Commit 8c4a9f6 ("fix: allow layers to have names and trigger status line active function") partially addressed this by adding _G.active_keymap_layer fallbacks to is_active(), get_name(), and get_color() — but get_hint() was missed.

Suggested fix

Store the Hydra reference on the Layer, and use it as a fallback in get_hint():

lua/hydra/init.lua — in _setup_pink_hydra(), after creating the Layer:

self.layer = Layer(layer)
self.layer._hydra = self  -- expose Hydra instance on Layer

lua/hydra/statusline.lua — update get_hint():

function statusline.get_hint()
   local hydra = _G.Hydra or (_G.active_keymap_layer and _G.active_keymap_layer._hydra)
   if not hydra then return end
   local hint_type = hydra.config.hint and hydra.config.hint.type
   if hydra.config.hint == false or hint_type == "statuslinemanual" or hint_type == "statusline" then
      return hydra.hint:show(true)
   end
end

Reproduction

  1. Create a pink Hydra with hint.type = "statuslinemanual"
  2. Activate it
  3. Call require("hydra.statusline").get_hint() → returns nil
  4. Call require("hydra.statusline").is_active() → returns true

Environment

  • Neovim 0.11+
  • hydra.nvim commit 8c4a9f6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions