Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed swank-js within existing node.js server #65

Merged
merged 7 commits into from
Apr 2, 2013

Conversation

mwolson
Copy link
Contributor

@mwolson mwolson commented Mar 17, 2013

Here are some changes I've made to support embedding swank-js within an existing node.js server, with the goal being to inspect and modify state within that server.

I'm looking for comments to see whether honing these changes is worth it. They're not usable as-is for the main repo, but if some of it were made configurable, it might be useful.

One change that could be taken by itself (with some modification) is limiting stacktrace output in errors so that it doesn't overwhelm Emacs REPL buffers.

Example for integrating into another server:

  var swank = require('swank-js');

  // Optionally start the swank REPL
  if (self.config.get('swank')) {
    if (self.config.get('swank:slime:enable')) {
      var swankPort = self.config.get('swank:slime:port') || 4005;
      swank.startSwankServer(swankPort);
      self.log.info('Swank SLIME server listening on http://localhost:' + swankPort);
    }
    if (self.config.get('swank:socketIO:enable')) {
      var socketIOPort = self.config.get('swank:socketIO:port') || 8009;
      swank.startSocketIOServer(socketIOPort);
      self.log.info('Swank socket.io server listening on http://localhost:' + socketIOPort);
    }
  }

Michael Olson added 5 commits March 16, 2013 20:47
By default swank-js starts a server as soon as it is required.  Instead export functions to start the servers, and
remove the default behavior of relying on argv.
…mand

* Remove custom quit_lisp handler
* Add built-in quit-lisp handler
* Provide self and response object to custom methods so they can accomplish more
* Deal with quit message from handler
* Note: if the client reconnects, they will have the same context as previous client
Better is to rewrite these calls to use some other function that conditionally does logging.
@rksm
Copy link
Contributor

rksm commented Mar 17, 2013

Thanks for contributing! What's the difference to using require("swank-js/client/node").setupNodeJSClient();?

@mwolson
Copy link
Contributor Author

mwolson commented Mar 17, 2013

The difference is that require("swank-js/client/node").setupNodeJSClient(); is a client for an existing server. Not a server in itself. So it didn't seem like it was capable of evaluating code within the global context of my app from SLIME.

@mwolson
Copy link
Contributor Author

mwolson commented Mar 17, 2013

Another related thing I noticed was that in order to prevent SLIME from trying to launch the entire node.js process (instead of just connecting to it via TCP), I had to do this to make C-c C-z from a newly-opened .js file Just Work. Would be nice if there was a better way.

;; Node REPL using SLIME
(add-to-list 'load-path (concat my-emacs-path "/elisp/slime"))
(add-to-list 'load-path (concat my-emacs-path "/elisp/slime/contrib"))
(require 'slime)
(autoload 'slime-js-minor-mode "slime-js" nil t)
(add-hook 'js2-mode-hook
          (lambda ()
            (slime-js-minor-mode 1)))
(slime-setup '(slime-repl slime-js))
(setq slime-auto-connect 'always)
(setq slime-kill-without-query-p t)
(setq slime-protocol-version 'ignore)

(defun slime ()
  (interactive)
  (let ((process (slime-connect "localhost" 4005)))
    ;; Use "NODE" instead of nil in the REPL buffer name
    (setf (slime-connection-name process) "NODE")))

@wallyqs
Copy link

wallyqs commented Apr 2, 2013

+1!
Is there something in particular that is holding this back? I just tried this, and it looks really useful! 👍

@jonnay
Copy link
Member

jonnay commented Apr 2, 2013

Looks great! Thanks! can you update the wiki with some instructions?

Cheers!

jonnay added a commit that referenced this pull request Apr 2, 2013
Embed swank-js within existing node.js server
@jonnay jonnay merged commit ab4684a into swank-js:master Apr 2, 2013
@mwolson
Copy link
Contributor Author

mwolson commented Apr 5, 2013

One thing to be aware of is that require() currently does not work with my patches, so may want to fix that before the next release. I'm thinking about plugging this into the built-in node.js REPL as a way of solving that. Possibly by taking a particular version of repl.js from node source and making small changes, possibly by just opening a socket to the one that comes with node.js.

@wallyqs
Copy link

wallyqs commented Apr 7, 2013

I updated the wiki with some instructions on how I used it, hope this helps.
https://github.com/swank-js/swank-js/wiki/Embed-Swank-server-in-a-Node.js-application

@mwolson mwolson deleted the attachable-server branch April 7, 2013 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants