lsp-mode
lsp-mode copied to clipboard
JSON language server doesn't work in Emacs 28.1
Thank you for the bug report
- [X] I am using the latest version of
lsp-moderelated packages. - [X] I checked FAQ and Troubleshooting sections
- [ ] You may also try reproduce the issue using clean environment using the following command:
M-x lsp-start-plain
Bug description

No completions are shown in .json files.
Steps to reproduce
- Install
json-lsserver - Create
package.jsonfile anywhere - Open this file
- Type the following code:
{ "desc - Nothing is suggested while
descriptionis expected to be shown
Expected behavior
description is expected to be suggested.
Which Language Server did you use?
json-ls
OS
Linux
Error callstack
*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.
3 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th\
e path.
4 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th\
e path.
5 Found the following clients for /home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json: (server-id json-ls, priority\
0)
6 The following clients were selected based on priority: (server-id json-ls, priority 0)
7 Cancelling textDocument/documentColor(2) in hook post-command-hook
8 cancelled
lsp-log:
[Trace - 11:07:01 PM] Sending request 'textDocument/hover - (10)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
},
"position": {
"line": 0,
"character": 0
}
}
[Trace - 11:07:01 PM] Sending request 'textDocument/documentLink - (11)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:01 PM] Received response 'textDocument/hover - (10)' in 20ms.
Result: null
[Trace - 11:07:01 PM] Received response 'textDocument/documentLink - (11)' in 16ms.
Result: []
[Trace - 11:07:04 PM] Sending request 'textDocument/documentLink - (12)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:04 PM] Received response 'textDocument/documentLink - (12)' in 2ms.
Result: []
[Trace - 11:07:04 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 1
},
"contentChanges": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"rangeLength": 0,
"text": "{"
}
]
}
[Trace - 11:07:05 PM] Sending request 'textDocument/hover - (13)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
},
"position": {
"line": 0,
"character": 1
}
}
[Trace - 11:07:05 PM] Sending request 'textDocument/documentSymbol - (14)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:05 PM] Sending request 'textDocument/documentLink - (15)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:05 PM] Sending request 'textDocument/documentColor - (16)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:05 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"diagnostics": []
}
[Trace - 11:07:05 PM] Sending notification '$/cancelRequest'.
Params: {
"id": 14
}
[Trace - 11:07:05 PM] Sending request 'textDocument/documentSymbol - (17)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:05 PM] Sending request 'textDocument/documentLink - (18)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:05 PM] Received response 'textDocument/hover - (13)' in 12ms.
Result: null
[Trace - 11:07:05 PM] Received response 'nil - (14)' in 0ms.
Result: []
[Trace - 11:07:05 PM] Received response 'textDocument/documentLink - (15)' in 10ms.
Result: []
[Trace - 11:07:05 PM] Received response 'textDocument/documentColor - (16)' in 32ms.
Result: []
[Trace - 11:07:05 PM] Received response 'textDocument/documentSymbol - (17)' in 25ms.
Result: []
[Trace - 11:07:05 PM] Received response 'textDocument/documentLink - (18)' in 24ms.
Result: []
[Trace - 11:07:05 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 2
},
"contentChanges": [
{
"range": {
"start": {
"line": 0,
"character": 1
},
"end": {
"line": 0,
"character": 1
}
},
"rangeLength": 0,
"text": "\n"
}
]
}
[Trace - 11:07:05 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 3
},
"contentChanges": [
{
"range": {
"start": {
"line": 1,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"rangeLength": 0,
"text": "\t"
}
]
}
[Trace - 11:07:05 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 4
},
"contentChanges": [
{
"range": {
"start": {
"line": 1,
"character": 1
},
"end": {
"line": 1,
"character": 1
}
},
"rangeLength": 0,
"text": "\""
}
]
}
[Trace - 11:07:05 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 5
},
"contentChanges": [
{
"range": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 2
}
},
"rangeLength": 0,
"text": "d"
}
]
}
[Trace - 11:07:05 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 6
},
"contentChanges": [
{
"range": {
"start": {
"line": 1,
"character": 3
},
"end": {
"line": 1,
"character": 3
}
},
"rangeLength": 0,
"text": "e"
}
]
}
[Trace - 11:07:05 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 7
},
"contentChanges": [
{
"range": {
"start": {
"line": 1,
"character": 4
},
"end": {
"line": 1,
"character": 4
}
},
"rangeLength": 0,
"text": "s"
}
]
}
[Trace - 11:07:06 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"version": 8
},
"contentChanges": [
{
"range": {
"start": {
"line": 1,
"character": 5
},
"end": {
"line": 1,
"character": 5
}
},
"rangeLength": 0,
"text": "c"
}
]
}
[Trace - 11:07:06 PM] Sending request 'textDocument/documentSymbol - (19)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:06 PM] Sending request 'textDocument/documentLink - (20)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:06 PM] Sending request 'textDocument/documentColor - (21)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:06 PM] Sending request 'textDocument/hover - (22)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
},
"position": {
"line": 1,
"character": 6
}
}
[Trace - 11:07:06 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json",
"diagnostics": []
}
[Trace - 11:07:06 PM] Received response 'textDocument/documentSymbol - (19)' in 4ms.
Result: []
[Trace - 11:07:06 PM] Received response 'textDocument/documentLink - (20)' in 4ms.
Result: []
[Trace - 11:07:06 PM] Sending request 'textDocument/documentLink - (23)'.
Params: {
"textDocument": {
"uri": "file:///home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json"
}
}
[Trace - 11:07:06 PM] Received response 'textDocument/documentColor - (21)' in 10ms.
Result: []
[Trace - 11:07:06 PM] Received response 'textDocument/hover - (22)' in 10ms.
Result: null
[Trace - 11:07:06 PM] Received response 'textDocument/documentLink - (23)' in 2ms.
Result: []
### Anything else?
*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.
3 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th
e path.
4 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th
e path.
5 Found the following clients for /home/emilyseville7cfg/Documents/Mine/Shell/personal-editor-configs/package.json: (server-id json-ls, priority
0)
6 The following clients were selected based on priority: (server-id json-ls, priority 0)
*Messages*:
18 ‘spacemacs-theme’ is already installed
17 ‘flycheck’ is already installed
16 ‘json-mode’ is already installed
15 ‘yaml-mode’ is already installed
14 ‘markdown-mode’ is already installed
13 ‘lsp-mode’ is already installed
12 ‘lsp-pyright’ is already installed
11 ‘lsp-java’ is already installed
10 ‘format-all’ is already installed
9 ‘company’ is already installed
8 [Treemacs] Warning: coudn’t find default background colour for icons, falling back on #2d2d31.
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 package.json has auto save data; consider M-x recover-this-file
3 LSP :: Yasnippet is not installed, but lsp-enable-snippet' is set to t'. You must either install yasnippet, or disable snippet support.
2 LSP :: Connected to [json-ls:25851/starting].
1 LSP :: json-ls:25851 initialized successfully in folders: (/home/emilyseville7cfg/Documents/Mine/Shell)
@kiennq is there anything else that the user has to do to get the package.json schema? I thought that it is built-in?
It should be built-in and I've tested it on Emacs 29, still working fine.
@EmilySeville7cfg, can you capture the lsp-io log from the start just until you type the first "?
I didn't see any completion request in your log so the completion result should be cached (or not requested) already.
Do you have company-mode enabled?
Steps done:
- touch package.json
- emacs -nw package.json (obtain
File mode specification error: (json-end-of-file)) - M-x toggle-debug-on-error RET
- M-x eval-expression RET (setq lsp-print-io t) RET
- Obtained 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.
3 Command "/home/emilyseville7cfg/.emacs.d/.cache/lsp/npm/vscode-langservers-extracted/bin/vscode-json-language-server --stdio" is present on th\
e path.
- M-x lsp RET (obtain
End of file while parsing JSON)
My ~/.emacs is here.
@EmilySeville7cfg, might be it's because of the file mode error?
Can you try to see if you can repro this with lsp-plain? Try lsp-restart-workspace as well
M-x lsp-plain RETexecuteslsp-start-plainand doesn't help: the same issue exists in the newly opened emacs windowlsp-restart-workspace(immediately after openingpackage.json) gives me this error: There are no active servers in the current buffer.
I've checked this issue with the following config (~/.emacs.d is removed before this test):
;;; .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 look-settings()
"Theme settings."
(package-install 'spacemacs-theme)
(load-theme 'spacemacs-light t))
(defun general-folding-setup()
"General folding settings setup."
(package-install 'origami))
(defun general-lsp-setup()
"General LSP settings setup."
(package-install 'lsp-mode)
(package-install 'company)
(require 'lsp-mode))
(defun lisp-setup()
"Lisp plugin setup."
(let ((hook 'emacs-lisp-mode-hook))
(add-hook hook #'company-mode)
(add-hook hook #'origami-mode)))
(defun yaml-setup()
"YAML plugin setup."
(package-install 'yaml-mode)
(let ((hook 'yaml-mode-hook))
(add-hook hook #'lsp)
(add-hook hook #'company-mode)
(add-hook hook #'origami-mode)))
(defun json-setup()
"JSON plugin setup."
(package-install 'json-mode)
(let ((hook 'json-mode-hook))
(add-hook hook #'lsp)
(add-hook hook #'company-mode)
(add-hook hook #'origami-mode)))
(defun bash-setup()
"Bash plugin setup."
(let ((hook 'sh-mode-hook))
(add-hook hook #'lsp)
(add-hook hook #'company-mode)
(add-hook hook #'origami-mode)))
(defun python-setup()
"Python plugin setup."
(package-install 'lsp-pyright)
(require 'dap-python)
(let ((hook 'python-mode-hook))
(add-hook hook #'lsp)
(add-hook hook #'company-mode)
(add-hook hook #'origami-mode)
(add-hook hook #'dap-mode)))
(defun java-setup()
"Java plugin setup."
(package-install 'lsp-java)
(require 'dap-java)
(let ((hook 'java-mode-hook))
(add-hook hook #'lsp)
(add-hook hook #'company-mode)
(add-hook hook #'origami-mode)
(add-hook hook #'dap-mode)))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(general-settings)
;(look-settings)
;(general-folding-setup)
(general-lsp-setup)
;(lisp-setup)
;(yaml-setup)
(json-setup)
;(bash-setup)
;(python-setup)
;(java-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
Hmm, I can still using json-mode just fine with this configuration.
Are you using lsp-use-plists but doesn't set the LSP_USE_PLISTS env variable?
Are you using lsp-use-plists but doesn't set the LSP_USE_PLISTS env variable?
What value must be used for this environment variable?
Installing and running yasnippet fixed this for me.
(use-package yasnippet :straight t :init (yas-global-mode))
https://github.com/emacs-lsp/lsp-mode/discussions/4033#discussioncomment-5736276
@sethidden, thanks. I'll try your way to solve this issue. :)
I can confirm, installing yasnippet solves the issue.
That said I'm not sure why we need yasnippet "A template system for Emacs" to make completions work in json modes. I've been using other modes and they have been working fine without yasnippet, why is json mode special?
@danielpza @EmilySeville7cfg @sethidden
FWIW it is not up to the client. Apparently, the server does not return completion when client-side does not support snippets. This one can be closed after documenting this server limitation.
@yyoncho Where can I add these docs? Best I found was https://github.com/emacs-lsp/lsp-mode/blob/master/docs/lsp-clients.json#L366 but it doesn't look like it supports adding arbitrary text
@sethidden check this: https://github.com/emacs-lsp/lsp-mode/blob/master/docs/manual-language-docs/lsp-gopls.md?plain=1#L1
Ok, please see https://github.com/emacs-lsp/lsp-mode/pull/4035
@yyoncho Hm https://github.com/emacs-lsp/lsp-mode/blob/master/docs/manual-language-docs/lsp-json-ls.md doesn't show up on https://emacs-lsp.github.io/lsp-mode/page/lsp-json/
Did I mess something up a few months back in the code so it's not detected?