Fork me on GitHub
#lsp
<
2022-08-04
>
sheluchin13:08:34

move-form doesn't work consistently in my vim setup. The trace contains :move-form made no changes when it fails. Sometimes it does just work. Are there any known reasons for this kind of behaviour?

ericdallo13:08:48

Could you share a example?

sheluchin13:08:59

I think I see what happened now. I interned a var in my REPL and then used it in a defn, and when I tried to move the defn, it failed. Something like this:

(comment
  (def bar :_))

(defn baz []
  bar)

sheluchin14:08:48

I shouldn't have done that, but an error message hint would be helpful.

ericdallo16:08:12

Yeah, I think so

wsbfg17:08:05

I’m just setting up emacs on my new computer and I have an issue with clojure-lsp. When switching to a new clojure file emacs hangs for about 5 seconds. Once that file has been previously opened I can switch to it normally. It doesn’t spike CPU. When a new buffer is opened the status bar says “LSP Connected To [<whatever>]“. This is the same process each time so it’s not restarting clojure-lsp. The first time a clojure file is opened it also says “Initialized”, subsequent times do not. Disabling lsp mode fixes the behaviour. My init.el looks like this:

(add-hook 'clojure-mode-hook 'lsp)
(add-hook 'clojurescript-mode-hook 'lsp)
(add-hook 'clojurec-mode-hook 'lsp)

(setq gc-cons-threshold (* 100 1024 1024)
      read-process-output-max (* 1024 1024)
      ;lsp-lens-enable t
      ;lsp-signature-auto-activate nil
      ;lsp-enable-indentation nil ; uncomment to use cider indentation instead of lsp
      ;lsp-enable-completion-at-point nil ; uncomment to use cider completion instead of lsp
      ;lsp-enable-file-watchers nil
      )
lsp-doctor is OK profiler-report looks like:
54  38% - term-sentinel
          54  38%  - term-handle-exit
          54  38%   - apply
          54  38%    - #<compiled -0x16e678a284eb14f2>
          50  35%     - fzf/action-find-file
          50  35%      - find-file
          50  35%       - find-file-noselect
          49  35%        - find-file-noselect-1
          49  35%         - after-find-file
          46  32%          - normal-mode
          45  32%           - set-auto-mode
          44  31%            - set-auto-mode--apply-alist
          44  31%             - set-auto-mode-0
          44  31%              - clojure-mode
          44  31%               - run-mode-hooks
          43  30%                - apply
          43  30%                 - run-hooks
          43  30%                  - lsp
          21  15%                   - lsp--filter-clients
          21  15%                    - -filter
          21  15%                     - #<compiled 0x1a14b229b7ba972f>
          21  15%                      - apply
          20  14%                       - lsp--supports-buffer?
          13   9%                        - lsp-volar--activate-p
          13   9%                         - lsp-workspace-root
          13   9%                          - lsp-f-ancestor-of?
          13   9%                             lsp-f-same?
           5   3%                        - #<compiled -0x6bb516da4b18541>
           5   3%                         - lsp-buffer-language
           5   3%                          - -first
           5   3%                           - #<compiled 0x1e2d04a40da2f7dc>
           5   3%                              s-matches?
          20  14%                   - lsp--try-project-root-workspaces
          18  12%                    - lsp--find-clients
          17  12%                     - lsp--filter-clients
          17  12%                      - -filter
          17  12%                       - #<compiled 0x1a14b229b7ba972f>
          17  12%                        - apply
          16  11%                         - lsp--supports-buffer?
          13   9%                          - lsp-volar--activate-p
          11   7%                           - lsp-workspace-root
          11   7%                            - lsp-f-ancestor-of?
          11   7%                               lsp-f-same?
           1   0%                             lsp-volar--vue-project-p
           3   2%                          - #<compiled -0x4f299e7fb6fa6f8>
           3   2%                           - lsp-buffer-language
           3   2%                            + -first
           1   0%                         - lsp--server-binary-present?
           1   0%                          - #<compiled 0x1fdd2cae7fd5>
           1   0%                           + lsp-clojure--server-executable-path
           1   0%                     - -map
           1   0%                      - mapcar
           1   0%                         #<compiled 0x1a7cfec8f69d2216>
           1   0%                    - lsp--calculate-root
           1   0%                     - lsp-find-session-folder
           1   0%                     - lsp-find-session-folder
           1   0%                        lsp-f-same?
           1   0%                    - lsp--ensure-lsp-servers
           1   0%                     - -map
           1   0%                      - mapcar
           1   0%                       - #<compiled 0x16038d054b21571a>
           1   0%                        - lsp--find-workspace
           1   0%                         - lsp--open-in-workspace
           1   0%                            lsp--text-document-did-open
           1   0%                   - lsp-find-session-folder
           1   0%                      lsp-f-same?
           1   0%                   - lsp--auto-configure
           1   0%                      add-hook
           1   0%                + run-hooks
           1   0%            + hack-dir-local--get-variables
           1   0%           + run-hooks
           3   2%          + run-hooks
           1   0%          find-buffer-visiting
           3   2%     - split-string
           3   2%        #<compiled -0x4950b36e725e83b>
          28  20% - command-execute
          28  20%  - call-interactively
          17  12%   + byte-code
          11   7%   - funcall-interactively
           5   3%    + execute-extended-command
           4   2%    + fzf
           1   0%    + term-send-raw
           1   0%    + evil-force-normal-state
          21  15% - term-emulate-terminal
          11   7%    redisplay
           2   1%  - vertical-motion
           2   1%   - jit-lock-function
           2   1%      jit-lock-fontify-now
           2   1%    split-string
          13   9% + redisplay_internal (C function)
          13   9% - timer-event-handler
          13   9%  - apply
           9   6%   + lsp--on-idle
           2   1%   + #<compiled -0x15e4a041019d7138>
           1   0%   - lsp-lens-refresh
           1   0%    - lsp-lens--backend
           1   0%     - #<compiled -0x1de9a9530c569b15>
           1   0%      - lsp-lens--process
           1   0%       - lsp-lens--display
           1   0%        - -map
           1   0%         - mapcar
           1   0%          - #<compiled 0x16ab61a178b5449c>
           1   0%             s-join
           1   0%     #<compiled 0x12cd0f47320ce376>
           9   6% + #<compiled 0x10271edba40b7524>
           2   1% + ...
