emacs-lsp / lsp-haskell

lsp-mode :heart: haskell
https://emacs-lsp.github.io/lsp-haskell
GNU General Public License v3.0
227 stars 56 forks source link

Lisp error: (void-variable fourmolu) #176

Closed ciukstar closed 10 months ago

ciukstar commented 10 months ago

I ran into some issues (see debugger output below) after updating lsp-mode-20230823.446, lsp-haskell-20230823.1043 and haskell-language-server (2.1.0.0) to the latest versions. And I have no idea how to solve them. Please help.

Debugger entered--Lisp error: (void-variable fourmolu)
  byte-code("\301\302!\210\301\303!\210\304\305\306\307\310\302%\210\311\312!\210\313\314\315\316\317\320\310\305\321\322&\11\210\311\323!\210\313\324\325\326\317\327\310\305\321\330&\11\210..." [fourmolu require lsp-mode haskell-mode custom-declare-group lsp-haskell nil "Customization group for ‘lsp-haskell’." :group lsp-register-custom-settings (("haskell.formattingProvider" lsp-haskell-formatting-provider nil)) custom-declare-variable lsp-haskell-formatting-provider "ormolu" "The formatter to use when formatting a document or..." :set #f(compiled-function (sym val) #<bytecode 0x156bb56059a5>) :type (choice (const "brittany") (const "floskell") (const "fourmolu") (const "ormolu") (const "stylish-haskell") (const "none")) (("haskell.checkProject" lsp-haskell-check-project t)) lsp-haskell-check-project t "Whether to typecheck the entire project on load.\nI..." #f(compiled-function (sym val) #<bytecode 0x156bb56059bd>) boolean (("haskell.maxCompletions" lsp-haskell-max-completions nil)) lsp-haskell-max-completions 40 "Maximum number of completions sent to the editor." #f(compiled-function (sym val) #<bytecode 0x156bb56059d5>) number lsp-haskell-plugins "Customization group for 'lsp-haskell' plugins." (("haskell.plugin.importLens.codeActionsOn" lsp-haskell-plugin-import-lens-code-actions-on t)) lsp-haskell-plugin-import-lens-code-actions-on "Enables explicit imports code actions" #f(compiled-function (sym val) #<bytecode 0x156bb56059ed>) (("haskell.plugin.importLens.codeLensOn" lsp-haskell-plugin-import-lens-code-lens-on t)) lsp-haskell-plugin-import-lens-code-lens-on "Enables explicit imports code lenses" #f(compiled-function (sym val) #<bytecode 0x156bb5616755>) (("haskell.plugin.hlint.codeActionsOn" lsp-haskell-plugin-hlint-code-actions-on t)) lsp-haskell-plugin-hlint-code-actions-on "Enables hlint code actions (apply hints)" #f(compiled-function (sym val) #<bytecode 0x156bb561676d>) (("haskell.plugin.hlint.diagnosticsOn" lsp-haskell-plugin-hlint-diagnostics-on t)) lsp-haskell-plugin-hlint-diagnostics-on "Enables hlint diagnostics" #f(compiled-function (sym val) #<bytecode 0x156bb5616785>) (("haskell.plugin.hlint.config.flags" lsp-haskell-plugin-hlint-config-flags nil)) ...] 14)
  require(lsp-haskell nil t)
  #f(compiled-function (package) #<bytecode 0x156bb517c469>)(lsp-haskell)
  mapc(#f(compiled-function (package) #<bytecode 0x156bb517c469>) (ccls lsp-actionscript lsp-ada lsp-angular lsp-ansible lsp-awk lsp-astro lsp-bash lsp-beancount lsp-clangd lsp-clojure lsp-cmake lsp-credo lsp-crystal lsp-csharp lsp-css lsp-d lsp-dart lsp-dhall lsp-docker lsp-dockerfile lsp-elm lsp-elixir lsp-emmet lsp-erlang lsp-eslint lsp-fortran lsp-fsharp lsp-gdscript lsp-go lsp-gleam lsp-glsl lsp-graphql lsp-hack lsp-grammarly lsp-groovy lsp-haskell lsp-haxe lsp-idris lsp-java lsp-javascript lsp-json lsp-kotlin lsp-latex lsp-ltex lsp-lua lsp-markdown lsp-marksman lsp-mint lsp-nginx ...))
  seq-do(#f(compiled-function (package) #<bytecode 0x156bb517c469>) (ccls lsp-actionscript lsp-ada lsp-angular lsp-ansible lsp-awk lsp-astro lsp-bash lsp-beancount lsp-clangd lsp-clojure lsp-cmake lsp-credo lsp-crystal lsp-csharp lsp-css lsp-d lsp-dart lsp-dhall lsp-docker lsp-dockerfile lsp-elm lsp-elixir lsp-emmet lsp-erlang lsp-eslint lsp-fortran lsp-fsharp lsp-gdscript lsp-go lsp-gleam lsp-glsl lsp-graphql lsp-hack lsp-grammarly lsp-groovy lsp-haskell lsp-haxe lsp-idris lsp-java lsp-javascript lsp-json lsp-kotlin lsp-latex lsp-ltex lsp-lua lsp-markdown lsp-marksman lsp-mint lsp-nginx ...))
  lsp--require-packages()
  lsp()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook haskell-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook haskell-mode-hook))
  run-mode-hooks(haskell-mode-hook)
  haskell-mode()
  set-auto-mode-0(haskell-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  ......
michaelpj commented 10 months ago

I don't think we have a fourmolu variable, so I don't know that it's us? Do you have any local config?

ciukstar commented 10 months ago

I don't think we have a fourmolu variable, so I don't know that it's us? Do you have any local config?

I installed and updated as usual, using standard Emacs tools (package-install, list-packages U x).

Here are some tips. Maybe this will help.

$ grep -rn "fourmolu" .emacs.d/
grep: .emacs.d/elpa/lsp-haskell-20230823.1043/lsp-haskell.elc: binary file matches
.emacs.d/elpa/lsp-haskell-20230823.1043/lsp-haskell.el:53:  :type '(choice (const "brittany") (const "floskell") (const "fourmolu") (const "ormolu") (const "stylish-haskell") (const "none"))
.emacs.d/elpa/lsp-haskell-20230823.1043/lsp-haskell.el:314:(lsp-defcustom lsp-haskell-plugin-fourmolu-config-external nil
.emacs.d/elpa/lsp-haskell-20230823.1043/lsp-haskell.el:315:  "Call out to an external "fourmolu" executable, rather than using the bundled library"
.emacs.d/elpa/lsp-haskell-20230823.1043/lsp-haskell.el:319:  :lsp-path "haskell.plugin.fourmolu.config.external")

The whole .el file:

$ cat .emacs.d/elpa/lsp-haskell-20230823.1043/lsp-haskell.el
;;; lsp-haskell.el --- Haskell support for lsp-mode

;; Version: 1.1
;; Package-Requires: ((emacs "27.1") (lsp-mode "3.0") (haskell-mode "16.1"))
;; Keywords: haskell
;; URL: https://github.com/emacs-lsp/lsp-haskell

;;; License
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.

;;; Commentary:

;; Haskell specific adapter for LSP mode

;;; Code:

(require 'lsp-mode)
(require 'haskell-mode)

;; ---------------------------------------------------------------------
;; Configuration

(defgroup lsp-haskell nil
  "Customization group for ‘lsp-haskell’."
  :group 'lsp-mode)

;; ---------------------------------------------------------------------
;; Language server options

;; These are registered with lsp-mode below, which handles preparing them for the server.
;; Originally generated from the vscode extension's package.json using lsp-generate-bindings.
;; Should ideally stay in sync with what's offered in the vscode extension.

(defcustom-lsp lsp-haskell-formatting-provider
  "ormolu"
  "The formatter to use when formatting a document or range.
Ensure the plugin is enabled."
  :group 'lsp-haskell
  :type '(choice (const "brittany") (const "floskell") (const "fourmolu") (const "ormolu") (const "stylish-haskell") (const "none"))
  :lsp-path "haskell.formattingProvider")
(defcustom-lsp lsp-haskell-check-project
  t
  "Whether to typecheck the entire project on load.
It could lead to bad perfomance in large projects."
  :group 'lsp-haskell
  :type 'boolean
  :lsp-path "haskell.checkProject")
(defcustom-lsp lsp-haskell-max-completions
  40
  "Maximum number of completions sent to the editor."
  :group 'lsp-haskell
  :type 'number
  :lsp-path "haskell.maxCompletions")

;; ---------------------------------------------------------------------
;; Plugin-specific configuration
(defgroup lsp-haskell-plugins nil
  "Customization group for 'lsp-haskell' plugins."
  :group 'lsp-haskell)

(defcustom-lsp lsp-haskell-plugin-import-lens-code-actions-on
  t
  "Enables explicit imports code actions"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.importLens.codeActionsOn")
(defcustom-lsp lsp-haskell-plugin-import-lens-code-lens-on
  t
  "Enables explicit imports code lenses"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.importLens.codeLensOn")
(defcustom-lsp lsp-haskell-plugin-hlint-code-actions-on
  t
  "Enables hlint code actions (apply hints)"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.hlint.codeActionsOn")
(defcustom-lsp lsp-haskell-plugin-hlint-diagnostics-on
  t
  "Enables hlint diagnostics"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.hlint.diagnosticsOn")
(defcustom-lsp lsp-haskell-plugin-hlint-config-flags
  nil
  "Flags used by hlint"
  :group 'lsp-haskell-plugins
  :type 'lsp-string-vector
  :lsp-path "haskell.plugin.hlint.config.flags")
(defcustom-lsp lsp-haskell-plugin-eval-global-on
  t
  "Enables eval plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.eval.globalOn")
(defcustom-lsp lsp-haskell-plugin-module-name-global-on
  t
  "Enables module name plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.moduleName.globalOn")
(defcustom-lsp lsp-haskell-plugin-splice-global-on
  t
  "Enables splice plugin (expand template haskell definitions)"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.splice.globalOn")
(defcustom-lsp lsp-haskell-plugin-haddock-comments-global-on
  t
  "Enables haddock comments plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.haddockComments.globalOn")
(defcustom-lsp lsp-haskell-plugin-class-global-on
  t
  "Enables type class plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.class.globalOn")
(defcustom-lsp lsp-haskell-plugin-retrie-global-on
  t
  "Enables retrie plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.retrie.globalOn")
(defcustom-lsp lsp-haskell-plugin-stan-global-on
  t
  "Enables stan plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.stan.globalOn")
(defcustom-lsp lsp-haskell-plugin-tactics-global-on
  t
  "Enables Wingman (tactics) plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.tactics.globalOn")
(defcustom-lsp lsp-haskell-plugin-tactics-config-auto-gas
  4
  "The depth of the search tree when performing \"Attempt to fill hole\".
Bigger values will be able to derive more solutions,
but will take exponentially more time."
  :group 'lsp-haskell-plugins
  :type 'number
  :lsp-path "haskell.plugin.tactics.config.auto_gas")
(defcustom-lsp lsp-haskell-plugin-tactics-config-hole-severity
  nil
  "The severity to use when showing hole diagnostics."
  :group 'lsp-haskell-plugins
  :type '(choice (const 1) (const 2) (const 3) (const 4) (const nil))
  :lsp-path "haskell.plugin.tactics.config.hole_severity")
(defcustom-lsp lsp-haskell-plugin-tactics-config-max-use-ctor-actions
  5
  "Maximum number of `Use constructor <x>` code actions that can appear"
  :group 'lsp-haskell-plugins
  :type 'number
  :lsp-path "haskell.plugin.tactics.config.max_use_ctor_actions")
(defcustom-lsp lsp-haskell-plugin-tactics-config-timeout-duration
  2
  "The timeout for Wingman actions, in seconds"
  :group 'lsp-haskell-plugins
  :type 'number
  :lsp-path "haskell.plugin.tactics.config.timeout_duration")
(defcustom-lsp lsp-haskell-plugin-tactics-config-proofstate-styling
  t
  "Should Wingman emit styling markup when showing metaprogram proof states?"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.tactics.config.proofstate_styling")
(defcustom-lsp lsp-haskell-plugin-pragmas-code-actions-on
  t
  "Enables pragmas code actions"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.pragmas.codeActionsOn")
(defcustom-lsp lsp-haskell-plugin-pragmas-completion-on
  t
  "Enables pragmas completions"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.pragmas.completionsOn")
(defcustom-lsp lsp-haskell-plugin-ghcide-completions-config-auto-extend-on
  t
  "Extends the import list automatically when completing a out-of-scope identifier"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.ghcide-completions.config.autoExtendOn")
(defcustom-lsp lsp-haskell-plugin-ghcide-completions-config-snippets-on
  lsp-enable-snippet
  "Inserts snippets when using code completions"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.ghcide-completions.config.snippetsOn")
(defcustom-lsp lsp-haskell-plugin-ghcide-type-lenses-global-on
  t
  "Enables type lenses plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.ghcide-type-lenses.globalOn")
(defcustom-lsp lsp-haskell-plugin-ghcide-type-lenses-config-mode
  t
  "Control how type lenses are shown"
  :group 'lsp-haskell-plugins
  :type '(choice (const "always") (const "exported") (const "diagnostics"))
  :lsp-path "haskell.plugin.ghcide-type-lenses.config.mode")
(defcustom-lsp lsp-haskell-plugin-refine-imports-global-on
  t
  "Enables refine imports plugin"
  :group 'lsp-haskell-plugins
  :type 'boolean
  :lsp-path "haskell.plugin.refineImports.globalOn")

;; Updated for haskell-language-server 2.1.0.0

(lsp-defcustom lsp-haskell-plugin-cabal-code-actions-on t
  "Enables cabal code actions"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.cabal.codeActionsOn")

(lsp-defcustom lsp-haskell-plugin-cabal-completion-on t
  "Enables cabal completions"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.cabal.completionOn")

(lsp-defcustom lsp-haskell-plugin-pragmas-suggest-global-on t
  "Enables pragmas-suggest plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.pragmas-suggest.globalOn")

(lsp-defcustom lsp-haskell-plugin-alternate-number-format-global-on t
  "Enables alternateNumberFormat plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.alternateNumberFormat.globalOn")

(lsp-defcustom lsp-haskell-plugin-call-hierarchy-global-on t
  "Enables callHierarchy plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.callHierarchy.globalOn")

(lsp-defcustom lsp-haskell-plugin-change-type-signature-global-on t
  "Enables changeTypeSignature plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.changeTypeSignature.globalOn")

(lsp-defcustom lsp-haskell-plugin-class-code-actions-on t
  "Enables class code actions"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.class.codeActionsOn")

(lsp-defcustom lsp-haskell-plugin-class-code-lens-on t
  "Enables class code lenses"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.class.codeLensOn")

(lsp-defcustom lsp-haskell-plugin-eval-config-diff t
  "Enable the diff output (WAS/NOW) of eval lenses"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.eval.config.diff")

(lsp-defcustom lsp-haskell-plugin-eval-config-exception nil
  "Enable marking exceptions with `*** Exception:` similarly to doctest and GHCi."
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.eval.config.exception")

(lsp-defcustom lsp-haskell-plugin-explicit-fields-global-on t
  "Enables explicit-fields plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.explicit-fields.globalOn")

(lsp-defcustom lsp-haskell-plugin-explicit-fixity-global-on t
  "Enables explicit-fixity plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.explicit-fixity.globalOn")

(lsp-defcustom lsp-haskell-plugin-fourmolu-config-external nil
  "Call out to an external "fourmolu" executable, rather than using the bundled library"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.fourmolu.config.external")

(lsp-defcustom lsp-haskell-plugin-gadt-global-on t
  "Enables gadt plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.gadt.globalOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-code-actions-bindings-global-on t
  "Enables ghcide-code-actions-bindings plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-code-actions-bindings.globalOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-code-actions-fill-holes-global-on t
  "Enables ghcide-code-actions-fill-holes plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-code-actions-fill-holes.globalOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-code-actions-imports-exports-global-on t
  "Enables ghcide-code-actions-imports-exports plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-code-actions-imports-exports.globalOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-code-actions-type-signatures-global-on t
  "Enables ghcide-code-actions-type-signatures plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-code-actions-type-signatures.globalOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-completions-global-on t
  "Enables ghcide-completions plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-completions.globalOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-hover-and-symbols-hover-on t
  "Enables ghcide-hover-and-symbols hover"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-hover-and-symbols.hoverOn")

(lsp-defcustom lsp-haskell-plugin-ghcide-hover-and-symbols-symbols-on t
  "Enables ghcide-hover-and-symbols symbols"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.ghcide-hover-and-symbols.symbolsOn")

(lsp-defcustom lsp-haskell-plugin-overloaded-record-dot-global-on t
  "Enables overloaded-record-dot plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.overloaded-record-dot.globalOn")

(lsp-defcustom lsp-haskell-plugin-pragmas-completion-global-on t
  "Enables pragmas-completion plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.pragmas-completion.globalOn")

(lsp-defcustom lsp-haskell-plugin-pragmas-disable-global-on t
  "Enables pragmas-disable plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.pragmas-disable.globalOn")

(lsp-defcustom lsp-haskell-plugin-qualify-imported-names-global-on t
  "Enables qualifyImportedNames plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.qualifyImportedNames.globalOn")

(lsp-defcustom lsp-haskell-plugin-rename-config-cross-module nil
  "Enable experimental cross-module renaming"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.rename.config.crossModule")

(lsp-defcustom lsp-haskell-plugin-rename-global-on t
  "Enables rename plugin"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.rename.globalOn")

;; ---------------------------------------------------------------------
;; Non-language server options

(defcustom lsp-haskell-server-path
  "haskell-language-server-wrapper"
  "The language server executable.
Can be something on the $PATH (e.g. 'ghcide') or a path to an executable itself."
  :group 'lsp-haskell
  :type 'string)

(defcustom lsp-haskell-server-log-file
  (expand-file-name "hls.log" temporary-file-directory)
  "The log file used by the server.
Note that this is passed to the server via 'lsp-haskell-server-args', so if
you override that setting then this one will have no effect."
  :group 'lsp-haskell
  :type 'string)

(defcustom lsp-haskell-server-args
  `("-d" "-l" ,lsp-haskell-server-log-file)
  "The arguments for starting the language server.
For a debug log when using haskell-language-server, use `-d -l /tmp/hls.log'."
  :group 'lsp-haskell
  :type '(repeat (string :tag "Argument")))

(defcustom lsp-haskell-server-wrapper-function
  #'identity
  "Use this to wrap the language server process started by lsp-haskell.
For example, use the following the start the process in a nix-shell:
\(lambda (argv)
  (append
   (append (list \"nix-shell\" \"-I\" \".\" \"--command\" )
           (list (mapconcat 'identity argv \" \"))
           )
   (list (concat (lsp--suggest-project-root) \"/shell.nix\"))
   )
  )"
  :group 'lsp-haskell
  :type '(choice
          (function-item :tag "None" :value identity)
          (function :tag "Custom function")))

;; ---------------------------------------------------------------------
;; Miscellaneous options
;;
(defcustom lsp-haskell-completion-in-comments
  t
  "Whether to trigger completions in comments.
Note that this must be set to true in order to get completion of pragmas."
  :group 'lsp-haskell
  :type 'boolean)

;; ---------------------------------------------------------------------
;; Starting the server and registration with lsp-mode

(defun lsp-haskell--server-command ()
  "Command and arguments for launching the inferior language server process.
These are assembled from the customizable variables `lsp-haskell-server-path'
and `lsp-haskell-server-args' and `lsp-haskell-server-wrapper-function'."
  (funcall lsp-haskell-server-wrapper-function (append (list lsp-haskell-server-path "--lsp") lsp-haskell-server-args) ))

;; This mapping is set for 'haskell-mode -> haskell' in the lsp-mode repo itself. If we move
;; it there, then delete it from here.
;; It also isn't *too* important: it only sets the language ID, see
;; https://microsoft.github.io/language-server-protocol/specification#textDocumentItem
(add-to-list 'lsp-language-id-configuration '(haskell-literate-mode . "haskell"))
(add-to-list 'lsp-language-id-configuration '(haskell-tng-mode . "haskell"))
(add-to-list 'lsp-language-id-configuration '(haskell-cabal-mode . "haskell"))

;; Register the client itself
(lsp-register-client
  (make-lsp--client
    :new-connection (lsp-stdio-connection (lambda () (lsp-haskell--server-command)))
    ;; Should run under haskell-mode, haskell-literate-mode and haskell-tng-mode. We need to list haskell-literate-mode even though it's a derived mode of haskell-mode.
    :major-modes '(haskell-mode haskell-literate-mode haskell-tng-mode haskell-cabal-mode)
    ;; This is arbitrary.
    :server-id 'lsp-haskell
    ;; HLS does not currently send 'workspace/configuration' on startup (https://github.com/haskell/haskell-language-server/issues/2762),
    ;; so we need to push the configuration to it manually on startup. We should be able to
    ;; get rid of this once the issue is fixed in HLS.
    :initialized-fn (lambda (workspace)
                      (with-lsp-workspace workspace
                        (lsp--set-configuration (lsp-configuration-section "haskell"))))
    :synchronize-sections '("haskell")
    ;; This is somewhat irrelevant, but it is listed in lsp-language-id-configuration, so
    ;; we should set something consistent here.
    :language-id "haskell"
    :completion-in-comments? lsp-haskell-completion-in-comments
    ))

;; ---------------------------------------------------------------------

(provide 'lsp-haskell)
;;; lsp-haskell.el ends here
svenpanne commented 10 months ago

I have the exact same error after updating lsp-haskell today (via Spacemacs, but this doesn't matter here, I guess). Reverting lsp-haskell.el to the previous version solves the problem, so I'm quite sure that https://github.com/emacs-lsp/lsp-haskell/commit/d15bbb7e254f7a2b05a1f1511e453ed8c50eb434 is the guilty commit. It contains a section

(lsp-defcustom lsp-haskell-plugin-fourmolu-config-external nil
  "Call out to an external "fourmolu" executable, rather than using the bundled library"
  :type 'boolean
  :group 'lsp-haskell-plugins
  :package-version '(lsp-mode . "8.0.1")
  :lsp-path "haskell.plugin.fourmolu.config.external")

which looks closely related to the bug. It would be nice to have a fix or at least a quick revert until the problem has been solved.

Just a small addition: This bug seems to break all LSP-based modes, I noticed it when editing Python files using pylsp.

michaelpj commented 10 months ago

"Call out to an external "fourmolu" executable, rather than using the bundled library"

Oh good lord... spot the unescaped quotes 🤦

alanz commented 10 months ago

I remember having to correct that too, when I updated the config, now I think of it.

Perhaps we should update HLS to use single quotes in its descriptions.

And/or get it to spit out lsp-mode config as it does vscode config

alanz commented 10 months ago

And the CI process here should have caught it too.

michaelpj commented 10 months ago

https://github.com/emacs-lsp/lsp-haskell/pull/177 seems to work for me.

Perhaps we should update HLS to use single quotes in its descriptions.

This really doesn't seem like HLS's problem. I think the problem is the lsp-mode update script, which should escape quotes since it's generating elisp.

michaelpj commented 10 months ago

Should be fixed.

svenpanne commented 10 months ago

The fix works for me. :+1: Thanks for the lightning-fast response & fix!

ciukstar commented 10 months ago

lsp-haskell version 20230824.850 solved this issue. Thanks.