emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.79k stars 889 forks source link

xmlls fails to start automatically in .xml files in Emacs #3695

Closed EmilyGraceSeville7cf closed 2 years ago

EmilyGraceSeville7cf commented 2 years ago

Thank you for the bug report

Bug description

image

No LSP started automatically for *.xml files.

Steps to reproduce

  1. touch test.xml
  2. emacs -nw test.xml
  3. obtain no LSP started automatically

Expected behavior

xmlls server started automatically.

Which Language Server did you use?

xmlls

OS

Linux

Error callstack

Emacs is started as: emacs -nw --eval '(toggle-debug-on-error) (setq lsp-print-io t)' test.xml

*lsp-log*:


  1 Command "/usr/local/bin/bash-language-server start" is present on the path.                                                                    
  1 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th\
    e path.                                                                                                                                        
  2 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/yaml-language-server/bin/yaml-language-server --stdio" is present on the path.

Anything else?

view my ~/.emacs

The original bug report is here.

M-x lsp starts xmlls normally:

image

yyoncho commented 2 years ago

That is the expected behavior. If lsp function is not attached to the major mode, the language server won't start.

EmilyGraceSeville7cf commented 2 years ago

I don't understand why it's not attached to a major mode. I have these lines in my config:

(defvar emacs-hooks '(cmake-mode-hook
                      xml-mode-hook ; <--
                      json-mode-hook
                      yaml-mode-hook
                      shell-mode-hook
                      python-mode-hook
                      java-mode-hook
                      csharp-mode-hook
                      c++-mode-hook))
(dolist (hook emacs-hooks)
  (add-hook hook #'lsp))
yyoncho commented 2 years ago

There is no xml-mode, there is nxml-mode or some are using web-mode for xml. Use M-: major-mode to find out what is your major mode.

EmilyGraceSeville7cf commented 2 years ago

LSP still does't work even I replaced xml-mode-hook with nxml-mode-hook. Now it doesn't want to start lsp at all...

yyoncho commented 2 years ago

and what is your major mode?

EmilyGraceSeville7cf commented 2 years ago

nxml-mode

The first error occures when I open empty test.xml file: File mode specification error: (json-end-of-file). The second when I press M-x lsp: End of file while parsing JSON.

yyoncho commented 2 years ago

can you do M-x toggle-debug-on-error and do M-x lsp again?

EmilyGraceSeville7cf commented 2 years ago

*lsp-log*:

  1 Command "/usr/local/bin/bash-language-server start" is present on the path.                                                                    
  1 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th\
    e path.                                                                                                                                        
  2 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/yaml-language-server/bin/yaml-language-server --stdio" is present on the path.
yyoncho commented 2 years ago

The first error occures when I open empty test.xml file: File mode specification error: (json-end-of-file).

Please, do M-x toggle-debug-on-error and reproduce that error.

EmilyGraceSeville7cf commented 2 years ago

I start emacs as emacs -nw --eval '(toggle-debug-on-error) (setq lsp-print-io t)' test.xml. But I don't see any notable differences. What am I doing wrong?

Here what I see:

image image

*Messages*:

 21 ‘spacemacs-theme’ is already installed                                                                                                         
 20 ‘flycheck’ is already installed                                                                                                                
 19 ‘json-mode’ is already installed                                                                                                               
 18 ‘yaml-mode’ is already installed                                                                                                               
 17 ‘markdown-mode’ is already installed                                                                                                           
 16 ‘lsp-mode’ is already installed                                                                                                                
 15 ‘cmake-mode’ is already installed                                                                                                              
 14 ‘lsp-pyright’ is already installed                                                                                                             
 13 ‘lsp-java’ is already installed                                                                                                                
 12 ‘lsp-pascal’ is already installed                                                                                                              
 11 ‘format-all’ is already installed                                                                                                              
 10 ‘company’ is already installed                                                                                                                 
  9 [Treemacs] Warning: coudn’t find default background colour for icons, falling back on #2d2d31.                                                 
  8 Saving file /home/emilyseville7cfg/.emacs...                                                                                                   
  7 Wrote /home/emilyseville7cfg/.emacs                                                                                                            
  6 For information about GNU Emacs and the GNU system, type C-h C-a.                                                                              
  5 Debug on Error enabled globally                                                                                                                
  4 test.xml has auto save data; consider M-x recover-this-file                                                                                    
  3 Using vacuous schema                                                                                                                           
  2 File mode specification error: (json-end-of-file)                                                                                              
  1 Making completion list...

*lsp-log*:

  1 Command "/usr/local/bin/bash-language-server start" is present on the path.                                                                    
  1 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th\
    e path.                                                                                                                                        
  2 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/yaml-language-server/bin/yaml-language-server --stdio" is present on the path.
yyoncho commented 2 years ago

when you do M-x toggle-debug-on-error and then the error like the one you have happens, you should see the error callstack. Apparently, you have something problematic in your config but without providing that info I cannot help.

EmilyGraceSeville7cf commented 2 years ago

The issue is I don't know what causes this problem in my config.

yyoncho commented 2 years ago

@EmilySeville7cfg delete your packages and then start adding them one by one.

EmilyGraceSeville7cf commented 2 years ago

@EmilySeville7cfg delete your packages and then start adding them one by one.

@yyoncho, my current ~/.emacs config:

;;; .emacs --- My custom .emacs config.
;;; Commentary:
;;; Installs different packages for code linting and formatting to enable user feel Emacs like an IDE.
;;; All language servers and linters can be installed separately.
;;; Code:

(require 'package)

(defun general-settings()
  "Settings accessible without any plugins setup."
  (defvar bookmark-save-flag 1)
  (menu-bar-mode -1)
  (setq-default tab-width 4)
  (setq-default display-line-numbers 'relative))

(defun general-lsp-setup()
  "General LSP settings setup."
  (package-install 'lsp-mode)
  (package-install 'company)
  (require 'lsp-mode))

(defun xml-setup()
  "XML plugin setup."
  (lsp-ensure-server 'xmlls)
  (let ((hook 'nxml-mode-hook))
    (add-hook hook #'lsp)
    (add-hook hook #'company-mode)
                                        ;(add-hook hook #'origami-mode)
    ))

(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)

(general-settings)

(general-lsp-setup)
(xml-setup)

(provide '.emacs)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(json-mode yaml-mode lsp-mode spacemacs-theme)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
;;; .emacs ends here

Almost everything is disabled except lsp mode. When I start emacs -nw --eval '(toggle-debug-on-error) (setq lsp-print-io t)' test.xml where test.xml is an empty new file I get File mode specification error: (json-end-of-file) error.

*Messages*:

  9 ‘lsp-mode’ is already installed
  8 ‘company’ is already installed
  7 Saving file /home/emilyseville7cfg/.emacs...
  6 Wrote /home/emilyseville7cfg/.emacs
  5 For information about GNU Emacs and the GNU system, type C-h C-a.
  4 Debug on Error enabled globally
  3 test.xml has auto save data; consider M-x recover-this-file
  2 Using vacuous schema
  1 File mode specification error: (json-end-of-file)

*lsp-log*: no such buffer available