function mountPanel(editors, mountTo, self) { var createTab = function (param) { return Tab$AgdaMode.make(editors[/* source */1], (function (param) { return "[Agda Mode] " + editors[/* source */1].getTitle(); }), "panel", (function (param, param$1, previousItem) { return Rebase.$$Option[/* forEach */8]((function (pane) { pane.activate(); pane.activateItem(previousItem); return /* () */0; }), atom.workspace.paneForItem(previousItem)); }), undefined, (function (param) { return Curry._1(self[/* send */0], /* MountTo */Block.variant("MountTo", 3, [/* ToBottom */0])); }), undefined, /* () */0); }; var match = self[/* state */1][/* mountAt */0]; if (match.tag) { if (!mountTo) { Curry._1(match[0][/* kill */1], /* () */0); Curry._1(self[/* send */0], /* UpdateMountAt */Block.variant("UpdateMountAt", 2, [/* Bottom */Block.variant("Bottom", 0, [createBottomPanel(/* () */0)])])); } } else if (mountTo) { Curry._1(self[/* send */0], /* UpdateMountAt */Block.variant("UpdateMountAt", 2, [/* Pane */Block.variant("Pane", 1, [createTab(/* () */0)])])); } return undefined; }
function mountSettings(editors, handles, open_, self) { var match = self[/* state */1][/* settingsView */2]; if (match !== undefined) { if (open_) { Event$AgdaMode.emitOk(true, handles[/* onSettingsView */12]); } else { Curry._1(match[/* kill */1], /* () */0); Curry._1(self[/* send */0], /* UpdateSettingsView */Block.variant("UpdateSettingsView", 1, [undefined])); Event$AgdaMode.emitOk(false, handles[/* onSettingsView */12]); } return undefined; } else { if (open_) { var tab = Tab$AgdaMode.make(editors[/* source */1], (function (param) { return "[Settings] " + editors[/* source */1].getTitle(); }), "settings", (function (param, param$1, param$2) { return Event$AgdaMode.emitOk(true, handles[/* onSettingsView */12]); }), undefined, (function (param) { Curry._1(self[/* send */0], /* ToggleSettingsTab */Block.variant("ToggleSettingsTab", 0, [false])); return Event$AgdaMode.emitOk(false, handles[/* onSettingsView */12]); }), undefined, /* () */0); Curry._1(self[/* send */0], /* UpdateSettingsView */Block.variant("UpdateSettingsView", 1, [tab])); } return undefined; } }
function make$1(param) { return /* record */Block.record([ "counter", "listeners" ], [ Block.record(["contents"], [0]), { } ]); }
})).on("close", (function (code, signal) { disconnect(/* ClosedByProcess */Block.variant("ClosedByProcess", 1, [ code, signal ]), connection); return Curry._1(reject, /* ClosedByProcess */Block.variant("ClosedByProcess", 1, [ code, signal ])); }));
var parseError = function (error) { if (error == null) { return undefined; } else { var message = Rebase.$$Option[/* getOr */16]("", error.message); if ((/No such file or directory/).test(message) || (/command not found/).test(message)) { return /* NotFound */Block.variant("NotFound", 1, [error]); } else { return /* ShellError */Block.variant("ShellError", 2, [error]); } } };
function make(textEditor) { atom.views.getView(textEditor).classList.add("agda"); var editors = Editors$AgdaMode.make(textEditor); var instance = /* record */Block.record([ "isLoaded", "editors", "view", "history", "highlightings", "goals", "connection", "runningInfo", "dispatch", "handleResponse" ], [ false, editors, Root$AgdaMode.initialize(editors), Block.record([ "checkpoints", "needsReloading" ], [ [], false ]), [], [], undefined, RunningInfo$AgdaMode.make(/* () */0), Instance__Handler$AgdaMode.dispatch, Instance__Handler$AgdaMode.handleResponseAndRecoverCursor ]); var destructor0 = Event$AgdaMode.onOk((function (path) { Instance__Connections$AgdaMode.connectWithAgdaPath(instance, path); return /* () */0; }))(instance[/* view */2][/* onInquireConnection */15]); var destructor1 = Event$AgdaMode.onOk((function (ev) { switch (ev.tag | 0) { case 0 : Instance__Handler$AgdaMode.dispatch(/* Jump */Block.variant("Jump", 9, [ev[0]]), instance); return /* () */0; case 1 : case 2 : return /* () */0; } }))(instance[/* view */2][/* onMouseEvent */8]); Async$AgdaMode.finalOk((function (param) { Curry._1(destructor0, /* () */0); return Curry._1(destructor1, /* () */0); }), Curry._1(instance[/* view */2][/* onDestroy */3], /* () */0)); return instance; }
function map(f, self) { var delta = /* record */Block.record(["contents"], [0]); return Rebase.$$Array[/* map */0]((function (token) { var match = Curry._1(f, token); var content = match[/* content */0]; var match$1 = token[/* range */1]; var lengthDiff = Rebase.$$String[/* length */1](content) - Rebase.$$String[/* length */1](token[/* content */0]) | 0; var result_001 = /* range : tuple */[ match$1[0] + delta[0] | 0, (match$1[1] + delta[0] | 0) + lengthDiff | 0 ]; var result_002 = /* type_ */match[/* type_ */2]; var result = /* record */Block.record([ "content", "range", "type_" ], [ content, result_001, result_002 ]); delta[0] = delta[0] + lengthDiff | 0; return result; }), self); }
return Async$AgdaMode.make((function (resolve, reject) { if (Rebase.$$String[/* isEmpty */5](path)) { Curry._1(reject, /* PathMalformed */Block.variant("PathMalformed", 0, ["the path must not be empty"])); } var hangTimeout = setTimeout((function (param) { return Curry._1(reject, /* ProcessHanging */0); }), 1000); Child_process.exec(path, (function (error, stdout, stderr) { clearTimeout(hangTimeout); var match = parseError(error); if (match !== undefined) { Curry._1(reject, match); } var stderr$prime = stderr.toString(); if (!Rebase.$$String[/* isEmpty */5](stderr$prime)) { Curry._1(reject, /* ProcessError */Block.variant("ProcessError", 3, [stderr$prime])); } var match$1 = parseStdout(stdout); if (match$1.tag) { return Curry._1(reject, match$1[0]); } else { return Curry._1(resolve, match$1[0]); } })); return /* () */0; }));
function add(info, self) { var match = self[/* editor */0]; if (match !== undefined) { Caml_option.valFromOption(match).insertText(info); return Async$AgdaMode.resolve(/* () */0); } else if (self[/* isOpeningEditor */1]) { self[/* buffer */2] = /* :: */Block.simpleVariant("::", [ info, self[/* buffer */2] ]); return Async$AgdaMode.resolve(/* () */0); } else { self[/* isOpeningEditor */1] = true; return Async$AgdaMode.thenOk((function (newItem) { self[/* isOpeningEditor */1] = false; self[/* editor */0] = Caml_option.some(newItem); newItem.insertText(Rebase.$$String[/* join */10](self[/* buffer */2])); self[/* buffer */2] = /* [] */0; self[/* subscriptions */3].add(newItem.onDidDestroy((function (param) { return destroy(self); }))); return Async$AgdaMode.resolve(/* () */0); }))(Async$AgdaMode.fromPromise(atom.workspace.open("agda-mode://log", itemOptions))); } }
return Async$AgdaMode.thenError((function (err) { return Async$AgdaMode.thenOk((function (param) { return getConnection(instance, param); }))(Async$AgdaMode.thenOk((function (param) { return getMetadata(instance, param); }))(inquireAgdaPath(/* ConnectionError */Block.variant("ConnectionError", 2, [err]), instance))); }))(Connection$AgdaMode.connect(metadata));
Child_process.exec("which " + path, (function (error, stdout, stderr) { clearTimeout(hangTimeout); if (!(error == null)) { Curry._1(reject, /* NotFound */Block.variant("NotFound", 1, [Rebase.$$Option[/* getOr */16]("", error.message)])); } var stderr$prime = stderr.toString(); if (!Rebase.$$String[/* isEmpty */5](stderr$prime)) { Curry._1(reject, /* NotFound */Block.variant("NotFound", 1, [stderr$prime])); } var stdout$prime = stdout.toString(); if (Rebase.$$String[/* isEmpty */5](stdout$prime)) { return Curry._1(reject, /* NotFound */Block.variant("NotFound", 1, [""])); } else { return Curry._1(resolve, Parser$AgdaMode.filepath(stdout$prime)); } }));
var f = function (token) { if (token[/* type_ */2] === source) { var cursor = /* record */Block.record(["contents"], [token[/* range */1][0]]); return Rebase.$$Array[/* map */0]((function (content) { var match = regex.test(content); var type_ = match ? target : source; var cursorOld = cursor[0]; cursor[0] = cursor[0] + Rebase.$$String[/* length */1](content) | 0; return /* record */Block.record([ "content", "range", "type_" ], [ content, [ cursorOld, cursor[0] ], type_ ]); }), Rebase.$$Array[/* filterMap */23]((function (x) { return x; }), token[/* content */0].split(regex))); } else { return /* array */[token]; } };
function makeHandles(param) { var activatePanel = Event$AgdaMode.make(/* () */0); var display = Event$AgdaMode.make(/* () */0); var inquire = Event$AgdaMode.make(/* () */0); var toggleDocking = Event$AgdaMode.make(/* () */0); var updateIsPending = Event$AgdaMode.make(/* () */0); var updateShouldDisplay = Event$AgdaMode.make(/* () */0); var updateConnection = Event$AgdaMode.make(/* () */0); var inquireConnection = Event$AgdaMode.make(/* () */0); var onInquireConnection = Event$AgdaMode.make(/* () */0); var onInquireQuery = Event$AgdaMode.make(/* () */0); var inquireQuery = Event$AgdaMode.make(/* () */0); var activateSettingsView = Event$AgdaMode.make(/* () */0); var onSettingsView = Event$AgdaMode.make(/* () */0); var navigateSettingsView = Event$AgdaMode.make(/* () */0); var interceptAndInsertKey = Event$AgdaMode.make(/* () */0); var activateInputMethod = Event$AgdaMode.make(/* () */0); var onMouseEvent = Event$AgdaMode.make(/* () */0); var destroy = Event$AgdaMode.make(/* () */0); return /* record */Block.record([ "display", "inquire", "toggleDocking", "activatePanel", "updateIsPending", "updateShouldDisplay", "updateConnection", "inquireConnection", "onInquireConnection", "inquireQuery", "onInquireQuery", "activateSettingsView", "onSettingsView", "navigateSettingsView", "destroy", "activateInputMethod", "interceptAndInsertKey", "onMouseEvent" ], [ display, inquire, toggleDocking, activatePanel, updateIsPending, updateShouldDisplay, updateConnection, inquireConnection, onInquireConnection, inquireQuery, onInquireQuery, activateSettingsView, onSettingsView, navigateSettingsView, destroy, activateInputMethod, interceptAndInsertKey, onMouseEvent ]); }
return Async$AgdaMode.thenError((function (err) { return Async$AgdaMode.thenOk((function (param) { return getMetadata(instance, param); }))(inquireAgdaPath(/* ValidationError */Block.variant("ValidationError", 1, [ pathAndParams, err ]), instance)); }))(Connection$AgdaMode.validateAndMake(pathAndParams));
function make(resolve, id) { return /* record */Block.record([ "resolve", "id" ], [ resolve, id ]); }
function wire(self) { var response = function (res) { var match = Rebase.$$Array[/* get */17](self[/* queue */2], 0); if (match !== undefined) { Event$AgdaMode.emitOk(res, match); if (typeof res === "number") { return Rebase.$$Option[/* forEach */8](Event$AgdaMode.destroy, Caml_option.undefined_to_opt(self[/* queue */2].pop())); } else { return /* () */0; } } else if (typeof res === "number" || !res.tag) { return /* () */0; } else { return Event$AgdaMode.emitOk(res[0], self[/* errorEmitter */3]); } }; var continuation = /* record */Block.record(["contents"], [undefined]); var onData = function (chunk) { var string = chunk.toString(); var endOfResponse = Rebase.$$String[/* endsWith */4]("Agda2> ", string); var trimmed; if (endOfResponse) { trimmed = string.substring(0, Rebase.$$String[/* length */1](string) - 7 | 0); } else { var length = Rebase.$$String[/* length */1](string) - 1 | 0; trimmed = Rebase.$$String[/* sub */9](0, length, string); } Rebase.$$Array[/* forEach */8]((function (line) { var $$continue = Rebase.$$Option[/* getOr */16](Parser$AgdaMode.SExpression[/* incrParse */4], continuation[0]); var match = Curry._1($$continue, line); switch (match.tag | 0) { case 0 : return response(/* Error */Block.variant("Error", 0, [/* SExpression */Block.variant("SExpression", 0, [match[0]])])); case 1 : continuation[0] = match[0]; return /* () */0; case 2 : var match$1 = Response$AgdaMode.parse(match[0]); if (match$1.tag) { response(/* Error */Block.variant("Error", 0, [match$1[0]])); } else { response(/* Data */Block.variant("Data", 1, [match$1[0]])); } continuation[0] = undefined; return /* () */0; } }), Parser$AgdaMode.splitAndTrim(trimmed)); if (endOfResponse) { return response(/* End */0); } else { return 0; } }; self[/* process */1].stdout.on("data", onData); return self; }
function Settings__Placeholder(Props) { var hidden = Props.hidden; var className = Curry._1(Util$AgdaMode.ClassName[/* serialize */2], Util$AgdaMode.ClassName[/* addWhen */1]("hidden", hidden, /* :: */Block.simpleVariant("::", [ "agda-settings-placeholder", /* [] */0 ]))); return React.createElement("section", { className: className }, React.createElement("h1", undefined, React.createElement("span", undefined, "Coming soon"))); }
function map$1(f, g, x) { return /* record */Block.record([ "counter", "listeners" ], [ x[/* counter */0], Js_dict.map((function (l) { return map(f, g, l); }), x[/* listeners */1]) ]); }
function map(f, g, listener) { return /* record */Block.record([ "resolve", "id" ], [ (function (x) { return Curry._1(listener[/* resolve */0], Rebase.Result[/* map2 */1](f, g, x)); }), listener[/* id */1] ]); }
var destructor1 = Event$AgdaMode.onOk((function (ev) { switch (ev.tag | 0) { case 0 : Instance__Handler$AgdaMode.dispatch(/* Jump */Block.variant("Jump", 9, [ev[0]]), instance); return /* () */0; case 1 : case 2 : return /* () */0; } }))(instance[/* view */2][/* onMouseEvent */8]);
var questionMark2GoalBracket = function (token) { return /* record */Block.record([ "content", "range", "type_" ], [ "{! !}", token[/* range */1], 3 ]); };
var display = function (text, style, body) { return Event$AgdaMode.emitOk(/* tuple */[ /* record */Block.record([ "text", "style" ], [ text, style ]), body ], handles[/* display */0]); };
Rebase.$$Array[/* forEach */8]((function (line) { var $$continue = Rebase.$$Option[/* getOr */16](Parser$AgdaMode.SExpression[/* incrParse */4], continuation[0]); var match = Curry._1($$continue, line); switch (match.tag | 0) { case 0 : return response(/* Error */Block.variant("Error", 0, [/* SExpression */Block.variant("SExpression", 0, [match[0]])])); case 1 : continuation[0] = match[0]; return /* () */0; case 2 : var match$1 = Response$AgdaMode.parse(match[0]); if (match$1.tag) { response(/* Error */Block.variant("Error", 0, [match$1[0]])); } else { response(/* Data */Block.variant("Data", 1, [match$1[0]])); } continuation[0] = undefined; return /* () */0; } }), Parser$AgdaMode.splitAndTrim(trimmed));
var parseStdout = function (stdout) { var message = stdout.toString(); var match = message.match((/Agda version (.*)/)); if (match !== null) { var match$1 = Rebase.$$Array[/* get */17](match, 1); if (match$1 !== undefined) { var match$2 = (/--interaction-json/).test(message); return /* Ok */Block.variant("Ok", 0, [/* record */Block.record([ "path", "args", "version", "protocol" ], [ path, args, Semver.coerce(match$1), match$2 ? /* EmacsAndJSON */1 : /* EmacsOnly */0 ])]); } else { return /* Error */Block.variant("Error", 1, [/* IsNotAgda */Block.variant("IsNotAgda", 4, [message])]); } } else { return /* Error */Block.variant("Error", 1, [/* IsNotAgda */Block.variant("IsNotAgda", 4, [message])]); } };
function make(param) { return /* record */Block.record([ "editor", "isOpeningEditor", "buffer", "subscriptions" ], [ undefined, false, 0, new Atom.CompositeDisposable() ]); }
function make(raw) { return /* array */[/* record */Block.record([ "content", "range", "type_" ], [ raw, [ 0, Rebase.$$String[/* length */1](raw) ], 0 ])]; }
return Async$AgdaMode.make((function (resolve, reject) { var os = Os.type(); var exit = 0; switch (os) { case "Darwin" : case "Linux" : exit = 1; break; case "Windows_NT" : return Curry._1(reject, /* NotSupported */Block.variant("NotSupported", 0, ["Windows_NT"])); default: return Curry._1(reject, /* NotSupported */Block.variant("NotSupported", 0, [os])); } if (exit === 1) { var hangTimeout = setTimeout((function (param) { return Curry._1(reject, /* ProcessHanging */0); }), 1000); Child_process.exec("which " + path, (function (error, stdout, stderr) { clearTimeout(hangTimeout); if (!(error == null)) { Curry._1(reject, /* NotFound */Block.variant("NotFound", 1, [Rebase.$$Option[/* getOr */16]("", error.message)])); } var stderr$prime = stderr.toString(); if (!Rebase.$$String[/* isEmpty */5](stderr$prime)) { Curry._1(reject, /* NotFound */Block.variant("NotFound", 1, [stderr$prime])); } var stdout$prime = stdout.toString(); if (Rebase.$$String[/* isEmpty */5](stdout$prime)) { return Curry._1(reject, /* NotFound */Block.variant("NotFound", 1, [""])); } else { return Curry._1(resolve, Parser$AgdaMode.filepath(stdout$prime)); } })); return /* () */0; } }));
function listen(callback, self) { var id = self[/* counter */0][0] + 1 | 0; self[/* counter */0][0] = id; var listener = /* record */Block.record([ "resolve", "id" ], [ callback, id ]); self[/* listeners */1][String(id)] = listener; return (function (param) { return removeListener(id, self); }); }
var inquire = function (text, placeholder, value) { var promise = Event$AgdaMode.once(handles[/* onInquireQuery */10]); Event$AgdaMode.emitOk(/* tuple */[ /* record */Block.record([ "text", "style" ], [ text, 0 ]), placeholder, value ], handles[/* inquire */1]); return promise; };
return Rebase.$$Array[/* map */0]((function (line) { var cursorOld = cursor[0]; cursor[0] = cursor[0] + Rebase.$$String[/* length */1](line) | 0; return /* record */Block.record([ "content", "range", "type_" ], [ raw.substring(cursorOld, cursor[0]), [ cursorOld, cursor[0] ], 1 ]); }), Rebase.$$Array[/* filter */10]((function (x) {