cursive-ide / cursive

Cursive: The IDE for beautiful Clojure code
588 stars 7 forks source link

"Cannot find surrounding form" on last form in file #750

Open deaddowney opened 9 years ago

deaddowney commented 9 years ago

When I try to evaluate the last form in a file by executing "Run form before Cursor in REPL", I often but not always get "Cannot find surrounding form", even though the file is syntactically correct and I can evaluate the whole file in the REPL.

Below is an example (sorry, I don't have time to come up with a more succinct example right now). If I try to evaluate the last form (put the cursor after the "nil)", I get Cannot find surrounding form

(ns clara.examples
  (require [clara.examples.shopping :as shopping]
           [clara.examples.validation :as validation]
           [clara.examples.sensors :as sensors]
           [clara.examples.durability :as durability]
           [clara.examples.java.shopping :as jshopping]
           [clara.rules :as r]))

(defn -main []
  (println "Shopping examples:")
  (shopping/run-examples)
  (println)
  (println "JavaBean Shopping examples from Clojure:")
  (jshopping/run-examples)
  (println)
  (println "JavaBean Shopping examples from Java:")
  (clara.examples.java.ExampleMain/main (into-array String []))
  (println)
  (println "Validation examples:")
  (validation/run-examples)
  (println)
  (println "Sensor examples:")
  (sensors/run-examples)
  (println "Durability examples:")
  (durability/run-examples))

(defn run-examples
  "Function to run the above example."
  []
  (println "VIP shopping example:")
  ;; prints "10 % :vip discount"
  (-> (r/mk-session 'clara.examples.shopping) ; Load the rules.
      (r/insert (shopping/->Customer :vip)
              (shopping/->Order 2013 :march 20)
              (shopping/->Purchase 20 :gizmo)
              (shopping/->Purchase 120 :widget)) ; Insert some facts.
      (r/fire-rules)
      (shopping/print-discounts!))

  (println "Summer special and widget promotion example:")
  ;; prints: "20 % :summer-special discount"
  ;;         "Free :lunch for promotion :free-lunch-for-gizmo"
  ;;         "Free :widget for promotion :free-widget-month"
  (-> (r/mk-session 'clara.examples.shopping) ; Load the rules.
      (r/insert (shopping/->Customer :vip)
              (shopping/->Order 2013 :august 20)
              (shopping/->Purchase 20 :gizmo)
              (shopping/->Purchase 120 :widget)
              (shopping/->Purchase 90 :widget)) ; Insert some facts.
      (r/fire-rules)
      (shopping/print-discounts!)
      (shopping/print-promotions!))

  nil)
breeze4 commented 9 years ago

I encountered this same issue with fresh install of IntelliJ 14.0.3 Community Edition running only the Cursive plugin.

I discovered that adding a comment to the end of the file works. Not a horrible workaround, but not ideal!

pbaille commented 9 years ago

same here