Skip to content

Commit 390a6a5

Browse files
committed
Provide prefix function
1 parent 5755472 commit 390a6a5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lsp-javacomp.el

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ The current directory is assumed to be the java project’s root otherwise."
7979
(or (seq-some (lambda (file) (locate-dominating-file default-directory file)) project-types)
8080
default-directory))))))
8181

82+
(defun lsp-javacomp--get-prefix ()
83+
"Get prefix for completion.
84+
85+
Return a cons of (start . end) for the bound of the prefix."
86+
(let* ((bound (bounds-of-thing-at-point 'symbol))
87+
(start (or (and bound (car bound)) (point)))
88+
(end (or (and bound (cdr bound)) (point))))
89+
;; java-mode considers '@' as a symbol constituent. However JavaComp doesn't
90+
;; take the leading '@' as part of the prefix. Remove the leading '@' from
91+
;; the prefix.
92+
(when (and (< start end) (char-equal (char-after start) ?@))
93+
(setq start (1+ start)))
94+
(cons start end)))
95+
8296
;;;###autoload
8397
(defun lsp-javacomp-install-server (&optional prompt-exists)
8498
"Download the JavaComp server JAR file if it does not exist.
@@ -127,7 +141,8 @@ See https://developer.github.com/v3/repos/releases/#get-the-latest-release
127141
(lsp-define-stdio-client lsp-javacomp "java" #'lsp-javacomp--get-root nil
128142
:command-fn #'lsp-javacomp--command
129143
:ignore-regexps '("^SLF4J: "
130-
"^Listening for transport dt_socket at address: "))
144+
"^Listening for transport dt_socket at address: ")
145+
:prefix-function #'lsp-javacomp--get-prefix)
131146

132147
(provide 'lsp-javacomp)
133148
;;; lsp-javacomp.el ends here

0 commit comments

Comments
 (0)