Fork me on GitHub
#cider
<
2016-12-31
>
dpsutton00:12:41

i'm braising ribs tonight. but i can look at it tomorrow. I'll look at what's going on and see what's up

dpsutton00:12:54

i don't know of a good way to introspect into the out middleware to see why it thinks 7 is hte id

dpsutton00:12:12

but i think cider can put "previous" input before the current stuff, which seems to be what's happening here

dpsutton00:12:35

if i were you you could open an issue and PR in cider-nrepl and hopefully malabarba and some others with experience can chime in

bhagany00:12:34

there are already two issues for it, though. and issuing a PR without it being ready to go (there’s a checklist) would be against the guidelines. I’m mostly hoping that someone sees it here, or shows interest in the issues I commented on. But, it’s also the holidays, so people are busy. No worries though, I’m setting this as a challenge to myself.

bhagany00:12:30

I fear what may be happening here is that the nrepl server itself isn’t correctly id-ing these things

dpsutton00:12:30

that's one thing i don't like about the PR open source model. I like collaboration over code rather than pull requests in from the dark. I wish there was a good way to collaborate and talk about code for a single feature, rather than several different people just tossing up features

bhagany00:12:10

I agree with you there.

bhagany00:12:29

though, from a maintainer’s point of view, I can see why they don’t want a bunch of half-baked code queued up for them to fix

bhagany00:12:06

anyway, if you come up with something, feel free to submit a work-in-progress PR to my branch 🙂

dpsutton00:12:30

sounds good

dpsutton00:12:44

i'm enjoying this two person talk back and forth

bhagany01:12:03

okay, so when cider connects to nrepl, with my configuration, it immediately issues seven requests, with id’s 1-7

bhagany01:12:26

#7 is the subscription to *out*, which I think can’t be a coincidence

bhagany01:12:40

okay, it’s not configuration dependent - “out-subscribe” is always the 7th thing done on connect https://github.com/clojure-emacs/cider/blob/a68fd4a22bbd75f5dcdc993eddb289ae5d8e096e/cider.el#L779

bhagany16:12:58

HAHAHAHAHAHAHAHA alright this is pretty good.

bhagany16:12:04

I just made it work

bhagany16:12:28

by switching the order of alter-var-root and setOut/`setErr`. that’s it.

bhagany16:12:26

uff, I take it back

dpsutton17:12:58

I've got it cloned and installed now

dpsutton17:12:32

(defn subscribe-session
      "Add msg to `tracked-sessions-map`."
      [{:keys [session] :as msg}]
      (when-let [session (:id (meta session))]
        (swap! tracked-sessions-map assoc session
               (select-key msg [:transport :session :id]))
        {:out-subscribe session}))

dpsutton17:12:50

@bhagany this looks suspcious

dpsutton17:12:58

why does it maintain the id of tracked sessions

dpsutton17:12:10

it should remember the session and transport

dpsutton17:12:14

and then use the current id

bhagany17:12:24

I confess I don't really understand that part

bhagany17:12:34

I have a thing that I think is working, but isn't the cleanest. But my cleanup attempt doesn't work. When I'm back on a wifi connection I'll push, if you wouldn't mind taking a look?

dpsutton17:12:39

so that's just stuffing in a map which connections are alive

dpsutton17:12:50

i'm not sure why it's putting the id in there though

dpsutton18:12:03

ok. so i did a little playing around and breaking things. It looks like its putting the id of 7 in the map of current connections

dpsutton18:12:07

and it uses this response handler

dpsutton18:12:30

so when it sends back a response with id 7, there's something there waiting for it

dpsutton18:12:53

so i'm storing the "msg" which i think are really just importatn for transport and session

dpsutton18:12:03

and making the with-out-binding look up the id of the response its working on

dpsutton18:12:35

(--> 
  ns  "user"
  op  "eval"
  session  "fce73b9c-6402-4f8b-b599-ce4797672838"
  code  "(.println *out* \"Hi\")
"
  file  "*cider-repl fizzbuzz*"
  line  43
  column  7
  id  "23"
)
(<-- 
  id  "23"
  out  "Hi
"
  session  "fce73b9c-6402-4f8b-b599-ce4797672838"
)

