ITADN

Help needed: Unable to use `orderless` and `corfu` when using `lsp-java` without tab indentation

#486OpenWalheimat 创建于 2024-09-14
W
Walheimatcommented
**Describe the bug** When completing in a Java buffer with `corfu` and `orderless` and not using `tab-indent-mode`, auto completion always triggers immediately. The reason I open this here and not in `corfu` or `orderless` is because I only have this problem when using `lsp-java`. It might very well be the `jdtls` itself, but I'm not sure how to debug this. I first thought it was problem with `orderless-component-separator` but space indentation doesn't cause problems in any other language I've tried. Maybe there is some workaround for this. For now I'll try to not setup orderless when using `lsp-java`. **To Reproduce** Use this slightly altered version of `lsp-start-plain` to also set up corfu and orderless as well disable tabs: ```elisp (require 'package) (make-directory "/tmp/lsp-test" t) (setq debug-on-error t no-byte-compile t byte-compile-warnings nil inhibit-startup-screen t package-archives '(("melpa" . "https://melpa.org/packages/") ("gnu" . "https://elpa.gnu.org/packages/")) package-user-dir "/tmp/lsp-test" custom-file (expand-file-name "custom.el" package-user-dir)) ;; (delete-file package-user-dir) (let* ((pkg-list '(lsp-mode lsp-ui yasnippet lsp-java lsp-treemacs flycheck ;; For this problem. orderless corfu))) (package-initialize) (package-refresh-contents) (mapc (lambda (pkg) (unless (package-installed-p pkg) (package-install pkg)) (require pkg)) pkg-list) (yas-global-mode) ;; Set up orderless as per https://github.com/minad/corfu/wiki#basic-example-configuration-with-orderless (require 'orderless nil t) (setq completion-styles '(orderless partial-completion basic) completion-category-defaults nil completion-category-overrides nil) (defun my/lsp-mode-setup-completion () (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults)) '(orderless))) (add-hook 'lsp-completion-mode-hook 'my/lsp-mode-setup-completion) (setq lsp-completion-provider :none) ;; Set up corfu with auto completion. (add-hook 'prog-mode-hook 'corfu-mode) (setq corfu-auto t) ;; Don't use tabs (setq-default indent-tabs-mode nil) (add-hook 'prog-mode-hook 'lsp) ;; (add-hook 'kill-emacs-hook `(lambda () ;; (delete-directory ,package-user-dir t))) ) ``` Save the file in a directory (I use `~/.emacs.d/lsp/init.el`) and then start emacs with `emacs --init-directory ~/.emacs.d/lsp`. Find a Java file, go to some line that has some level of indentation, hit return to open a new line, type a single char: it will immediately trigger completion. Now re-enable `indent-tabs-mode`, and do the same: it will only trigger completion after three chars (the default for `corfu-auto-prefix`).
1 条评论