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

LSP mode with imenu does not show Python classes/functions properly #2246

Open
dmalyuta opened this issue Oct 12, 2020 · 1 comment
Open

Comments

@dmalyuta
Copy link

(The original question was posted on stack exchange: https://emacs.stackexchange.com/q/61141/13661)

I am using Emacs 27.1 with the latest versions of all packages. My LSP-related setup is:

(use-package lsp-pyright
  :ensure t
  :hook (python-mode . (lambda ()
                         (require 'lsp-pyright)
                         (lsp))))  ; or lsp-deferred

(use-package lsp-mode
  :ensure t
  :init
  (setq lsp-keymap-prefix "C-c l")
  :config
  (require 'lsp-mode)
  (add-hook 'python-mode-hook #'lsp)
  (add-hook 'c-mode-common-hook #'lsp)
  (require 'company-capf)
  (setq lsp-prefer-capf t)
  (push 'company-capf company-backends)
  (push 'company-c-headers company-backends)
  (setq lsp-idle-delay 0.500)
  (setq lsp-diagnostic-package :none)
  (add-hook 'lsp-mode-hook (lambda ()
			     (setq company-minimum-prefix-length 1
				   company-idle-delay 0.0)))
  (setq lsp-enable-semantic-highlighting t)
  (setq lsp-enable-snippet nil)  ;; Enable arguments completion
  (setq lsp-signature-auto-activate nil)
  (setq lsp-progress-via-spinner nil)
  )

(use-package lsp-ui
  :ensure t
  :config
  (add-hook 'lsp-mode-hook
	    (lambda ()
	      (setq lsp-ui-doc-enable nil ;; disable docs
		    ;; lsp-ui-doc-delay 1
   		    ;; lsp-ui-doc-use-childframe t
   		    lsp-ui-doc-position 'bottom
		    lsp-ui-doc-max-height 20
   		    lsp-ui-doc-include-signature t

   		    lsp-ui-sideline-enable t
		    lsp-ui-sideline-delay 0.2
		    lsp-ui-sideline-show-code-actions nil
		    lsp-ui-sideline-show-hover nil

   		    lsp-ui-flycheck-enable t
   		    lsp-ui-flycheck-list-position 'right
   		    lsp-ui-flycheck-live-reporting t

		    lsp-ui-peek-enable nil
   		    ;; lsp-ui-peek-list-width 60
   		    ;; lsp-ui-peek-peek-height 25

		    lsp-ui-imenu-enable nil
		    )
	      (local-set-key (kbd "C-c l i") 'lsp-ui-imenu)
	      ))
  )

I feel like something is wrong with my Imenu setup, because here is what it shows on a simple Python script:

image

It seems to show some variable definitions, but doesn't have separate entries for the function definitions (the def ... lines), or the classes. What I want is an Imenu that shows just the function and class definitions, in the order in which they appear. So, I want to see something like:

Function: foo(x)
Class: Bar
Function: Bar / __init__(s)
Function: Bar / buz(x, y)

Is that possible at all? Semantic is not an option because it does not parse functions that are typed using Python's type annotations (e.g. a function like def foo() -> None: ... does not appear in the list).

@nbfalcon
Copy link
Member

nbfalcon commented Nov 8, 2020

Currently it isn't, but I made a PR to fix that.

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

No branches or pull requests

2 participants