dpsutton18:12:49

so how does writing to \out know the id to respond to?

dpsutton18:12:26

but this doesn't

dpsutton18:12:29

(--> 
  ns  "user"
  op  "eval"
  session  "fce73b9c-6402-4f8b-b599-ce4797672838"
  code  "(.println (java.lang.System/out) \"Hi\")
"
  file  "*cider-repl fizzbuzz*"
  line  46
  column  7
  id  "42"
)
(<-- 
  id  "7"
  out  "Hi"
  session  "fce73b9c-6402-4f8b-b599-ce4797672838"
)

bhagany18:12:50

I think nrepl itself handles *out* , but ignores System/out

bhagany18:12:21

That was my impression from reading nrepl's code last night anyway

dpsutton18:12:57

i put some code in there and it wasn't hit when printing to *out*

dpsutton18:12:19

its weird that our middleware has to put which id its handling

dpsutton18:12:33

i thought the point of middleware was that it bubbled down and then bubbled back up

dpsutton18:12:57

would be nice if when we got a request and it went through all of the layers, as it came back out it was set as a response to request id

dpsutton18:12:12

but i think the problem is that we may not be handling things at request time

dpsutton18:12:17

its almost a side effect

dpsutton18:12:36

our forking printer is bound at request time, id 7, and its set as system out

dpsutton18:12:50

i think we need to get the id we are handling

dpsutton18:12:19

something like (nrepl-current-id )

dpsutton18:12:23

something along those lines

bhagany18:12:34

My new solution redirects System/out to *out* after it's rebound to avoid nrepl not handling it

dpsutton18:12:10

well my thinking is that this out rebinding is fundamentally broken

dpsutton18:12:21

that it can only respond as id 7 ever

dpsutton18:12:42

and it would be totally hacky if cider knew to reorder things unless it was for the registering out step

bhagany19:12:33

I don't think I understand what you mean

dpsutton19:12:43

so cider reorders some stuff coming back if id coming back < id working on now

dpsutton19:12:41

and it would be gross to change that less than sign to a function that returns (if (= id cider-setup-out-id)....)

bhagany19:12:14

Ah, yes, I agree. That was the first thing I thought of, and, ew.

bhagany19:12:39

okay, I’m back home and I just updated my branch

bhagany19:12:37

it works as it is now, but I’d like to abstract out-stream and err-stream into a single function

bhagany19:12:08

print-stream is my attempt at that, but it doesn’t work, and I don’t understand why.

bhagany19:12:56

to break it, you can comment (out-stream) and (err-stream) on these two lines, and uncomment the calls to print-stream. https://github.com/bhagany/cider-nrepl/blob/repl-err/src/cider/nrepl/middleware/out.clj#L132-L133

richiardiandrea19:12:04

Guys, just thanks! very good job!

bhagany19:12:49

gosh, I’m not sure I’ve actually done anything yet 🙂

richiardiandrea19:12:19

you've done the most tiring part of any OSS contribution 🙂

richiardiandrea19:12:39

it would be awesome to just dump this conversations in a wiki page 😄

dpsutton19:12:11

oh for sure

bhagany19:12:48

I’ll take your word for it. From my point of view, it’s been quite refreshing to work things out with others like this

featheredtoast19:12:24

can cider load a lein project into an existing repl?

bhagany19:12:55

@dpsutton okay, I got it. I’m still not sure why it needed this, but I added a bit of indirection and now print-stream works

dpsutton19:12:19

with the correct id's in the response?

dpsutton19:12:40

got it on github? can i pull and check it out?

bhagany19:12:48

yep, it’s there, go ahead and pull

bhagany19:12:54

I’ll give people a chance to check it out - I’m off to see Rogue One with my son 🙂

bhagany20:12:05

if everything looks okay, I’ll submit a PR when I get back

qqq23:12:52

I have defined my own pattern matching macro called mm. Is there a way to tell emacs to indent "mm" in the same awy as "case"? The answer is yes, unfortunately, I don't know what's the right layer to provide this information.

qqq23:12:09

@richiardiandrea : that solved it; thanks!