Skip to content

chore: add some configuration settings to OCamllsp #4689

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 88 additions & 17 deletions clients/lsp-ocaml.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -45,43 +55,104 @@
(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))
:major-modes '(reason-mode caml-mode tuareg-mode)
: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
:new-connection
(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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is a bit weird here.


(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.
Expand Down
Loading