Skip to content

Commit

Permalink
fix(ltex): use ltex-ls as TCP server, add helpers
Browse files Browse the repository at this point in the history
LTeX-LS v16.0.0 is not working when launched as a STDIO stream, we
switch to TCP for communications. The server can be started or stopped
locally using `ltex-ls-start` and `ltex-ls-stop` respectively.
  • Loading branch information
abougouffa committed May 21, 2023
1 parent 51dd7b8 commit fe290c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
6 changes: 4 additions & 2 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,11 @@ Fallback to FALLBACK-RELEASE when it can't get the last one.
(register-definition-prefixes "me-defaults" '("+whitespace-auto-cleanup-modes"))


;;; Generated autoloads from ../modules/extras/me-eglot-ltex-extras.el
;;; Generated autoloads from ../modules/extras/me-eglot-ltex.el

(register-definition-prefixes "../modules/extras/me-eglot-ltex-extras" '("eglot-ltex-"))
(autoload 'ltex-ls-start "../modules/extras/me-eglot-ltex" "\
Start LTeX-LS as a TCP server at localhost:40001." t)
(register-definition-prefixes "../modules/extras/me-eglot-ltex" '("eglot-ltex-" "ltex-ls-"))


;;; Generated autoloads from ../modules/extras/me-elisp-extras.el
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; me-eglot-ltex-extras.el --- Extra functionality for Eglot+LTeX-LS -*- lexical-binding: t; -*-
;;; me-eglot-ltex.el --- Extra functionality for Eglot+LTeX-LS -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

Expand Down Expand Up @@ -34,6 +34,36 @@
(defvar-local eglot-ltex-language "auto")
(defvar eglot-ltex-user-rules-path (concat minemacs-local-dir "eglot/ltex/"))

(defvar ltex-ls-command "ltex-ls")
(defvar ltex-ls-server-port 40001)
(defvar ltex-ls-server-process-name "ltex-ls-server")
(defvar ltex-ls--process nil)

;;;###autoload
(defun ltex-ls-start ()
"Start LTeX-LS as a TCP server at port `ltex-ls-server-port' on \"localhost\"."
(interactive)
(if (eq (process-status ltex-ls-server-process-name) 'run)
(message "LTeX-LS server already running!")
(if (executable-find ltex-ls-command)
(setq ltex-ls--process
(make-process
:name ltex-ls-server-process-name
:buffer (format " *%s*" ltex-ls-server-process-name)
:command (list ltex-ls-command "--server-type=TcpSocket" (format "--port=%d" ltex-ls-server-port))))
(user-error "LTeX-LS command \"%s\" not found." ltex-ls-command))
(if (process-live-p ltex-ls--process)
(message "Started LTeX-LS TCP server successfuly.")
(user-error "Cannot start LTeX-LS TCP server."))))

(defun ltex-ls-stop ()
"Stop LTeX-LS server if running."
(interactive)
(if (not (process-live-p ltex-ls--process))
(message "No running instance of LTeX-LS server!")
(delete-process ltex-ls--process)
(message "LTeX-LS server stopped.")))

(defvar eglot-ltex-dictionary
(+deserialize-sym 'eglot-ltex-dictionary eglot-ltex-user-rules-path))

Expand Down Expand Up @@ -85,14 +115,16 @@ When STORE is non-nil, this will also store the new plist in the directory
(plist-get args-plist lang)))))

(defun eglot-ltex-enable-handling-client-commands ()
"Enable Eglot hack to handle code actions of LTeX-LS."
(interactive)
(advice-add 'eglot-execute-command :before #'eglot-ltex--can-process-client-commands-a))

(defun eglot-ltex-disable-handling-client-commands ()
"Disable Eglot hack to handle code actions of LTeX-LS."
(interactive)
(advice-remove 'eglot-execute-command #'eglot-ltex--can-process-client-commands-a))


(provide 'me-eglot-ltex-extras)
(provide 'me-eglot-ltex)

;;; me-eglot-ltex-extras.el ends here
;;; me-eglot-ltex.el ends here
4 changes: 2 additions & 2 deletions modules/me-natural-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@
;; . ((ltex . ((language . "fr")
;; (disabledRules . ((fr . ["FRENCH_WHITESPACE"])))
;; (additionalRules . ((languageModel . "/usr/share/ngrams/")))))))))
(use-package me-eglot-ltex-extras
(use-package me-eglot-ltex
:after eglot
:demand t
:config
(eglot-ltex-enable-handling-client-commands)
(+eglot-register
'(text-mode org-mode markdown-mode rst-mode latex-mode bibtex-mode context-mode)
"ltex-ls"))
`("localhost" ,ltex-ls-server-port)))


(provide 'me-natural-langs)
Expand Down

0 comments on commit fe290c2

Please sign in to comment.