goog.provide('sci.nrepl.server');
if((typeof sci !== 'undefined') && (typeof sci.nrepl !== 'undefined') && (typeof sci.nrepl.server !== 'undefined') && (typeof sci.nrepl.server._BANG_last_ns !== 'undefined')){
} else {
sci.nrepl.server._BANG_last_ns = cljs.core.volatile_BANG_(cljs.core.deref(sci.core.ns));
}
sci.nrepl.server.eval_string = (function sci$nrepl$server$eval_string(s){
var bm__49624__auto__ = cljs.core.PersistentArrayMap.createAsIfByAssoc([sci.core.ns,cljs.core.deref(sci.nrepl.server._BANG_last_ns)]);
if(cljs.core.map_QMARK_(bm__49624__auto__)){
} else {
throw (new Error("Assert failed: (clojure.core/map? bm__49624__auto__)"));
}

sci.impl.vars.push_thread_bindings(bm__49624__auto__);

try{var rdr = sci.core.reader(s);
var res = null;
while(true){
var form = sci.core.parse_next.cljs$core$IFn$_invoke$arity$2(sci.ctx_store.get_ctx(),rdr);
if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword("sci.core","eof","sci.core/eof",-808584945),form)){
cljs.core.vreset_BANG_(sci.nrepl.server._BANG_last_ns,cljs.core.deref(sci.core.ns));

return res;
} else {
var G__50202 = sci.core.eval_form(sci.ctx_store.get_ctx(),form);
res = G__50202;
continue;
}
break;
}
}finally {sci.impl.vars.pop_thread_bindings();
}});
sci.nrepl.server.nrepl_websocket = (function sci$nrepl$server$nrepl_websocket(){
return window.ws_nrepl;
});
sci.nrepl.server.nrepl_reply = (function sci$nrepl$server$nrepl_reply(p__50173,p__50174){
var map__50175 = p__50173;
var map__50175__$1 = cljs.core.__destructure_map(map__50175);
var id = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__50175__$1,new cljs.core.Keyword(null,"id","id",-1388402092));
var session = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__50175__$1,new cljs.core.Keyword(null,"session","session",1008279103));
var send_fn = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__50175__$1,new cljs.core.Keyword(null,"send-fn","send-fn",351002041));
var map__50176 = p__50174;
var map__50176__$1 = cljs.core.__destructure_map(map__50176);
var payload = map__50176__$1;
var ns = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__50176__$1,new cljs.core.Keyword(null,"ns","ns",441598760));
var ns__$1 = (function (){var or__5025__auto__ = ns;
if(cljs.core.truth_(or__5025__auto__)){
return or__5025__auto__;
} else {
return cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.deref(sci.nrepl.server._BANG_last_ns));
}
})();
var reply = cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2(cljs.core.assoc.cljs$core$IFn$_invoke$arity$variadic(payload,new cljs.core.Keyword(null,"id","id",-1388402092),id,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([new cljs.core.Keyword(null,"session","session",1008279103),session,new cljs.core.Keyword(null,"ns","ns",441598760),ns__$1], 0)),new cljs.core.Keyword(null,"ctx","ctx",-493610118));
if(cljs.core.truth_(send_fn)){
return (send_fn.cljs$core$IFn$_invoke$arity$1 ? send_fn.cljs$core$IFn$_invoke$arity$1(reply) : send_fn.call(null,reply));
} else {
return sci.nrepl.server.nrepl_websocket().send(cljs.core.str.cljs$core$IFn$_invoke$arity$1(reply));
}
});
sci.nrepl.server.handle_nrepl_eval = (function sci$nrepl$server$handle_nrepl_eval(p__50186){
var map__50187 = p__50186;
var map__50187__$1 = cljs.core.__destructure_map(map__50187);
var msg = map__50187__$1;
var code = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__50187__$1,new cljs.core.Keyword(null,"code","code",1586293142));
var vec__50189 = (function (){try{return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword("sci.nrepl.server","success","sci.nrepl.server/success",-67357591),sci.nrepl.server.eval_string(code)], null);
}catch (e50192){var e = e50192;
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword("sci.nrepl.server","error","sci.nrepl.server/error",855827645),cljs.core.str.cljs$core$IFn$_invoke$arity$1(e)], null);
}})();
var kind = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__50189,(0),null);
var val = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__50189,(1),null);
var G__50195 = kind;
var G__50195__$1 = (((G__50195 instanceof cljs.core.Keyword))?G__50195.fqn:null);
switch (G__50195__$1) {
case "sci.nrepl.server/success":
sci.nrepl.server.nrepl_reply(msg,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"value","value",305978217),cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([val], 0))], null));

