Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to complete some commands with company-math and company-ispell when using eglot, texlab, and company #710

Open
hongyi-zhao opened this issue Jun 26, 2021 · 4 comments

Comments

@hongyi-zhao
Copy link

  • Server used: texlab
  • Emacs version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2021-06-19
  • Operating system: Ubuntu 20.04.1 LTS
  • Eglot version: 5cc8df6
  • Eglot installation method: straight
  • Using Doom: No

LSP transcript - M-x eglot-events-buffer (mandatory unless Emacs inoperable)

[client-request] (id:1) Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
	  (:processId 1053223 :rootPath "/home/werner/" :rootUri "file:///home/werner" :initializationOptions #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
															    ())
		      :capabilities
		      (:workspace
		       (:applyEdit t :executeCommand
				   (:dynamicRegistration :json-false)
				   :workspaceEdit
				   (:documentChanges :json-false)
				   :didChangeWatchedFiles
				   (:dynamicRegistration t)
				   :symbol
				   (:dynamicRegistration :json-false)
				   :configuration t)
		       :textDocument
		       (:synchronization
			(:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
			:completion
			(:dynamicRegistration :json-false :completionItem
					      (:snippetSupport :json-false)
					      :contextSupport t)
			:hover
			(:dynamicRegistration :json-false :contentFormat
					      ["plaintext"])
			:signatureHelp
			(:dynamicRegistration :json-false :signatureInformation
					      (:parameterInformation
					       (:labelOffsetSupport t)
					       :activeParameterSupport t))
			:references
			(:dynamicRegistration :json-false)
			:definition
			(:dynamicRegistration :json-false)
			:declaration
			(:dynamicRegistration :json-false)
			:implementation
			(:dynamicRegistration :json-false)
			:typeDefinition
			(:dynamicRegistration :json-false)
			:documentSymbol
			(:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind
					      (:valueSet
					       [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]))
			:documentHighlight
			(:dynamicRegistration :json-false)
			:codeAction
			(:dynamicRegistration :json-false :codeActionLiteralSupport
					      (:codeActionKind
					       (:valueSet
						["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"]))
					      :isPreferredSupport t)
			:formatting
			(:dynamicRegistration :json-false)
			:rangeFormatting
			(:dynamicRegistration :json-false)
			:rename
			(:dynamicRegistration :json-false)
			:publishDiagnostics
			(:relatedInformation :json-false))
		       :experimental #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
						   ()))))
[server-reply] (id:1) Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :id 1 :result
	  (:capabilities
	   (:completionProvider
	    (:resolveProvider t :triggerCharacters
			      ["\\" "{" "}" "@" "/" " "])
	    :definitionProvider t :documentFormattingProvider t :documentHighlightProvider t :documentLinkProvider
	    (:resolveProvider :json-false)
	    :documentSymbolProvider t :foldingRangeProvider t :hoverProvider t :referencesProvider t :renameProvider
	    (:prepareProvider t)
	    :textDocumentSync
	    (:change 1 :openClose t :save
		     (:includeText :json-false))
	    :workspaceSymbolProvider t)
	   :serverInfo
	   (:name "TexLab" :version "3.2.0")))
[client-notification] Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :method "initialized" :params #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
							    ()))
[client-notification] Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
	  (:textDocument
	   (:uri "file:///home/werner/test/test.tex" :version 0 :languageId "latex" :text "\\documentclass{paper}\n\n\\usepackage{amsmath}\n\\usepackage{braket}\n\\usepackage{mathtools}\n\\usepackage{stix}\n\\usepackage{hyperref}\n\n\\begin{document}\n\n$\\thermod$\n\n\\end{document}\n")))
[client-notification] Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params
	  (:settings nil))
[server-request] (id:0) Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :id 0 :method "workspace/configuration" :params
	  (:items
	   [(:section "texlab")]))
[client-reply] (id:0) Sat Jun 26 12:03:14 2021:
(:jsonrpc "2.0" :id 0 :result
	  [nil])
[stderr] ERROR - Invalid configuration: invalid type: null, expected struct Options
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   [(:message "File `test.out' has changed. Rerun to get outlines right or use package `bookmark'." :range
		      (:end
		       (:character 0 :line 0)
		       :start
		       (:character 0 :line 0))
		      :severity 2 :source "latex")]
	   :uri "file:///home/werner/test/test.tex"))
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.log"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.log)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.aux"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.aux)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   [(:message "File `test.out' has changed. Rerun to get outlines right or use package `bookmark'." :range
		      (:end
		       (:character 0 :line 0)
		       :start
		       (:character 0 :line 0))
		      :severity 2 :source "latex")]
	   :uri "file:///home/werner/test/test.tex"))
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.log"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.log)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.aux"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.aux)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   [(:message "File `test.out' has changed. Rerun to get outlines right or use package `bookmark'." :range
		      (:end
		       (:character 0 :line 0)
		       :start
		       (:character 0 :line 0))
		      :severity 2 :source "latex")]
	   :uri "file:///home/werner/test/test.tex"))
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.log"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.log)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.aux"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.aux)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   [(:message "File `test.out' has changed. Rerun to get outlines right or use package `bookmark'." :range
		      (:end
		       (:character 0 :line 0)
		       :start
		       (:character 0 :line 0))
		      :severity 2 :source "latex")]
	   :uri "file:///home/werner/test/test.tex"))
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.log"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.log)")
[server-notification] Sat Jun 26 12:03:15 2021:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
	  (:diagnostics
	   []
	   :uri "file:///home/werner/test/test.aux"))
