Skip to content

Commit

Permalink
change entrypoint in lem-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Dec 10, 2023
1 parent a4e3a9f commit 0d34c1e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
5 changes: 3 additions & 2 deletions frontends/jsonrpc/lem-jsonrpc.asd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"lem/extensions"
"jsonrpc"
"trivial-utf-8"
"jsonrpc/transport/stdio")
"jsonrpc/transport/stdio"
"command-line-arguments")
:serial t
:components ((:file "jsonrpc-stdio-patch")
(:file "utils")
Expand All @@ -13,5 +14,5 @@
(defsystem "lem-jsonrpc/executable"
:build-operation program-op
:build-pathname "lem-rpc"
:entry-point "lem:main"
:entry-point "lem-jsonrpc:program"
:depends-on ("lem-jsonrpc" "lem-electron-backend"))
48 changes: 39 additions & 9 deletions frontends/jsonrpc/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
(:use :cl
:lem-jsonrpc/utils
:lem-jsonrpc/view)
(:local-nicknames (:display :lem-core/display)))
(:local-nicknames (:display :lem-core/display))
(:export :program))
(in-package :lem-jsonrpc)

(defparameter *default-port* 50879)

(defvar *mode*)
(defvar *port*)
(defvar *editor-thread*)

(pushnew :lem-jsonrpc *features*)
Expand Down Expand Up @@ -79,12 +80,14 @@
(notify jsonrpc "exit" nil)
(uiop:quit 0)))

#+(or)
(jsonrpc:server-listen (jsonrpc-server jsonrpc)
:mode :tcp
:port *default-port*)
(jsonrpc:server-listen (jsonrpc-server jsonrpc)
:mode :stdio)))
(ecase *mode*
(:tcp
(jsonrpc:server-listen (jsonrpc-server jsonrpc)
:mode :tcp
:port *port*))
(:stdio
(jsonrpc:server-listen (jsonrpc-server jsonrpc)
:mode :stdio)))))

(defmethod lem-if:get-background-color ((jsonrpc jsonrpc))
(log:info jsonrpc)
Expand Down Expand Up @@ -495,3 +498,30 @@
(with-output-to-string (stream)
(let ((stream (yason:make-json-output-stream stream)))
(yason:encode args stream)))))))

;;;
(defparameter +command-line-spec+
;; TODO: more helpful documentation
'((("mode" #\m) :type string :optional t :documentation "\"tcp\" or \"stdio\"")
(("port" #\p) :type integer :optional nil :documentation "port of \"tcp\"")))

(defun program (&optional (args (uiop:command-line-arguments)))
(command-line-arguments:handle-command-line
+command-line-spec+
(lambda (&key (mode "stdio") port)
(cond ((string= mode "tcp")
(unless port
(command-line-arguments:show-option-help +command-line-spec+)
(uiop:quit 1))
(let ((*mode* :tcp)
(*port* port))
(lem:lem)))
((string= mode "stdio")
(let ((*mode* :stdio))
(lem:lem)))
(t
(command-line-arguments:show-option-help +command-line-spec+)
(uiop:quit 1))))
:name "lem-rpc"
:positional-arity 0
:command-line args))

0 comments on commit 0d34c1e

Please sign in to comment.