Git Product home page Git Product logo

nrebl.middleware's Introduction

nrebl.middleware

Clojars Project

VERY ALPHA

The start of an nREPL middleware that will spy on an nREPL connection and capture the results of evaluation for browsing in REBL.

NOTE: REBL requires a commercial license if it's to be used for commercial work

Installation (tools.deps)

  1. Install clojure
  2. Install REBL to a known path
  3. Include some aliases either in your ~/.clojure/deps.edn or your projects deps.edn respectively. Note the :rebl-8 and :rebl-11 aliases are for running either on Oracle's JDK 8 (which bundles JavaFX) or OpenJDK 11 which doesn't.
{:aliases {
           :nrebl {:extra-deps {nrepl {:mvn/version "RELEASE"}
                                cider/cider-nrepl {:mvn/version "0.21.0"}
                                refactor-nrepl {:mvn/version "2.4.0"}
                                rickmoynihan/nrebl.middleware {:mvn/version "0.2.0"}}
          :main-opts ["-e" "((requiring-resolve,'cognitect.rebl/ui))" "-m" "nrepl.cmdline" "-i" "--middleware" "[nrebl.middleware/wrap-nrebl,cider.nrepl/cider-middleware]"]}
	  
           :nrepl {:extra-deps {nrepl/nrepl {:mvn/version "0.6.0"}}}
           ;; - see https://github.com/cognitect-labs/REBL-distro
           ;; - you need to download the REBL JAR (and update the local/root below)
           ;; - you need to be using Clojure 1.10 and either
           ;; - - Oracle JDK 8 -- use :rebl-8
           ;; - - OpenJDK 11 -- use :rebl-11
           :rebl-8
           {:extra-deps {org.clojure/core.async {:mvn/version "0.4.490"}
                         ;; deps for file datafication (0.9.149 or later)
                         org.clojure/data.csv {:mvn/version "0.1.4"}
                         org.clojure/data.json {:mvn/version "0.2.3"}
                         org.yaml/snakeyaml {:mvn/version "1.23"}
                         com.cognitect/rebl
                         ;; adjust to match your install location
                         {:local/root "/Developer/REBL/latest/REBL.jar"}}
            :main-opts ["-m" "cognitect.rebl"]}
            :rebl-11
            {:extra-deps {org.clojure/core.async {:mvn/version "0.4.490"}
                          ;; deps for file datafication (0.9.149 or later)
                          org.clojure/data.csv {:mvn/version "0.1.4"}
                          org.clojure/data.json {:mvn/version "0.2.3"}
                          org.yaml/snakeyaml {:mvn/version "1.23"}
                          com.cognitect/rebl
                          ;; adjust to match your install location
                          {:local/root "/Developer/REBL/latest/REBL.jar"}
                          org.openjfx/javafx-fxml     {:mvn/version "11.0.1"}
                          org.openjfx/javafx-controls {:mvn/version "11.0.1"}
                          org.openjfx/javafx-graphics {:mvn/version "11.0.1"}
                          org.openjfx/javafx-media    {:mvn/version "11.0.1"}
                          org.openjfx/javafx-swing    {:mvn/version "11.0.1"}
                          org.openjfx/javafx-base     {:mvn/version "11.0.1"}
                          org.openjfx/javafx-web      {:mvn/version "11.0.1"}}
             :main-opts ["-m" "cognitect.rebl"]}

             :cider {:extra-deps {cider/cider-nrepl {:mvn/version "0.22.1"
                                  refactor-nrepl {:mvn/version "2.4.0"}}}}}}}}

Usage

Assuming OpenJDK 11:

clj -R:nrepl:cider:rebl-11 -A:nrebl

Or Oracle JDK 8:

clj -R:nrepl:cider:rebl-8 -A:nrebl

You should now be able to connect to your nREPL through your editor or via an nREPL client and have nREBL capture the evaluation of forms.

Installation (leiningen)

