Skip to content

Commit 39452e4

Browse files
liaowang11kritzcreek
authored andcommitted
replace psc-ide-server with purs ide server (#96)
* replace `psc-ide-server` with `purs ide server` * add a switch between old psc-ide-server and purs, defaulting to psc-ide-server for now * Fix for starting psc-ide-server without arguments * Default `psc-ide-use-purs` to `t` and always passing globs, update error notice
1 parent ac8b8e1 commit 39452e4

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

README.org

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* psc-ide-emacs
44

5-
Emacs integration for [[https://github.com/purescript/purescript/tree/master/psc-ide-server][psc-ide]]
5+
Emacs integration for [[https://github.com/purescript/purescript/tree/master/psc-ide][psc-ide]]
66

77
** Installation
88

@@ -32,7 +32,7 @@
3232
#+END_SRC
3333

3434
If you want to use the psc-ide server that is relative to your `npm bin`
35-
directory, e.g. `./node_modules/.bin/psc-ide-server`, add this line to your
35+
directory, e.g. `./node_modules/.bin/purs`, add this line to your
3636
config:
3737

3838
#+BEGIN_SRC elisp

psc-ide.el

+41-20
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,25 @@
6262
:group 'psc-ide)
6363

6464
(defcustom psc-ide-server-executable "psc-ide-server"
65-
"Path to the 'psc-ide-server' executable."
65+
"Path to the 'psc-ide-server' executable"
66+
:group 'psc-ide
67+
:type 'string)
68+
69+
(defcustom psc-ide-purs-executable "purs"
70+
"Path to the 'purs' executable."
6671
:group 'psc-ide
6772
:type 'string)
6873

6974
(defcustom psc-ide-use-npm-bin nil
70-
"Whether to use `npm bin` to determine the location of the psc-ide server."
75+
"Whether to use `npm bin` to determine the location of the psc ide server."
7176
:group 'psc-ide
7277
:type 'boolean)
7378

79+
(defcustom psc-ide-use-purs t
80+
"Whether to use `purs ide' to start psc ide server, if nil fallback to use old psc-ide-server"
81+
:group 'psc-ide
82+
:type 'boolean)
83+
7484
(defcustom psc-ide-port 4242
7585
"The port that psc-ide-server uses."
7686
:group 'psc-ide
@@ -360,44 +370,55 @@ use when the search used was with `string-match'."
360370

361371

362372
(defun psc-ide-ask-project-dir ()
363-
"Ask psc-ide-server for the project dir."
373+
"Ask psc-ide server for the project dir."
364374
(interactive)
365375
(psc-ide-send psc-ide-command-cwd
366376
(-compose 'message 'psc-ide-unwrap-result)))
367377

368378
(defun psc-ide-server-start-impl (dir-name)
369-
"Start psc-ide-server."
379+
"Start psc-ide server."
370380
(apply 'start-process `("*psc-ide-server*" "*psc-ide-server*"
371381
,@(psc-ide-server-command dir-name))))
372382

373383
(defun psc-ide-server-command (dir-name)
374-
"Tries to find the psc-ide-server-executable and builds up the
384+
"Tries to find the psc-ide executable and builds up the
375385
command by appending eventual options. Returns a list that can
376386
be expanded and passed to start-process"
377-
(let* ((npm-bin-path (if psc-ide-use-npm-bin
378-
(psc-ide-npm-bin-server-executable)
387+
(let* ((executable-name (psc-ide-executable-name))
388+
(npm-bin-path (if psc-ide-use-npm-bin
389+
(psc-ide-npm-bin-server-executable executable-name)
379390
nil))
380-
(path (or npm-bin-path (executable-find psc-ide-server-executable)))
391+
(path (or npm-bin-path (executable-find executable-name)))
392+
(cmd (if psc-ide-use-purs
393+
`(,path "ide" "server")
394+
`(,path)))
381395
(port (number-to-string psc-ide-port))
382396
(directory (expand-file-name dir-name))
383-
(debug-flag (when psc-ide-debug "--debug"))
384-
(globs (when (psc-ide--version-gte (psc-ide-server-version) "0.9.2") psc-ide-source-globs)))
397+
(debug-flags (when psc-ide-debug (if psc-ide-use-purs
398+
'("--log-level" "debug")
399+
'("--debug")))))
385400
(if path
386-
(remove nil `(,path "-p" ,port "-d" ,directory "--output-directory" ,psc-ide-output-directory ,debug-flag ,@globs))
387-
(error (s-join " " '("Couldn't locate the psc-ide-server executable. You"
388-
"could either customize the psc-ide-server-executable"
389-
"setting, or set the psc-ide-use-npm-bin variable to"
390-
"true, or put the executable on your path."))))))
391-
392-
(defun psc-ide-npm-bin-server-executable ()
393-
"Find psc-ide-server binary of current project by invoking `npm bin`"
401+
(remove nil `(,@cmd "-p" ,port "-d" ,directory "--output-directory" ,psc-ide-output-directory ,@debug-flags ,@psc-ide-source-globs))
402+
(error (s-join " " '("Couldn't locate psc ide executable. You"
403+
"could either customize the psc-ide-purs-executable"
404+
" or psc-ide-server-executable if psc-ide-use-purs is nil,"
405+
" or set the psc-ide-use-npm-bin variable to"
406+
" true, or put the executable on your path."))))))
407+
(defun psc-ide-executable-name ()
408+
"Find ide executable name"
409+
(if psc-ide-use-purs
410+
psc-ide-purs-executable
411+
psc-ide-server-executable))
412+
413+
(defun psc-ide-npm-bin-server-executable (cmd)
414+
"Find psc-ide server binary of current project by invoking `npm bin`"
394415
(let* ((npm-bin (s-trim-right (shell-command-to-string "npm bin")))
395-
(server (expand-file-name psc-ide-server-executable npm-bin)))
416+
(server (expand-file-name cmd npm-bin)))
396417
(if (and server (file-executable-p server)) server nil)))
397418

398419
(defun psc-ide-server-version ()
399420
"Returns the version of the found psc-ide-server executable"
400-
(let ((path (executable-find psc-ide-server-executable)))
421+
(let ((path (executable-find (psc-ide-executable-name))))
401422
(s-chomp (shell-command-to-string (s-concat path " --version")))))
402423

403424
(defun psc-ide--version-gte (version1 version2)

0 commit comments

Comments
 (0)