Skip to content

Commit

Permalink
Factor out "esy status" related functions in a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Nov 19, 2024
1 parent 0f34582 commit 02cba3b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 22 deletions.
57 changes: 57 additions & 0 deletions esy-core.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;;; esy-core --- core library for minor mode and esy.el. -*- lexical-binding: t; -*-

;; Copyright (C) 2020 Manas Jayanth

;; Author: Manas Jayanth <[email protected]>
;; Created: 19 November 2024
;; Keywords: Reason, OCaml
;; Package-Requires: ((emacs "25.1"))
;; Homepage: http://example.com/foo

;;; Commentary:

;;; Change Log: TODO

;;; Code:

;; macros
(defmacro esy/macro--with-esy-project (buffer binding-project exp)
`(let ((project (esy/project--of-buffer ,buffer)))
(if (esy/project--p project)
(let ((,binding-project project)) ,exp)
(message "Doesn't look like an esy project. esy-mode will stay dormant"))))

(defmacro let-esy-project (binding exp)
`(let ((,(car binding) ,(cadr binding)))
(if (esy/project--p ,(car binding))
,exp
(message "Doesn't look like an esy project. esy-mode will stay dormant"))))

;;;;;;;;;;;;;;;;;;; esy/status--* defuns ;;;;;;;;;;;;;;;;;;;;;;;
(defun esy/status--get-manifest-file-path (esy-status)
"Given the json object of \'esy status\' output,
it returns the manifest file"
(gethash "rootPackageConfigPath" esy-status))

(defun esy/status--dependencies-installed-p (esy-status)
"Given the json object of \'esy status\' output,
it returns if dependencies have been installed."
(gethash "isProjectFetched" esy-status))

(defun esy/status--dependency-constraints-solved-p (esy-status)
"Given the json object of \'esy status\' output,
it returns if dependencies have been installed."
(gethash "isProjectSolved" esy-status))

(defun esy/status--ready-for-dev-p (esy-status)
"Given the json object of \'esy status\' output,
it returns if dependencies have been installed."
(gethash "isProjectReadyForDev" esy-status))

(defun esy/status--project-p (esy-status)
"Given the json object of \'esy status\' output,
it returns if dependencies have been installed."
(gethash "isProject" esy-status))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(provide 'esy-core)
28 changes: 6 additions & 22 deletions esy-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,11 @@
;;; Code:
(require 'json)

;; esy libraries
;; esy utils libraries
(require 'esy-utils)

;; macros
(defmacro esy/macro--with-esy-project (buffer binding-project exp)
`(let ((project (esy/project--of-buffer ,buffer)))
(if (esy/project--p project)
(let ((,binding-project project)) ,exp)
(message "Doesn't look like an esy project. esy-mode will stay dormant"))))

(defmacro let-esy-project (binding exp)
`(let ((,(car binding) ,(cadr binding)))
(if (esy/project--p ,(car binding))
,exp
(message "Doesn't look like an esy project. esy-mode will stay dormant"))))
;; esy core defuns
(require 'esy-core)

;; Errors
(define-error 'esy-mode-error "Internal esy-mode error occurred" 'error)
Expand All @@ -76,11 +66,6 @@
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/internal-status--get-manifest-file-path (esy-status)
"Given the json object of \'esy status\' output,
it returns the manifest file"
(gethash "rootPackageConfigPath" esy-status))

(defun esy/prompt--ask-for-project-root ()
"Prompts user for project root"
(let ((prompt-msg "Couldn't detect project root. Enter project root (where opam or esy manifests are present): ")
Expand Down Expand Up @@ -228,17 +213,16 @@ later be used to obtain more info about the esy project"
(defun esy/project--fetched-p (project)
"Returns if a given project's sources have been solved and fetched. This
is necessary for commands like 'esy command-env', 'esy build-plan' etc to work."
(gethash "isProjectFetched" (plist-get project 'json)))
(esy/status--dependencies-installed-p (plist-get project 'json)))

(defun esy/project--ready-p (project)
"Returns if a given project is ready for
development ie. if the tools can be looked in it's sandbox"
(gethash "isProjectReadyForDev" (plist-get project 'json)))
(esy/status--ready-for-dev-p (plist-get project 'json)))

(defun esy/project--p (project)
"Returns if a given project structure is a valid esy project"
(let ((esy-status-json (plist-get project 'json)))
(when esy-status-json (gethash "isProject" esy-status-json))))
(esy/status--project-p (plist-get project 'json)))

(defun esy/command-env--of-project (project)
"Given a project, it returns an abstract structure
Expand Down

0 comments on commit 02cba3b

Please sign in to comment.