eerohele / Tutkain

A Sublime Text package for interactive Clojure development
https://tutkain.flowthing.me
Other
68 stars 8 forks source link

Tutkain forgets import aliases after switching windows #50

Closed hgranthorner closed 3 years ago

hgranthorner commented 3 years ago

I'm using the clj-cli tutorial as an example (https://clojure.org/guides/deps_and_cli) - here's the code.

(ns hello
  (:require [java-time :as t]))

(defn time-str
  "Returns a string representation of a datetime in the local time zone."
  [instant]
  (t/format
    (t/with-zone (t/formatter "hh:mm a") (t/zone-id))
    instant))

(defn run [opts]
  (println "Hello world, the time is" (time-str (t/instant))))

(comment
  (time-str (t/instant))
  )

If I evaluate the ns expression, then the defn time-str, then the expressions in the comment, everything works as expected. However, if I switch windows (for example, to this browser) and then back, Tutkain seems to forget the (:require [java-time :as t]) and I get

Syntax error compiling at (src/hello.clj:15:13).
No such namespace: t

Is this expected behavior? Is there some way for Tutkain to remember these bindings? I just started using Tutkain, so this may be a ID10T error as well.

pedrorgirardi commented 3 years ago

Hi @hgranthorner,

I could not reproduce the issue. Sorry for the basic question, but are you running the latest Tutkain version with a socket REPL?

https://clojure.org/guides/deps_and_cli#socket_repl

eerohele commented 3 years ago

Thanks for the report!

I can't reproduce the issue on macOS with the latest version of Tutkain that's available in Package Control, either. It's definitely not an ID10T error, though. Which OS are you using?

By default, Tutkain picks up the namespace from the ns form in your current view and switches to it when you activate that view. There must be a bug in that feature that's causing this issue.

You can disable automatic namespace switching by setting Tutkain's auto_switch_namespace setting (via Preferences » Package Settings » Tutkain » Settings on macOS) to false. You might need to restart ST for the change to take effect. After that, Tutkain won't automatically switch namespaces for you anymore.

If you'd like to help us figure out what's going wrong, you could set the debug setting to true, restart ST, and try reproducing the issue. Then, after you activate the view with (ns hello) and open the ST console (View » Show Console), it should have a pair of lines like this:

[Tutkain.src] [tutkain.clojure.client_1] 2021-06-01 09:29:46.827 DEBUG {'event': 'client/send', 'item': "(do (or (some->> 'hello find-ns ns-name in-ns) (ns hello)) (set! *3 *2) (set! *2 *1))"}
[Tutkain.src] [tutkain.clojure.client_0] 2021-06-01 09:29:46.834 DEBUG {'event': 'client/recv', 'item': {:tag: :ret, :val: '"09:27 AM"\n', :ns: 'hello', :ms: 5, :form: "(do (or (some->> 'hello find-ns ns-name in-ns) (ns hello)) (set! *3 *2) (set! *2 *1))"}}

If the log entries look different, maybe copy-paste them here so that we can take a look.

hgranthorner commented 3 years ago

This was absolutely an ID10T error. No idea what i was doing, but it's working now.

eerohele commented 3 years ago

Glad to hear it's working. Not an ID10T error, though. :) Please don't hesitate to reopen this issue if you come across the same problem again.

I noticed one issue that might or might not be related recently. Given something like this:

(ns foo.bar)

(defmacro m
  []
  `(ns baz.quux))

The current version of Tutkain picks up the namespace from the last ns form in the current view. In the example above, that is the ns form in the macro. That can lead to some confusing situations.

Starting from the next version, Tutkain picks up the first ns form in the current view. Still not a perfect solution, but hopefully an improvement.