Assuming you're running a recent leiningen (2.9.1) follow the steps:

  1. Install REBL to a known path.
  2. Add the following to your ~/.lein/profiles.clj file in order to configure nrebl as part of your :user profile:
 :nrebl  {:repl-options {:nrepl-middleware [nrebl.middleware/wrap-nrebl]}
         :dependencies [[rickmoynihan/nrebl.middleware "0.2.0"] ;; set this to the latest nrebl version
                        [org.clojure/core.async "0.4.490"]]
         :resource-paths ["/Users/rick/Software/rebl/REBL-0.9.157.jar"] ;; set this to where your REBL jar is installed
         :injections [(require '[cognitect.rebl :as rebl])]
         }

 :user [:nrebl
        ;;:other-tool-profiles...]

NOTE: the above configuration stores all :nrebl config in a single profile which is then merged into the :user profile, which will be available in dev/repl environments. It is usually cleaner to do it this way as it makes it explicit what configuration belongs to each tool.

Usage (lein)

  1. Run lein repl and/or connect to nREPL with your Editor.
  2. Evaluate (rebl/ui) (the :injections should make this available in every namespace)
  3. The REBL UI should appear
  4. Evaluate more forms in the REPL, they should each then appear in REBL.

Help Wanted

There's lots that can be done to improve this. Help & suggestions welcome.

Thanks to

License

Copyright © 2018 Rick Moynihan

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

nrebl.middleware's People

Contributors

cichli avatar danieroux avatar dharrigan avatar iamdrowsy avatar rickmoynihan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nrebl.middleware's Issues

Managed REBL window

Running REBL from within CIDER opens a new JavaFX window that is not recognized and managed by MacOS. As a result, after switching windows via cmd+tab one cannot find it again via cmd+tab.

If I start REBL via (1), then there is a managed Java window one can correctly cmd+tab to.

If I start REBL via (2), then there is a headless Java window.

Interestingly, if I start an nrepl session (3), and run (cognitect.rebl/-main), it also will start a headless Java window.

;; (1)
clj -A:rebl -m cognitect.rebl

;; (2)
clj -A:nrepl:cider:rebl -m nrepl.cmdline --middleware '[nrebl.middleware/wrap-nrebl cider.nrepl/cider-middleware]'

;; (3)
clj -A:nrepl:cider:rebl -m nrepl.cmdline --middleware '[nrebl.middleware/wrap-nrebl cider.nrepl/cider-middleware]' --interactive

(require 'cognitect.rebl)
(cognitect.rebl/-main)

values are shown quoted ("")?

Thanks for publishing this middleware!

I have tried to use it with boot-clj. Everything seems to work except that values are quoted as if they are printed with pr-str.

I'm not sure as to whether this is an issue of the boot middleware or not. I have monkeypatched send-to-rebl in my project to fix it for my situation. You can find that patch here

Evals blow up if REBL is not running

I don't want to always have a REBL launched in order to use my nrepl, but it looks like if there isn't a REBL any eval will blow up with:

#error {
 :cause nil
 :via
 [{:type clojure.lang.ExceptionInfo
   :message nil
   :data #:clojure.error{:phase :print-eval-result}
   :at [clojure.main$repl$read_eval_print__9068 invoke "main.clj" 419]}
  {:type java.lang.NullPointerException
   :message nil
   :at [java.io.StringReader <init> "StringReader.java" 50]}]
 :trace
 [[java.io.StringReader <init> "StringReader.java" 50]
  [clojure.lang.RT readString "RT.java" 1873]
  [clojure.lang.RT readString "RT.java" 1869]
  [clojure.core$read_string invokeStatic "core.clj" 3815]
  [clojure.core$read_string invoke "core.clj" 3805]
  [nrebl.middleware$send_to_rebl_BANG_ invokeStatic "middleware.clj" 29]
  [nrebl.middleware$send_to_rebl_BANG_ invoke "middleware.clj" 27]
  [nrebl.middleware$wrap_rebl_sender$reify__877 send "middleware.clj" 43]
  [nrepl.middleware.caught$caught_transport$reify__22510 send "caught.clj" 58]
  [nrepl.middleware.load_file$wrap_load_file$fn$reify__22599 send "load_file.clj" 95]
  [nrepl.middleware.interruptible_eval$evaluate$fn__22560 invoke "interruptible_eval.clj" 114]
  [clojure.main$repl$read_eval_print__9068 invoke "main.clj" 419]
  [clojure.main$repl$fn__9077 invoke "main.clj" 435]
  [clojure.main$repl invokeStatic "main.clj" 435]
  [clojure.main$repl doInvoke "main.clj" 345]
  [clojure.lang.RestFn invoke "RestFn.java" 1523]
  [nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 79]
  [nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55]
  [nrepl.middleware.interruptible_eval$interruptible_eval$fn__22569$fn__22573 invoke "interruptible_eval.clj" 142]
  [clojure.lang.AFn run "AFn.java" 22]
  [nrepl.middleware.session$session_exec$main_loop__22650$fn__22654 invoke "session.clj" 171]
  [nrepl.middleware.session$session_exec$main_loop__22650 invoke "session.clj" 170]
  [clojure.lang.AFn run "AFn.java" 22]

This was from attempting to eval any value like 1 or "foo".

Syntax error compiling at (nrebl/middleware.clj:1:1)

I'm trying to setup the middleware with leiningen. My profile.clj looks like this

{
 :nrebl  {:repl-options {:nrepl-middleware [nrebl.middleware/wrap-nrebl]}
           :dependencies [[rickmoynihan/nrebl.middleware "0.2.0"] ;; set this to the latest nrebl version
                          [org.clojure/core.async "0.4.490"]]
          :resource-paths ["/home/alendit/projects/clojure/rebl/REBL-0.9.172.jar"] ;; set this to where your REBL jar \
is installed
           :injections [(require '[cognitect.rebl :as rebl])]
           }
 :repl {:plugins [[cider/cider-nrepl "0.21.2-SNAPSHOT"]]
        :dependencies [[nrepl "0.6.0"]]}

 :user [:nrebl :repl]
 }

I use clojure 1.10.1, leiningen 2.9.1, and java 1.8.0_222 on Arch.

When I run lein repl in a project I get

Error loading nrebl.middleware: Syntax error compiling at (nrebl/middleware.clj:1:1).
Exception in thread "main" Syntax error compiling var at (/tmp/form-init2591289400909914130.clj:1:9228).

and a typical compiler failure stack trace.

nrebl should capture stdout and forward it to REBL

Not sure how to do this yet... but it can probably be achieved by intercepting stdout in nrepl, and proxying the streams through REBL's server/prepl.

This approach may also be better than relying on cognitect.rebl/submit to capture forms etc from nrebl, and allow a more native/direct integration with REBL.

Error loading nrebl.middleware

After "updating" to REBL-0.9.218, I receive the following error:

Error loading nrebl.middleware: Syntax error compiling at (nrebl/middleware.clj:1:1).
Syntax error compiling var at (/tmp/form-init4222078885548392034.clj:1:8722).
Unable to resolve var: nrebl.middleware/wrap-nrebl in this context

What am I doing wrong? It worked with the previous release of REBL... My .lein/profiles.clj looks like this:

{:nrebl  {:repl-options {:nrepl-middleware [nrebl.middleware/wrap-nrebl]}
          :dependencies [[rickmoynihan/nrebl.middleware "0.2.0"] ;; set this to the latest nrebl version
                         [org.clojure/core.async "0.4.500"]]
          :resource-paths ["/home/user/clojure/REBL-0.9.218/REBL-0.9.218.jar"] ;; set this to where your REBL jar is installed
          :injections [(require '[cognitect.rebl :as rebl])]
          }
 :user [:nrebl]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.