diff --git a/clients/lsp-ocaml.el b/clients/lsp-ocaml.el index 59ffa9cb18..4d5102aac5 100644 --- a/clients/lsp-ocaml.el +++ b/clients/lsp-ocaml.el @@ -31,10 +31,20 @@ :group 'lsp-mode :link '(url-link "https://github.com/freebroccolo/ocaml-language-server")) -(define-obsolete-variable-alias - 'lsp-ocaml-ocaml-lang-server-command - 'lsp-ocaml-lang-server-command - "lsp-mode 6.1") +(defgroup lsp-ocaml-lsp-server nil + "LSP support for OCaml, using ocaml-lsp-server." + :group 'lsp-mode + :link '(url-link "https://github.com/ocaml/ocaml-lsp")) + +;; Custom vars +(defcustom lsp-ocaml-lsp-server-command + '("ocamllsp") + "Command to start ocaml-language-server." + :group 'lsp-ocaml + :type '(choice + (string :tag "Single string value") + (repeat :tag "List of string values" + string))) (defcustom lsp-ocaml-lang-server-command '("ocaml-language-server" "--stdio") @@ -45,6 +55,58 @@ (repeat :tag "List of string values" string))) +(defcustom lsp-ocaml-semantic-highlighting '("full") + "Semantic highlighting options for ocaml-language-server. + + To enable non-incremental (expectedly slower but more stable) + version, choose 'Full'. + + To enable incremental (potentially faster but more + error-prone) version, choose 'Full Delta'." + :group 'lsp-ocaml + :type '(choice + (const :tag "Full" "full") + (const :tag "Full Delta" "full/delta"))) + +(defcustom lsp-ocaml-extended-hover nil + "Alternative hover command providing additional information." + :group 'lsp-ocaml + :type 'boolean) + +(defcustom lsp-ocaml-codelens nil + "Enable CodeLens." + :group 'lsp-ocaml + :type 'boolean) + +(defcustom lsp-ocaml-dune-diagnostics t + "Use dune to provide diagnostics, such as mli and ml type mismatches." + :group 'lsp-ocaml + :type 'boolean) + +(defcustom lsp-ocaml-inlay-hints nil + "Enable inlay hints." + :group 'lsp-ocaml + :type 'boolean) + +(defcustom lsp-ocaml-syntax-documentation nil + "Display documentation about when hovering over OCaml code." + :group 'lsp-ocaml + :type 'boolean) + +(defcustom lsp-ocaml-merlin-jump-code-actions nil + "Allow Merlin-type code navigation in a source buffer." + :group 'lsp-ocaml + :type 'boolean) + +(defcustom lsp-ocaml-trace-server "off" + "Enable tracing of the server communication." + :group 'lsp-ocaml + :type '(choice + (const :tag "Off" "off") + (const :tag "Compact" "compact") + (const :tag "Messages" "messages") + (const :tag "Verbose" "verbose"))) + (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection (lambda () lsp-ocaml-lang-server-command)) @@ -52,22 +114,28 @@ :priority -1 :server-id 'ocaml-ls)) -(defgroup lsp-ocaml-lsp-server nil - "LSP support for OCaml, using ocaml-lsp-server." - :group 'lsp-mode - :link '(url-link "https://github.com/ocaml/ocaml-lsp")) +;; Obsolete aliases +(define-obsolete-variable-alias + 'lsp-ocaml-ocaml-lang-server-command + 'lsp-ocaml-lang-server-command + "lsp-mode 6.1") (define-obsolete-variable-alias 'lsp-merlin 'lsp-ocaml-lsp-server "lsp-mode 6.1") (define-obsolete-variable-alias 'lsp-merlin-command 'lsp-ocaml-lsp-server-command "lsp-mode 6.1") -(defcustom lsp-ocaml-lsp-server-command - '("ocamllsp") - "Command to start ocaml-language-server." - :group 'lsp-ocaml - :type '(choice - (string :tag "Single string value") - (repeat :tag "List of string values" - string))) + +;; TODO most of these need some sort of command implementation +(defun lsp-ocaml--make-custom-settings () + "Return custom settings for ocaml-language-server." + (list + :extendedHover (list :enable lsp-ocaml-extended-hover) + :codelens (list :enable lsp-ocaml-codelens) + :duneDiagnostics (list :enable lsp-ocaml-dune-diagnostics) + :inlayHints (list :enable lsp-ocaml-inlay-hints) + :syntaxDocumentation (list :enable lsp-ocaml-syntax-documentation) + :merlinJumpCodeActions (list :enable lsp-ocaml-merlin-jump-code-actions) + :trace (list :server lsp-ocaml-trace-server) + :extendedHover (list :enable lsp-ocaml-extended-hover))) (lsp-register-client (make-lsp-client @@ -75,13 +143,16 @@ (lsp-stdio-connection (lambda () lsp-ocaml-lsp-server-command)) :major-modes '(reason-mode caml-mode tuareg-mode) :priority 0 + :environment-fn (lambda () + '(("OCAMLLSP_SEMANTIC_HIGHLIGHTING" . lsp-ocaml-semantic-highlighting))) + :initialization-options 'lsp-ocaml--make-custom-settings :server-id 'ocaml-lsp-server)) (defcustom lsp-cut-signature 'space "If non-nil, signatures returned on hover will not be split on newline." :group 'lsp-ocaml :type '(choice (symbol :tag "Default behaviour" 'cut) - (symbol :tag "Display all the lines with spaces" 'space))) + (symbol :tag "Display all the lines with spaces" 'space))) (cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql ocaml-lsp-server)) &optional storable) "Extract a representative line from OCaml's CONTENTS, to show in the echo area.