0

I have a configuration for Java code on emacs that's the following:

(use-package flycheck
  :ensure t
  :config
  (global-flycheck-mode))

(use-package company
  :ensure t
  :hook (after-init . global-company-mode)
  :config
  (setq company-tooltip-align-annotations t
        company-minimum-prefix-length 1
        company-idle-delay 0.0)
  (with-eval-after-load 'lsp-mode
    (add-hook 'lsp-mode-hook #'company-mode))
  (add-to-list 'company-backends 'company-capf))

(use-package lsp-java
  :ensure t
  :hook (java-mode . lsp)
  :config
  (customize-set-variable 'lsp-java-server-install-dir "~/Documents/jdt-language-server/")
  (require 'lsp-java))

It works fine with the flycheck for errors and the company mode shows recommendations of functions in Java. I'm using the Eclipse JDT language server (Milestone build 1.9.0):

enter image description here

However, it doesn't recognize classes that I create in my project, so I'm not able to type and see recommendations of the classes and functions I have developed in my project. Am I missing any detail in my configuration? I've started to think that the language server I'm using in Java doesn't have this functionality since it works pretty fine with the TypeScript language server that I'm using... Is there any way of making Company recommend to me Java classes from my Java project?

3
  • I suppose the first step would be to report the problem to Eclipse.
    – Dmitry
    Commented Apr 20, 2023 at 21:56
  • 2
    Then, while you're waiting for a response, you could either try grouping company-dabbrev-code with company-capf to add all-symbols-in-all-buffers completions, or write a new backend of your own. Maybe search around for existing reports in lsp-java, etc.
    – Dmitry
    Commented Apr 20, 2023 at 21:58
  • 1
    @Dmitry Thanks! I didn't manage to create a new backend but grouping company-dabbrev-code with company-campf worked fine for me. Even though it works only when the file I want recommendations is open in a buffer. In practice, I only changed the last line of the use-package company to ` (add-to-list 'company-backends (company-capf :with company-dabbrev-code)))
    – raylight
    Commented Apr 24, 2023 at 0:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.