From 02cba3ba3f473405b3100fc08954f2c0795026b5 Mon Sep 17 00:00:00 2001 From: Manas Jayanth <3097018+ManasJayanth@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:13:28 +0530 Subject: [PATCH] Factor out "esy status" related functions in a separate file --- esy-core.el | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ esy-mode.el | 28 ++++++-------------------- 2 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 esy-core.el diff --git a/esy-core.el b/esy-core.el new file mode 100644 index 0000000..3f4643d --- /dev/null +++ b/esy-core.el @@ -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 +;; 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) diff --git a/esy-mode.el b/esy-mode.el index 0f0d157..ae3bed3 100644 --- a/esy-mode.el +++ b/esy-mode.el @@ -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) @@ -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): ") @@ -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