text: // Generated by ReScript, PLEASE EDIT WITH CARE
  'use strict';
  
  var Curry = require("rescript/lib/js/curry.js");
  var Vscode = require("vscode");
  var $$Promise = require("reason-promise/lib/js/src/js/promise.bs.js");
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
  var Chan$AgdaModeVscode = require("../Util/Chan.bs.js");
  var Item$AgdaModeVscode = require("../View/Component/Item.bs.js");
  var Util$AgdaModeVscode = require("../Util/Util.bs.js");
  var State$AgdaModeVscode = require("../State.bs.js");
  var Editor$AgdaModeVscode = require("../Editor.bs.js");
  var Parser$AgdaModeVscode = require("../Parser/Parser.bs.js");
  var Tokens$AgdaModeVscode = require("../Tokens.bs.js");
  var RichText$AgdaModeVscode = require("../View/Component/RichText.bs.js");
  var State__Goal$AgdaModeVscode = require("./State__Goal.bs.js");
  var State__View$AgdaModeVscode = require("./State__View.bs.js");
  var Highlighting$AgdaModeVscode = require("../Highlighting.bs.js");
  var Emacs__Parser2$AgdaModeVscode = require("../View/Panel/Emacs/Emacs__Parser2.bs.js");
  
  function removeNewlines(string) {
    return Belt_Array.joinWith(string.split("\\n"), "\n", (function (x) {
                  return x;
                }));
  }
  
  function handle(state, x) {
    switch (x.TAG | 0) {
      case /* Generic */0 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: x._0,
                      [Symbol.for("name")]: "Plain"
                    }, x._1);
      case /* CompilationOk */1 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 1,
                      _0: "Compilation result",
                      [Symbol.for("name")]: "Success"
                    }, [Item$AgdaModeVscode.plainText(x._0)]);
      case /* CompilationOkLSP */2 :
          var message = [Item$AgdaModeVscode.plainText("The module was successfully compiled.")];
          var errors = Belt_Array.map(x._1, (function (raw) {
                  return Item$AgdaModeVscode.error(RichText$AgdaModeVscode.string(raw), raw);
                }));
          var warnings = Belt_Array.map(x._0, (function (raw) {
                  return Item$AgdaModeVscode.warning(RichText$AgdaModeVscode.string(raw), raw);
                }));
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 1,
                      _0: "Compilation result",
                      [Symbol.for("name")]: "Success"
                    }, Belt_Array.concatMany([
                          message,
                          errors,
                          warnings
                        ]));
      case /* Constraints */3 :
          var body = x._0;
          if (body === undefined) {
            return State__View$AgdaModeVscode.Panel.display(state, {
                        TAG: 0,
                        _0: "No Constraints",
                        [Symbol.for("name")]: "Plain"
                      }, []);
          }
          var items = Emacs__Parser2$AgdaModeVscode.parseOutputs(body);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Constraints",
                      [Symbol.for("name")]: "Plain"
                    }, items);
      case /* AllGoalsWarnings */4 :
          var body$1 = x._1;
          var header = x._0;
          if (body$1 === "nil") {
            return State__View$AgdaModeVscode.Panel.display(state, {
                        TAG: 1,
                        _0: header,
                        [Symbol.for("name")]: "Success"
                      }, []);
          }
          var items$1 = Emacs__Parser2$AgdaModeVscode.parseAllGoalsWarnings(header, body$1);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: header,
                      [Symbol.for("name")]: "Plain"
                    }, items$1);
      case /* AllGoalsWarningsLSP */5 :
          var errors$1 = Belt_Array.map(x._4, (function (raw) {
                  return Item$AgdaModeVscode.error(RichText$AgdaModeVscode.string(raw), raw);
                }));
          var warnings$1 = Belt_Array.map(x._3, (function (raw) {
                  return Item$AgdaModeVscode.warning(RichText$AgdaModeVscode.string(raw), raw);
                }));
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: x._0,
                      [Symbol.for("name")]: "Plain"
                    }, Belt_Array.concatMany([
                          x._1,
                          x._2,
                          errors$1,
                          warnings$1
                        ]));
      case /* Time */6 :
          var items$2 = Emacs__Parser2$AgdaModeVscode.parseTextWithLocation(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Time",
                      [Symbol.for("name")]: "Plain"
                    }, items$2);
      case /* Error */7 :
          var items$3 = Emacs__Parser2$AgdaModeVscode.parseError(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 3,
                      _0: "Error",
                      [Symbol.for("name")]: "Error"
                    }, items$3);
      case /* Intro */8 :
          var items$4 = Emacs__Parser2$AgdaModeVscode.parseTextWithLocation(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Intro",
                      [Symbol.for("name")]: "Plain"
                    }, items$4);
      case /* Auto */9 :
          var items$5 = Emacs__Parser2$AgdaModeVscode.parseTextWithLocation(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Auto",
                      [Symbol.for("name")]: "Plain"
                    }, items$5);
      case /* ModuleContents */10 :
          var items$6 = Emacs__Parser2$AgdaModeVscode.parseTextWithLocation(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Module Contents",
                      [Symbol.for("name")]: "Plain"
                    }, items$6);
      case /* SearchAbout */11 :
          var items$7 = Emacs__Parser2$AgdaModeVscode.parseSearchAbout(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Search About",
                      [Symbol.for("name")]: "Plain"
                    }, items$7);
      case /* WhyInScope */12 :
          var items$8 = Emacs__Parser2$AgdaModeVscode.parseTextWithLocation(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Scope info",
                      [Symbol.for("name")]: "Plain"
                    }, items$8);
      case /* NormalForm */13 :
          var items$9 = Emacs__Parser2$AgdaModeVscode.parseTextWithLocation(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Normal form",
                      [Symbol.for("name")]: "Plain"
                    }, items$9);
      case /* GoalType */14 :
          var items$10 = Emacs__Parser2$AgdaModeVscode.parseGoalType(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Goal and Context",
                      [Symbol.for("name")]: "Plain"
                    }, items$10);
      case /* CurrentGoal */15 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Current Goal",
                      [Symbol.for("name")]: "Plain"
                    }, [Item$AgdaModeVscode.plainText(x._0)]);
      case /* CurrentGoalLSP */16 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Current Goal",
                      [Symbol.for("name")]: "Plain"
                    }, [x._0]);
      case /* InferredType */17 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Inferred type",
                      [Symbol.for("name")]: "Plain"
                    }, [Item$AgdaModeVscode.plainText(x._0)]);
      case /* InferredTypeLSP */18 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Inferred type",
                      [Symbol.for("name")]: "Plain"
                    }, [x._0]);
      case /* Context */19 :
          var items$11 = Emacs__Parser2$AgdaModeVscode.parseOutputs(x._0);
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Context",
                      [Symbol.for("name")]: "Plain"
                    }, items$11);
      case /* HelperFunction */20 :
          var payload = x._0;
          return $$Promise.flatMap(Vscode.env.clipboard.writeText(payload), (function (param) {
                        return State__View$AgdaModeVscode.Panel.display(state, {
                                    TAG: 0,
                                    _0: "Helper function (copied to clipboard)",
                                    [Symbol.for("name")]: "Plain"
                                  }, [Item$AgdaModeVscode.plainText(payload)]);
                      }));
      case /* Version */21 :
          return State__View$AgdaModeVscode.Panel.display(state, {
                      TAG: 0,
                      _0: "Version",
                      [Symbol.for("name")]: "Plain"
                    }, [Item$AgdaModeVscode.plainText(x._0)]);
      
    }
  }
  
  var DisplayInfo = {
    handle: handle
  };
  
  function handle$1(state, dispatchCommand, response) {
    var handleResponse;
    if (typeof response === "number") {
      switch (response) {
        case /* ClearHighlighting */1 :
            Tokens$AgdaModeVscode.clear(state.tokens);
            Highlighting$AgdaModeVscode.clear(state.highlighting);
            handleResponse = $$Promise.resolved({
                  TAG: 0,
                  _0: undefined,
                  [Symbol.for("name")]: "Ok"
                });
            break;
        case /* CompleteHighlightingAndMakePromptReappear */4 :
            handleResponse = $$Promise.flatMap(Tokens$AgdaModeVscode.readTempFiles(state.tokens, state.editor), (function (param) {
                    return $$Promise.map(Highlighting$AgdaModeVscode.apply(state.highlighting, state.tokens, state.editor), (function (param) {
                                  return {
                                          TAG: 0,
                                          _0: undefined,
                                          [Symbol.for("name")]: "Ok"
                                        };
                                }));
                  }));
            break;
        default:
          handleResponse = $$Promise.resolved({
                TAG: 0,
                _0: undefined,
                [Symbol.for("name")]: "Ok"
              });
      }
    } else {
      switch (response.TAG | 0) {
        case /* HighlightingInfoDirect */0 :
            Tokens$AgdaModeVscode.insert(state.tokens, state.editor, response._1);
            handleResponse = $$Promise.resolved({
                  TAG: 0,
                  _0: undefined,
                  [Symbol.for("name")]: "Ok"
                });
            break;
        case /* HighlightingInfoIndirect */1 :
            Tokens$AgdaModeVscode.addEmacsFilePath(state.tokens, response._0);
            handleResponse = $$Promise.resolved({
                  TAG: 0,
                  _0: undefined,
                  [Symbol.for("name")]: "Ok"
                });
            break;
        case /* HighlightingInfoIndirectJSON */2 :
            Tokens$AgdaModeVscode.addJSONFilePath(state.tokens, response._0);
            handleResponse = $$Promise.resolved({
                  TAG: 0,
                  _0: undefined,
                  [Symbol.for("name")]: "Ok"
                });
            break;
        case /* Status */3 :
            handleResponse = $$Promise.resolved({
                  TAG: 0,
                  _0: undefined,
                  [Symbol.for("name")]: "Ok"
                });
            break;
        case /* JumpToError */4 :
            var path = Parser$AgdaModeVscode.filepath(state.document.fileName);
            if (path === response._0) {
              var point = state.document.positionAt(response._1 - 1 | 0);
              Editor$AgdaModeVscode.Cursor.set(state.editor, point);
            }
            handleResponse = $$Promise.resolved({
                  TAG: 0,
                  _0: undefined,
                  [Symbol.for("name")]: "Ok"
                });
            break;
        case /* InteractionPoints */5 :
            handleResponse = $$Promise.map(State__Goal$AgdaModeVscode.instantiate(state, response._0), (function (param) {
                    return {
                            TAG: 0,
                            _0: undefined,
                            [Symbol.for("name")]: "Ok"
                          };
                  }));
            break;
        case /* GiveAction */6 :
            var give = response._1;
            var index = response._0;
            var found = Belt_Array.keep(state.goals, (function (goal) {
                    return goal.index === index;
                  }));
            var goal = Belt_Array.get(found, 0);
            if (goal !== undefined) {
              if (typeof give === "number") {
                handleResponse = give !== 0 ? $$Promise.map(State__Goal$AgdaModeVscode.removeBoundaryAndDestroy(state, goal), (function (param) {
                          return {
                                  TAG: 0,
                                  _0: undefined,
                                  [Symbol.for("name")]: "Ok"
                                };
                        })) : $$Promise.map($$Promise.flatMap(State__Goal$AgdaModeVscode.modify(state, goal, (function (content) {
                                  return "(" + (content + ")");
                                })), (function (param) {
                              return State__Goal$AgdaModeVscode.removeBoundaryAndDestroy(state, goal);
                            })), (function (param) {
                          return {
                                  TAG: 0,
                                  _0: undefined,
                                  [Symbol.for("name")]: "Ok"
                                };
                        }));
              } else {
                var content = give._0;
                handleResponse = $$Promise.map($$Promise.flatMap(State__Goal$AgdaModeVscode.modify(state, goal, (function (param) {
                                return content.replace(/\\n/g, "\n");
                              })), (function (param) {
                            return State__Goal$AgdaModeVscode.removeBoundaryAndDestroy(state, goal);
                          })), (function (param) {
                        return {
                                TAG: 0,
                                _0: undefined,
                                [Symbol.for("name")]: "Ok"
                              };
                      }));
              }
            } else {
              handleResponse = $$Promise.map(State__View$AgdaModeVscode.Panel.display(state, {
                        TAG: 3,
                        _0: "Error: Give failed",
                        [Symbol.for("name")]: "Error"
                      }, [Item$AgdaModeVscode.plainText("Cannot find goal #" + String(index))]), (function (param) {
                      return {
                              TAG: 0,
                              _0: undefined,
                              [Symbol.for("name")]: "Ok"
                            };
                    }));
            }
            break;
        case /* MakeCase */7 :
            var lines = response._1;
            var match = State__Goal$AgdaModeVscode.pointed(state);
            if (match !== undefined) {
              var goal$1 = match[0];
              handleResponse = $$Promise.flatMap(response._0 ? State__Goal$AgdaModeVscode.replaceWithLambda(state, goal$1, lines) : State__Goal$AgdaModeVscode.replaceWithLines(state, goal$1, lines), (function (param) {
                      return Curry._1(dispatchCommand, /* Load */0);
                    }));
            } else {
              handleResponse = $$Promise.map(State__View$AgdaModeVscode.Panel.displayOutOfGoalError(state), (function (param) {
                      return {
                              TAG: 0,
                              _0: undefined,
                              [Symbol.for("name")]: "Ok"
                            };
                    }));
            }
            break;
        case /* SolveAll */8 :
            var solutions = response._0;
            var solveOne = function (param) {
              var solution = param[1];
              var index = param[0];
              var goals = Belt_Array.keep(state.goals, (function (goal) {
                      return goal.index === index;
                    }));
              var goal = Belt_Array.get(goals, 0);
              if (goal !== undefined) {
                return $$Promise.flatMap(State__Goal$AgdaModeVscode.modify(state, goal, (function (param) {
                                  return solution;
                                })), (function (param) {
                              var param$1 = {
                                TAG: 3,
                                _0: goal,
                                [Symbol.for("name")]: "Give"
                              };
                              return State$AgdaModeVscode.sendRequest(state, (function (param) {
                                            return handle$1(state, dispatchCommand, param);
                                          }), param$1);
                            }));
              } else {
                return $$Promise.resolved({
                            TAG: 0,
                            _0: undefined,
                            [Symbol.for("name")]: "Ok"
                          });
              }
            };
            handleResponse = $$Promise.map($$Promise.flatMap(Util$AgdaModeVscode.oneByOne(Belt_Array.map(solutions, solveOne)), (function (param) {
                        var size = solutions.length;
                        if (size === 0) {
                          return State__View$AgdaModeVscode.Panel.display(state, {
                                      TAG: 3,
                                      _0: "No solutions found",
                                      [Symbol.for("name")]: "Error"
                                    }, []);
                        } else {
                          return State__View$AgdaModeVscode.Panel.display(state, {
                                      TAG: 1,
                                      _0: String(size) + " goals solved",
                                      [Symbol.for("name")]: "Success"
                                    }, []);
                        }
                      })), (function (param) {
                    return {
                            TAG: 0,
                            _0: undefined,
                            [Symbol.for("name")]: "Ok"
                          };
                  }));
            break;
        case /* DisplayInfo */9 :
            handleResponse = $$Promise.map(handle(state, response._0), (function (param) {
                    return {
                            TAG: 0,
                            _0: undefined,
                            [Symbol.for("name")]: "Ok"
                          };
                  }));
            break;
        case /* RunningInfo */10 :
            var verbosity = response._0;
            if (verbosity !== 1) {
              var message = removeNewlines(response._1);
              state.runningInfoLog.push([
                    verbosity,
                    message
                  ]);
              handleResponse = $$Promise.map(State__View$AgdaModeVscode.DebugBuffer.displayInAppendMode([[
                          verbosity,
                          message
                        ]]), (function (param) {
                      return {
                              TAG: 0,
                              _0: undefined,
                              [Symbol.for("name")]: "Ok"
                            };
                    }));
            } else {
              var message$1 = removeNewlines(response._1);
              state.runningInfoLog.push([
                    1,
                    message$1
                  ]);
              handleResponse = $$Promise.map($$Promise.flatMap(State__View$AgdaModeVscode.Panel.displayInAppendMode(state, {
                            TAG: 0,
                            _0: "Type-checking",
                            [Symbol.for("name")]: "Plain"
                          }, [Item$AgdaModeVscode.plainText(message$1)]), (function (param) {
                          return State__View$AgdaModeVscode.DebugBuffer.displayInAppendMode([[
                                        1,
                                        message$1
                                      ]]);
                        })), (function (param) {
                      return {
                              TAG: 0,
                              _0: undefined,
                              [Symbol.for("name")]: "Ok"
                            };
                    }));
            }
            break;
        
      }
    }
    return $$Promise.tapOk(handleResponse, (function (param) {
                  return Chan$AgdaModeVscode.emit(state.channels.responseHandled, response);
                }));
  }
  
  exports.removeNewlines = removeNewlines;
  exports.DisplayInfo = DisplayInfo;
  exports.handle = handle$1;
  /* vscode Not a pure module */
  