Flimenu provides functions to flatten imenu indexes and a mode to apply those functions automatically.
Install from MELPA (coming soon) with M-x package-install flimenu
. See the melpa repository for details about how to set up MELPA if you have not already done so.
(require 'flimenu)
(setq flimenu-ignore-modes-list 'my-mode-where-things-shouldnt-be-active)
(flimenu-global-mode)
(use-package flimenu
:config
(progn
(setq flimenu-ignore-modes-list 'my-mode-where-things-shouldnt-be-active)
(flimenu-global-mode)))