astoff / digestif

A language server for TeX and friends
Other
251 stars 6 forks source link

Completion does not work on a digestif language server using Emacs with the lsp-mode package. #33

Closed hongyi-zhao closed 3 years ago

hongyi-zhao commented 3 years ago

On Ubuntu 20.04, I try to test the Emacs with the lsp-mode package based setting according to the instruction here using the following steps:

  1. Install digestif according to the instruction here:
$ git clone https://github.com/astoff/digestif.git digestif.git
$ cd digestif.git/scripts
# Bootstrap digestif with the self-installing wrapper script.
$ ./digestif
# Place it in your $PATH
$ ln -sfr digestif ~/.local/bin
  1. Installation and setting of Emacs, auctex, lsp-mode, and relevant packages through straight:
    
    (straight-use-package
    `( auctex :type git :host nil :repo "https://git.savannah.gnu.org/git/auctex.git"
    :pre-build ,(pcase system-type
                (`berkeley-unix '("gmake"))
                (_ '(
                    ;("bash" "-c" "cd ~/.emacs.d/straight/repos/auctex")
                    ("./autogen.sh")
                    ("./configure")
                    ("make")
                    ("sudo" "make" "install"))))))

(load "auctex.el" nil t t) (load "preview-latex.el" nil t t) (setq TeX-auto-save t) (setq TeX-parse-self t) (setq-default TeX-master nil)

(use-package lsp-mode) (use-package company-lsp) (require 'company-lsp) (push 'company-lsp company-backends) (add-to-list 'company-lsp-filter-candidates '(digestif . nil))


Then I open some TeX document and still can't have the Digestif enabled. OTOH, I've successfully configured and tested `Emacs with the Eglot package` based approach as described [here](https://github.com/abo-abo/swiper/issues/2887#issuecomment-861534700).

Any hints for this problem will be highly appreciated.

Regards,
HY
astoff commented 3 years ago

I get the impression that lsp-mode changed the default server for LaTeX, so you need to tell it that you want to use Digestif. Can you try customizing the variable lsp-tex-server and see if that helps?

When you solve the problem with lsp-mode, let me know the details, so I can update the README (I myself only use Eglot).

hongyi-zhao commented 3 years ago

I get the impression that lsp-mode changed the default server for LaTeX, so you need to tell it that you want to use Digestif. Can you try customizing the variable lsp-tex-server and see if that helps?

Any hint or documentation for the format and usage of setting this variable, especially the case of Digestif?

When you solve the problem with lsp-mode, let me know the details, so I can update the README (I myself only use Eglot).

Surely.

astoff commented 3 years ago

Any hint or documentation for the format and usage of setting this variable, especially the case of Digestif?

M-x customize-variable

hongyi-zhao commented 3 years ago

M-x customize-variable RET

Then filtering the result with lsp gives the following list:

image

But I still can't find any clues for the setting you mentioned above.

astoff commented 3 years ago

Like I said above, lsp-tex-server is supposed to be the variable that controls that. But I'm just relying on what I read online on lsp-mode's website.

hongyi-zhao commented 3 years ago

I find the corresponding source code here:

(defcustom lsp-tex-server 'texlab
          "Choose LSP tex server."
           :type '(choice (const :tag "texlab" texlab)
                         (const :tag "digestif" digestif))

But still can't figure out how to do the corresponding setting.

astoff commented 3 years ago

(setq lsp-tex-server 'digestif)

hongyi-zhao commented 3 years ago

The setting and testing are shown below.

The digestif info:

werner@X10DAi:~$ digestif --help
Usage: digestif [-h] [-v] [-g FILES]

Digestif is a language server for TeX

Optional arguments:
  -v, --verbose          Enable log output to stderr
  -g, --generate FILES   Generate data file stubs for FILES
  -h, --help             Display this message and quit

Environment variables:
  DIGESTIF_DATA          Paths to look for data files
  DIGESTIF_TEXMF         Paths to look for TeX files
  DIGESTIF_TLPDB         Path to the TeXLive package database file

  If your TeX distribution or Digestif are installed in a non-standard
  location, you may need to set some of the above variables.

Emacs' initialization file configurations:

(use-package lsp-mode)
(require 'lsp-mode)
(setq lsp-tex-server 'digestif) 

(use-package company-lsp)
(require 'company-lsp)
(push 'company-lsp company-backends)
(add-to-list 'company-lsp-filter-candidates '(digestif . nil))

But still failed, as shown below:

image

astoff commented 3 years ago

I can't see any obvious problem in your config. I think you should check with the lsp-mode people.

hongyi-zhao commented 3 years ago

Anyway, based on the wonderful notes here, I tried out the following solution using auctex, eglot, texlab, and company:

;;; Auctex
;Using AUCTeX from local Git repo without installation
(straight-use-package
 `(auctex :type git :host nil :repo "https://git.savannah.gnu.org/git/auctex.git"
    :pre-build ,(pcase system-type
                (`berkeley-unix '("gmake"))
                (_ '(
                    `("bash" "-c" "cd" ,(straight--repos-dir "auctex"))
                    ("./autogen.sh")
                    ("./configure" "--without-texmf-dir" "--with-lispdir=.") 
                    ("make")
                    )))))

     (setq TeX-data-directory (straight--repos-dir "auctex")
           TeX-lisp-directory TeX-data-directory)                   

; Or set the following variable via custom-set-variables in the opened buffer by the following command.
; M-x describe-variable RET preview-TeX-style-dir RET
;`(preview-TeX-style-dir ,(concat ".:" (straight--repos-dir "auctex") "latex:"))
(setq preview-TeX-style-dir (concat ".:" (straight--repos-dir "auctex") "latex:"))

(load "auctex.el" nil t t) 
(load "preview-latex.el" nil t t)

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

;;; eglot, company, and texlab
(use-package company)
(add-hook 'after-init-hook 'global-company-mode)

(use-package eglot)
;https://tam5917.hatenablog.com/entry/2021/04/01/014719
;; hook into AUCTeX 
(add-hook 'TeX-mode-hook 'eglot-ensure)
;; ensure we don't use digestif server, which is far less than texlab on features and characteristics.
(delete (assoc '(tex-mode context-mode texinfo-mode bibtex-mode)
               eglot-server-programs) eglot-server-programs)
;; ensure texlab is set as the server.
(add-to-list 'eglot-server-programs
             '((latex-mode tex-mode context-mode texinfo-mode bibtex-mode) . (
             "texlab"
             )))

image

Based on my actual testing experience, digestif's capability is far less powerful than that of texlab. Hence, I switched to texlab.

astoff commented 3 years ago

Based on my actual testing experience, digestif's capability is far less powerful than that of texlab.

What does is do that Digestif doesn't?

hongyi-zhao commented 3 years ago

What does is do that Digestif doesn't?

It only can provide partial results shown by texlab.