 (ns figwheel-sidecar.cljs-utils.exception-parsing
   (:require
+   [cljs.analyzer :as ana]
    [clojure.string :as string]
    [clojure.java.io :as io]
    [clojure.stacktrace :as stack]

               [[:error-in-code line (nth lines (dec line))]]
               [[:error-message nil
                 (breaker-line (nth lines (dec line))
                               message
                               (if (= line 1)
                                 (+ (repl-prompt-indent
                                     environment

    (map #(update-in % [1]
                     (partial left-pad-string max-line-number-length)) inline-error)))

(defn min-lead-whitespace [lines]
  (reduce min (map (fn [[_ _ line]] (count (take-while #(re-matches #"\s" (str %)) line))) lines)))

(defn truncate-leading-space [lines]
  (let [subtract-space (min-lead-whitespace lines)]
    (mapv (fn [[a b line]]
            [a b (apply str (drop subtract-space line))])
          lines)))

(defn format-error-inline [context-code-lines]
  (let [lines (pad-line-numbers context-code-lines)
        lines (truncate-leading-space lines)]
    (string/join "\n" (map format-error-line lines))))

;; needs to know the length of the current namespace
