emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.03k stars 141 forks source link

Hover on comment / function doc selects bigger scope & so Emacs hangs in the big Haskell files #653

Closed Anton-Latukha closed 2 years ago

Anton-Latukha commented 2 years ago

Headpost updates to the current status results of the discussion

Previous thread: https://github.com/haskell/haskell-mode/issues/1764

There seems to be a bug of a computational data spike during the hover on the comment.

It probably may not be 100% a lsp-ui/lsp-ui-doc bug, but an intercommunication between several projects, lsp-ui-doc it is the closest entity I found currently.

I have 100% reproducible hang in largish (~>1kLoC) Haskell files - directly in the moment of hovering over comments.

Observe syndrome behaviour

Smaller file

![1](https://user-images.githubusercontent.com/20933385/132835407-434d95dc-f5a0-4809-b541-176e257b43a6.gif)
Bigger file

Sorry for the somewhat longish GIF file, it took numerous attempts of initial selection positioning (to not hang Emacs right away) and so numerous Emacs restarts to somewhat properly record and show this behavior. ![2](https://user-images.githubusercontent.com/20933385/132851914-88ac5359-0eb1-4d67-9943-e85393f1b78e.gif) My symbol map (`pretty-symbols-mode`) does not matter - the hang happens regardless of it.

So Emacs hangs on selecting comments on big files. During hover over any comment - lsp-ui tries to select the whole file (if module head doc is selected, and whole module if function doc is selected) & overflows Emacs function with data & their computations, and there is a small size point (~1kLoC) and so never calculates data and so never arrives to spawn the minibuffer.

Debugging information:

I have small Emacs skill, but would try to pinpoint the issue to: It happens between:

Profiler trace

``` 1293 58% - redisplay_internal (C function) 1276 57% - eval 1191 54% - spaceline-ml-main 925 41% - -difference 925 41% - let 925 41% - let 925 41% - while 925 41% - setq 925 41% - car-safe 925 41% - prog1 922 41% - helm-execute-selection-action-1 922 41% - let 836 37% - if 453 20% - progn 453 20% - funcall 446 20% - # 446 20% - save-current-buffer 446 20% - apply 446 20% - # 446 20% - save-excursion 446 20% - let 446 20% - lsp-ui-doc--callback 446 20% - let* 446 20% - let 446 20% - if 446 20% - progn 446 20% - lsp-ui-doc--display 248 11% - let 242 10% - let 239 10% - let 239 10% - if 239 10% - progn 239 10% - lsp-ui-doc--extract 239 10% - apply 239 10% - # 239 10% - cond 239 10% - lsp-ui-doc--extract-marked-string 235 10% - string-trim-right 235 10% - let* 235 10% - cond 235 10% - lsp--render-string 229 10% - let* 229 10% - if 229 10% - lsp--fontlock-with-mode 229 10% - let 229 10% - condition-case 229 10% - let 229 10% - save-current-buffer 229 10% - unwind-protect 229 10% - progn 141 6% - progn 141 6% - let 141 6% - funcall 141 6% + lsp--render-markdown 51 2% + let* 34 1% + lsp--buffer-string-visible 3 0% + lsp-ui-doc--inline-formatted-string 3 0% + setq 3 0% + if 6 0% + if 181 8% + if 17 0% thing-at-point 7 0% + helm-M-x-execute-command 380 17% - apply 354 16% - helm-internal 354 16% - let 354 16% - unwind-protect 354 16% - condition-case 354 16% - let 354 16% - unwind-protect 267 12% - helm-cleanup 264 11% - helm-frame-or-window-configuration 264 11% - let 264 11% - cond 264 11% - let* 260 11% - unwind-protect 260 11% - progn 257 11% - condition-case 257 11% - let 257 11% - catch 257 11% - let 257 11% - setq 257 11% - or 257 11% - progn 257 11% - let* 257 11% - let* 146 6% + cond 54 2% + sp--get-closing-regexp 51 2% + sp--get-allowed-pair-list 6 0% + and 3 0% select-frame-set-input-focus 4 0% + markdown-code-block-at-pos 3 0% + helm-log-run-hook 87 3% + helm-read-from-minibuffer 26 1% + # 3 0% + lsp-ui-doc--resize-buffer 72 3% + helm-process-filtered-candidate-transformer 14 0% + lsp-headerline--build-file-string 3 0% setq 32 1% + powerline-raw 30 1% + spaceline--get-face 17 0% + powerline-buffer-id 16 0% + powerline-render 15 0% + powerline-width 14 0% file-remote-p 13 0% + eyebrowse--get 13 0% + spaceline--mode-line-nonempty 7 0% + powerline-hud 7 0% + powerline-wave-left 6 0% + winum-get-number 4 0% + powerline-wave-right 61 2% + spacemacs/title-prepare 17 0% + # 548 24% - ... 483 21% - markdown-fontify-code-block-natively 483 21% - let 483 21% - if 483 21% - progn 483 21% - let 483 21% - save-current-buffer 483 21% - font-lock-ensure 483 21% - # 483 21% - font-lock-fontify-region 483 21% - font-lock-default-fontify-region 483 21% - font-lock-fontify-keywords-region 479 21% - markdown-fontify-gfm-code-blocks 479 21% - markdown-fontify-code-blocks-generic 479 21% - if 479 21% - progn 479 21% - save-excursion 479 21% - let 479 21% - unwind-protect 479 21% - progn 479 21% - let* 472 21% - if 459 20% - markdown-fontify-code-block-natively 459 20% - let 459 20% - if 455 20% - progn 455 20% - let 445 20% - save-current-buffer 264 11% + font-lock-ensure 139 6% + let 30 1% + while 3 0% + set-buffer 4 0% + markdown-get-lang-mode 13 0% + and 4 0% + progn 3 0% + font-lock-append-text-property 4 0% + rainbow-delimiters--propertize 59 2% Automatic GC 6 0% + sp--looking-back-p 196 8% + timer-event-handler 37 1% + evil--jump-hook 24 1% + command-execute 21 0% + jit-lock--antiblink-post-command 19 0% + # 18 0% + lsp-ui-sideline 10 0% + evil-repeat-pre-hook 7 0% + company-pre-command 7 0% + evil--jump-handle-buffer-crossing 6 0% + winner-save-old-configurations 6 0% + lsp--post-command 3 0% global-flycheck-mode-check-buffers 3 0% + sp--post-command-hook-handler 3 0% + global-hl-line-highlight 3 0% + evil-normal-post-command ```

So far despite of efforts, I can not track the problem deeper. From all modes (packages) mentioned, only when the mode is turned off - then Emacs works normally in large Haskell files, but at that point - there is no Haskell functionality there.

An example of a project/file when it happens 100% of the time is - https://github.com/haskell-nix/hnix Nix.Expr.Types module, but got the hang in other big Haskell files also.

What we can do to observe the problem more closely, and stop lsp-ui/lsp-ui-doc from selecting, in Haskell files and maybe others, almost the whole file while the mouse or keyboard hovers on comments.

Anton-Latukha commented 2 years ago

On hover (with mouse or keyboard) on function/module documentation/comments - the selection is plainly should be fixed, since selection selects the scope one lever higher than it should.

Anton-Latukha commented 2 years ago

Further going to try to get result bisecting on lsp-ui/lsp-ui-doc, but you may not hold the horses, since I've seen that lsp-ui-doc had wide changes on selections recently, and my experience correlates with those changes.

Anton-Latukha commented 2 years ago

Well, it is HLS (Haskell Language Server) problem. I've tracked it down into it, in other editors - the selection behavior is the same.