Toggling debug on quit I get this from during the hang:
Debugger entered--Lisp error: (quit)
  turn-on-font-lock-if-desired()
  global-font-lock-mode-enable-in-buffers()
  run-hooks(after-change-major-mode-hook)
  run-mode-hooks(clojure-mode-hook)
  clojure-mode()
  set-auto-mode-0(clojure-mode nil)
  set-auto-mode--apply-alist((("\\(?:build\\|profile\\)\\.boot\\'" . clojure-mode) ("\\.cljs\\'" . clojurescript-mode) ("\\.cljc\\'"$
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer utils.clj> "~/workspace/dso-smoke-tests/src/dso_test/utils.clj" nil nil "~/workspace/dso-smoke-tests$
  find-file-noselect("/Users/ben/workspace/dso-smoke-tests/src/dso_test/..." nil nil nil)
  find-file("/Users/ben/workspace/dso-smoke-tests/src/dso_test/...")
  fzf/action-find-file("/Users/ben/workspace/dso-smoke-tests/src/dso_test/...")
  #f(compiled-function (_ msg) #<bytecode -0x173e6b06304614f2>)("fzf" "finished\n")
  apply(#f(compiled-function (_ msg) #<bytecode -0x173e6b06304614f2>) ("fzf" "finished\n"))
  term-handle-exit("fzf" "finished\n")
  term-sentinel(#<process fzf> "finished\n")
I’m pretty stuck and I would hugely appreciate any ideas on what to try 🙂

ericdallo17:08:18

Kind of curious about that fzf/action-find-file on your profiler, that looks odd

ericdallo17:08:45

Never saw that kind of slowness even before clojure-lsp process was requested to start.

wsbfg17:08:29

That’s a fuzzy finder that I used to open the file. So I don’t think it’s related to the slowness (given that it’s fine to use when lsp-mode is disabled). I just think that’s all the profiler picked up on - which is also really strange!

wsbfg17:08:58

I did notice in the *lsp-clojure* log that it took 956ms for a response to be received during initialisation. That seems a bit long to me but it could very well be normal.

ericdallo17:08:13

could be a issue during the find of the project root...

ericdallo17:08:26

oh yeah, how did you install and what's your clojure-lsp version?

wsbfg17:08:39

I installed clojure-lsp via brew. Versions are:

clojure-lsp 2022.07.24-18.25.43
clj-kondo 2022.06.23-SNAPSHOT
lsp-mode in emacs was latest installed fresh a few hours ago.

wsbfg17:08:38

project is a lein project in this case with a .project file in the root. It’s also a simple and tiny project for what that’s worth (I’m testing on this as it’s the smallest project I have)

ericdallo18:08:23

yeah, I meant the lsp-mode projects, check that with lsp-workspace-folders-remove , it should show all projects lsp-mode imported before

wsbfg18:08:50

Yes you are absolutely right! That contained a whole heap of broken references to projects on my old computer. Turns out there was a hidden file in my emacs config that contained them. Deleting that has fixed the issue. That’s amazing thank you so much for your help! Out of interest did you see something in the traces that made you suspect that or just experience?

ericdallo18:08:41

Great! A little bit of both I guess 😅 lsp--try-project-root-workspaces made me guess multiple projects or wrong project root could cause that

wsbfg18:08:59

Fantastic. We’ll you’ve saved my evening! Thanks again 😄

ericdallo18:08:16

You're welcome, have a happy code :)