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

Emacs 27.1 - set-formatter commands error: (wrong-type-argument json-value-p :brittany) #75

Closed
shaunplee opened this issue Aug 11, 2020 · 0 comments

Comments

@shaunplee
Copy link

shaunplee commented Aug 11, 2020

Hello, I just upgraded to Emacs 27.1, and it seems that there was some change to the handling of JSON serialization. When trying the various lsp-set-formatter commands:
lsp-set-formatter-ormolu
lsp-set-formatter-brittany
lsp-set-formatter-floskell
I get a: (wrong-type-argument json-value-p :ormolu), (wrong-type-argument json-value-p :brittany), or (wrong-type-argument json-value-p :floskell), respectively.

Here's a Backtrace from trying lsp-set-formatter-brittany:

Debugger entered--Lisp error: (wrong-type-argument json-value-p :brittany)
  json-serialize((:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params (:settings (:languageServerHaskell #<hash-table eql 3/65 0x1ff4d46f7b2d>))) :null-object nil :false-object :json-false)
  (let ((body (json-serialize params :null-object nil :false-object :json-false))) (concat "Content-Length: " (number-to-string (1+ (string-bytes body))) "\15\n\15\n" body "\n"))
  lsp--make-message((:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params (:settings (:languageServerHaskell #<hash-table eql 3/65 0x1ff4d46f7b2d>))))
  (lsp--send-no-wait (lsp--make-message body) (progn (or (and (memq (type-of lsp--cur-workspace) cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list 'lsp--workspace lsp--cur-workspace))) (aref lsp--cur-workspace 7)))
  (let ((lsp--cur-workspace it)) (if lsp-print-io (progn (lsp--log-entry-new (lsp--make-log-entry (plist-get body :method) nil (plist-get body :params) 'outgoing-notif) lsp--cur-workspace))) (lsp--send-no-wait (lsp--make-message body) (progn (or (and (memq (type-of lsp--cur-workspace) cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list 'lsp--workspace lsp--cur-workspace))) (aref lsp--cur-workspace 7))))
  (closure ((body :jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params (:settings (:languageServerHaskell #<hash-table eql 3/65 0x1ff4d46f7b2d>))) cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) (it) (let ((lsp--cur-workspace it)) (if lsp-print-io (progn (lsp--log-entry-new (lsp--make-log-entry (plist-get body :method) nil (plist-get body :params) 'outgoing-notif) lsp--cur-workspace))) (lsp--send-no-wait (lsp--make-message body) (progn (or (and (memq ... cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list ... lsp--cur-workspace))) (aref lsp--cur-workspace 7)))))(#s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 17/17 0x1ff4d6363c41> :registered-server-capabilities (... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :root "/Users/shaun/workspa..." :client #s(lsp--client :language-id nil :add-on? nil :new-connection ... :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x1ff4d377d0c1> :request-handlers #<hash-table equal 0/65 0x1ff4d37d6cb1> :response-handlers #<hash-table eql 3/65 0x1ff4d37d6fa9> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x1ff4d37d7281> :action-handlers #<hash-table equal 0/65 0x1ff4d37d72a1> :major-modes ... :activation-fn nil :priority 0 :server-id hie :multi-root nil :initialization-options nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil ...) :host-root nil :proc #<process hie> :cmd-proc #<process hie> :buffers (#<buffer Scenes.hs> #<buffer Lib.hs> #<buffer Random.hs> #<buffer Main.hs>) :semantic-highlighting-faces nil :semantic-highlighting-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x1ff4d6518a55> :watches #<hash-table equal 0/65 0x1ff4d6518d2d> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x1ff4d6518dd1> ...))
  mapcar((closure ((body :jsonrpc "2.0" :method "workspace/didChangeConfigu..." :params ...) cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) (it) (let (...) (if lsp-print-io ...) (lsp--send-no-wait ... ...))) (#s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 17/17 0x1ff4d6363c41> :registered-server-capabilities (... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :root "/Users/shaun/workspace/ray..." :client #s(lsp--client :language-id nil :add-on? nil :new-connection ... :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 0/65 0x1ff4d377d0c1> :request-handlers #<hash-table equal 0/65 0x1ff4d37d6cb1> :response-handlers #<hash-table eql 3/65 0x1ff4d37d6fa9> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x1ff4d37d7281> :action-handlers #<hash-table equal 0/65 0x1ff4d37d72a1> :major-modes ... :activation-fn nil :priority 0 :server-id hie :multi-root nil :initialization-options nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn ... :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil ...) :host-root nil :proc #<process hie> :cmd-proc #<process hie> :buffers (#<buffer Scenes.hs> #<buffer Lib.hs> #<buffer Random.hs> #<buffer Main.hs>) :semantic-highlighting-faces nil :semantic-highlighting-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x1ff4d6518a55> :watches #<hash-table equal 0/65 0x1ff4d6518d2d> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x1ff4d6518dd1> :work-done-tokens #<hash-table equal 0/65 0x1ff4d64fd4c1>)))
  lsp--send-notification((:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params (:settings (:languageServerHaskell #<hash-table eql 3/65 0x1ff4d46f7b2d>))))
  lsp-notify("workspace/didChangeConfiguration" (:settings (:languageServerHaskell #<hash-table eql 3/65 0x1ff4d46f7b2d>)))
  lsp--set-configuration((:languageServerHaskell #<hash-table eql 3/65 0x1ff4d46f7b2d>))
  lsp-haskell--set-configuration()
  lsp-haskell-set-formatter-brittany()
  funcall-interactively(lsp-haskell-set-formatter-brittany)
  call-interactively(lsp-haskell-set-formatter-brittany record nil)
  command-execute(lsp-haskell-set-formatter-brittany record)
  execute-extended-command(nil "lsp-haskell-set-formatter-brittany" "lsp-haskell-set-formatter-brit")
  funcall-interactively(execute-extended-command nil "lsp-haskell-set-formatter-brittany" "lsp-haskell-set-formatter-brit")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

As an experiment, modifying the lsp-haskell-set-formatter functions to use strings seems to solve the issue:

(defun lsp-haskell-set-formatter-brittany ()
  "Use brittany."
  (interactive)
  (lsp-haskell-set-formatter "brittany")
  (lsp-haskell--set-configuration))

(defun lsp-haskell-set-formatter-floskell ()
  "Use floskell."
  (interactive)
  (lsp-haskell-set-formatter "floskell")
  (lsp-haskell--set-configuration))

(defun lsp-haskell-set-formatter-ormolu ()
  "Use ormolu."
  (interactive)
  (lsp-haskell-set-formatter "ormolu")
  (lsp-haskell--set-configuration))

However, I don't know if this breaks compatibility with prior versions of Emacs.

Edit: Using strings instead of symbols, as shown above, also works on Emacs 26.3.

@shaunplee shaunplee changed the title Emacs 27.1 - set-formatter commands error: (wrong-type-argument json-value-p :brittany) Emacs 27.1 - set-formatter commands error: (wrong-type-argument json-value-p :brittany) Aug 11, 2020
@shaunplee shaunplee changed the title Emacs 27.1 - set-formatter commands error: (wrong-type-argument json-value-p :brittany) Emacs 27.1 - set-formatter commands error: (wrong-type-argument json-value-p :brittany) Aug 11, 2020
michaelpj added a commit to michaelpj/lsp-haskell that referenced this issue Sep 18, 2020
This does two things:
- Create `defcustom` variables for settings, matching the vscode
extension for all the language server settings.
- Use `lsp-mode`'s support for custom settings to handle sending them to
the server.

This lets users persistently configure their server settings using
normal Emacs setting customization.

This will probably break people, so should maybe be a major version
bump.

Fixes emacs-lsp#69, emacs-lsp#75, emacs-lsp#78; supersedes the (excellent) emacs-lsp#74 and emacs-lsp#76.

Notes:
- I have not copied the settings from the vscode extension regarding
starting the server. We don't try and get prebuilt binaries, so I
thought it was simplest to stick to command-and-arguments.
- I renamed the process option for consistency with other servers and to
avoid references to `hie`. This PR will already break basically everyone, so
I thought I might as well do that too.
- The current customization functions re-send a `didChangeConfiguration`
notification when called. `lsp-mode` does *not* currently do this when
you change variables, which is annoying. My inclination is to let them
fix it in the name of simplicity, but if anyone really hates not being
able to change the formatter without restarting the server I can try and
hack something together.
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

1 participant