Skip to content

Commit

Permalink
Export project type
Browse files Browse the repository at this point in the history
This helps in the users configuring things like lsp-clients
accordingly.

Example (warn: changes are not buffer local)

	       (setq esy-mode-callback
		     (lambda (esy-project-type)
		       (cond ((eq esy-project-type 'opam)
			      (lsp-register-client
			       (make-lsp-client
				:new-connection (lsp-stdio-connection '("opam" "exec" "--" "ocamllsp"))
				:major-modes '(reason-mode tuareg-mode)
				:server-id 'opam-ocaml-lsp)))
			     ((eq esy-project-type 'esy)
			      (lsp-register-client
			       (make-lsp-client
				:new-connection (lsp-stdio-connection '("esy" "ocamllsp"))
				:major-modes '(reason-mode tuareg-mode)
				:server-id 'esy-ocaml-lsp)))
			     ((eq esy-project-type 'npm) (message "TODO: configure lsp for esy JS project")))
		       (message "esy-mode ready")))
  • Loading branch information
ManasJayanth committed Nov 30, 2020
1 parent 547125d commit 887698c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions esy-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
(defvar esy-command "esy"
"The 'esy' command. Can be full path to the esy binary.")

(defvar esy-mode-callback (lambda ())
(defvar esy-mode-callback (lambda (project-type))
"The callback that can be run once an esy project is initialised. Common use case is to enable ask lsp client to connect to the server (since this can only be done after the esy project is ready)")

(defun esy/f--read (file-path)
Expand Down Expand Up @@ -300,6 +300,7 @@ package.json or not"
"Initialises esy-mode with necessary config. Relies on global vars like esy-command esy-mode-callback"
(make-local-variable 'process-environment)
(make-local-variable 'exec-path)
(make-local-variable 'merlin-command)
(if (file-exists-p esy-command)
(let ((esy-bin-dir (file-name-directory esy-command)))
(add-to-list 'exec-path esy-bin-dir)
Expand Down Expand Up @@ -333,7 +334,7 @@ package.json or not"
(callback
(lambda (config-plist)
(setq merlin-command (executable-find "ocamlmerlin"))
(funcall esy-mode-callback))))
(funcall esy-mode-callback project-type))))
(cond ((eq project-type 'opam)
(esy/setup--opam project
callback))
Expand Down

0 comments on commit 887698c

Please sign in to comment.