[internal] Sat Jun 26 12:03:15 2021:
(:message "Diagnostics received for unvisited (file:///home/werner/test/test.aux)")

Backtrace (mandatory, unless no error message seen or heard):

I don't have info of this part.

... Paste the backtrace here ...
Debugger entered--Lisp error: (error "oh no")
  signal(error ("oh no"))
  error("oh no")
  eval((error "oh no") nil)
  pp-eval-expression((error "oh no"))
  funcall-interactively(pp-eval-expression (error "oh no"))
  call-interactively(pp-eval-expression nil nil)
  command-execute(pp-eval-expression)

Minimal configuration (mandatory)

# Type this in a shell to start an Emacs with Eglot configured
# $ /path/to/a/certain/version/of/emacs -Q -f package-initialize -L /path/to/git-cloned/eglot -l eglot.el 

$ emacs -q --load ~/.emacs.d/init.texlab-lsp-mode-eglot-lsp-latex-company
;; The minimal configuration of the above mentioned initialization file.

;;Bootstrap straight
(defvar bootstrap-version)
(let ((bootstrap-file
      (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
     (bootstrap-version 5))
 (unless (file-exists-p bootstrap-file)
   (with-current-buffer
       (url-retrieve-synchronously
        "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
        'silent 'inhibit-cookies)
     (goto-char (point-max))
     (eval-print-last-sexp)))
 (load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)


;Using AUCTeX from local Git repo without installation
;https://github.com/raxod502/straight.el/issues/800#issuecomment-862165317
(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)

(use-package eglot
 :hook 
 ((TeX-mode . eglot-ensure))
 :config
 (add-to-list 'eglot-stay-out-of 'company)
 ;;; ensure texlab is set as the server.
 (add-to-list 'eglot-server-programs
            '((latex-mode tex-mode context-mode texinfo-mode bibtex-mode) . ("texlab"))))

(use-package company
 :hook
 (TeX-mode . company-mode)
 :custom
 ;https://github.com/company-mode/company-mode/issues/14#issuecomment-290261406
 ; Do not downcase the returned candidates automatically
 (company-dabbrev-downcase nil) 
 (company-idle-delay 0) 
 (company-minimum-prefix-length 1))

(use-package company-math)

(add-to-list 'company-backends 'company-math-symbols-unicode)
(defun my-latex-mode-setup ()
(setq-local company-backends
               (append '((company-math-symbols-latex
   		   company-latex-commands
   		   company-ispell
   		   ))
                       company-backends)))

(add-hook 'TeX-mode-hook 'my-latex-mode-setup)

And the testing tex document:

\documentclass{paper}

\usepackage{amsmath}
\usepackage{braket}
\usepackage{mathtools}
\usepackage{stix}
\usepackage{hyperref}

\begin{document}

 Some testing code comes here.

\end{document}

With the above configuaration, some commands still couldn't be completed, as shown below.

The \bra command which is defined in braket package can't be completed:

image

The \href command which is defined in hyperref package can't be completed:

image

@joaotavora
Copy link
Owner

Sorry for the delay in looking into this.

@skangas skangas changed the title Failed to comlete some commands with company-math and company-ispell when using eglot, texlab, and company. Failed to complete some commands with company-math and company-ispell when using eglot, texlab, and company Jan 10, 2022
@joaotavora
Copy link
Owner

Almost two years on. I still haven't gotten to this. So sorry. Too much setup. Maybe @astoff, who develops a LaTeX LSP server and is familiar with the Eglot client and its code base, can lend a hand.

@astoff
Copy link
Contributor

astoff commented Mar 26, 2023

Judging by the screenshots, all seems to be working fine. It's impossible, theoretically and in practice, to determine all commands defined by a TeX package except by running TeX.

Unless @hongyi-zhao can confirm that these completions work in other editors, I'd say there's no bug here.

@joaotavora
Copy link
Owner

Yes, I think this is just a server limitation. Let's close this old issue. We can always reopen if more information arises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants