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):
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?
company-dabbrev-code
withcompany-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.company-dabbrev-code
withcompany-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 theuse-package company
to ` (add-to-list 'company-backends(company-capf :with company-dabbrev-code)))