syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.58k stars 4.9k forks source link

Pressing TAB to autocomplete on java makes the whole editor freeze (company capf timeout) #16304

Closed resendecode closed 1 week ago

resendecode commented 4 months ago

I am needing help coding in java with spacemacs. I finally got the autocomplete working by downloading the eclipse jdtls version 1.33 and specifying its path: (lsp :variables lsp-java-server-install-dir "~/myjdtls" )

In the following annexed video, I start typing the name of a variable and then hit TAB to trigger the autocomplete. Now, as you can see in the video, the pop up suggestions work but as soon as i hit Tab, the editor freezes. I then go into the the messages log to show the error messages I obtain: (accidentally stop at the lsp-log buffer instead of going directly into the error message) emacs java error.webm

WHAT I'VE TRIED Not specifying the lsp server path just makes my autocomplete functionality disappear for java Choosing Meghanada also seems clunky and not as polished. I just wish I didn't have this happen because it still is very enjoyable. If I'm posting this in the wrong place or you need further information, please let me know. Thank you for reading.

smile13241324 commented 3 weeks ago

Hi @resendecode,

I am working with jdtls as well and its working most of the time, I sometimes also have mysterious freezes and company-capf timeouts but this only happens occasionally. Upgrading my lsp server to the latest version and upgrading lsp-mode also lowered the frequency of these issues.

Ok with this being said, lets try some troubleshooting. First I would like to have your system details this is the content of what spacemacs/report-issue returns to you.

Then we should make sure that your config is proper. Here is my java config:

     (java :variables
      java-backend 'lsp)

As you see I do not have given any path, instead lsp-mode asked me to install jdtls which it will then do into your spacemacs directory. Also you should make sure you configure the java settings, the defaults are horribly underrated for a non toy lsp server.

I.e. here is what I am using in my user-config:

  ;; Setup lsp
  (defconst lsp-java-lombok-jar-path (expand-file-name
                                      (locate-user-emacs-file
                                       (f-join ".cache" "lombok.jar"))))
  (defun smile13241324/lombok-download ()
    "Download the latest Lombok JAR file and install it into `lsp-java-lombok-jar-path'."
    (interactive)
    (if (and (y-or-n-p (format "Download the latest Lombok JAR into %s? "
                               lsp-java-lombok-jar-path))
             (or (not (file-exists-p lsp-java-lombok-jar-path))
                 (y-or-n-p (format "The Lombok JAR already exists at %s, overwrite? "
                                   lsp-java-lombok-jar-path))))
        (progn
          (mkdir (file-name-directory lsp-java-lombok-jar-path) t)
          (message "Downloading Lombok JAR into %s" lsp-java-lombok-jar-path)
          (url-copy-file "https://projectlombok.org/downloads/lombok.jar" lsp-java-lombok-jar-path t))
      (message "Aborted.")))

  (defun smile13241324/setup-lsp-java-vmargs ()
    (setq lsp-java-vmargs '("-XX:+UseZGC" "-XX:+ZGenerational" "-Xmx20G" "-Xms20G" "-XX:MaxMetaspaceSize=10G" "-XX:+UseStringDeduplication"))
    (setq lsp-java-vmargs
          (append lsp-java-vmargs
                  (list (concat "-javaagent:" lsp-java-lombok-jar-path)))))

  ;; Setup lsp java with productive settings
  (setq lsp-java-jdt-download-url "https://www.eclipse.org/downloads/download.php?file=/jdtls/milestones/1.36.0/jdt-language-server-1.36.0-202405301306.tar.gz")

  ;; Setup the lsp-java vmargs
  (smile13241324/setup-lsp-java-vmargs)

When this does not solve your issue, you should execute company-diag and post the output.

smile13241324 commented 1 week ago

Closed due to inactivity