return sci.nrepl.server.nrepl_reply(msg,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"status","status",-1997798413),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, ["done"], null)], null));

break;
case "sci.nrepl.server/error":
sci.nrepl.server.nrepl_reply(msg,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"err","err",-2089457205),cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([val], 0))], null));

return sci.nrepl.server.nrepl_reply(msg,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"ex","ex",-1413771341),cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([val], 0)),new cljs.core.Keyword(null,"status","status",-1997798413),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["error","done"], null)], null));

break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__50195__$1)].join('')));

}
});
sci.nrepl.server.handle_nrepl_info = (function sci$nrepl$server$handle_nrepl_info(msg){
var info = sci.nrepl.info.info(cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(msg,new cljs.core.Keyword(null,"ctx","ctx",-493610118),sci.ctx_store.get_ctx()));
return sci.nrepl.server.nrepl_reply(msg,info);
});
sci.nrepl.server.handle_describe = (function sci$nrepl$server$handle_describe(msg){
return sci.nrepl.server.nrepl_reply(msg,new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"versions","versions",536521978),new cljs.core.PersistentArrayMap(null, 1, ["sci-nrepl",new cljs.core.PersistentArrayMap(null, 3, ["major","0","minor","0","incremental","1"], null)], null),new cljs.core.Keyword(null,"ops","ops",1237330063),cljs.core.zipmap(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.name,cljs.core.concat.cljs$core$IFn$_invoke$arity$variadic(cljs.core.keys(sci.nrepl.server.ops),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"load-file","load-file",-424586670),null,new cljs.core.Keyword(null,"clone","clone",711747572),null], null), null),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, ["close",null], null), null)], 0))),cljs.core.repeat.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY)),new cljs.core.Keyword(null,"status","status",-1997798413),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, ["done"], null)], null));
});
/**
 * Operations supported by the nrepl server.
 */
sci.nrepl.server.ops = new cljs.core.PersistentArrayMap(null, 6, [new cljs.core.Keyword(null,"eval","eval",-1103567905),sci.nrepl.server.handle_nrepl_eval,new cljs.core.Keyword(null,"info","info",-317069002),sci.nrepl.server.handle_nrepl_info,new cljs.core.Keyword(null,"eldoc","eldoc",-1321421900),sci.nrepl.server.handle_nrepl_info,new cljs.core.Keyword(null,"lookup","lookup",1225356838),sci.nrepl.server.handle_nrepl_info,new cljs.core.Keyword(null,"describe","describe",1369790582),sci.nrepl.server.handle_describe,new cljs.core.Keyword(null,"complete","complete",-500388775),(function (msg){
var completions = sci.nrepl.completions.completions(cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(msg,new cljs.core.Keyword(null,"ctx","ctx",-493610118),sci.ctx_store.get_ctx()));
return sci.nrepl.server.nrepl_reply(msg,completions);
})], null);
sci.nrepl.server.handle_nrepl_message = (function sci$nrepl$server$handle_nrepl_message(msg){
var temp__5802__auto__ = (function (){var G__50201 = new cljs.core.Keyword(null,"op","op",-1882987955).cljs$core$IFn$_invoke$arity$1(msg);
return (sci.nrepl.server.ops.cljs$core$IFn$_invoke$arity$1 ? sci.nrepl.server.ops.cljs$core$IFn$_invoke$arity$1(G__50201) : sci.nrepl.server.ops.call(null,G__50201));
})();
if(cljs.core.truth_(temp__5802__auto__)){
var handler = temp__5802__auto__;
return (handler.cljs$core$IFn$_invoke$arity$1 ? handler.cljs$core$IFn$_invoke$arity$1(msg) : handler.call(null,msg));
} else {
return sci.nrepl.server.nrepl_reply(msg,cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([msg,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"status","status",-1997798413),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["error","done"], null),new cljs.core.Keyword(null,"err","err",-2089457205),"unknown-op"], null)], 0)));
}
});

//# sourceMappingURL=sci.nrepl.server.js.map
