Olical / conjure

Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile, Python and more!)
https://conjure.oli.me.uk
The Unlicense
1.78k stars 110 forks source link

Compile error with `ns`: "unknown global in strict mode: ns" #231

Open cshintov opened 3 years ago

cshintov commented 3 years ago

I'm getting compile error when trying to evaluate namespace definition.

(ns examples.core         // This doesn't work!
  (:gen-class))

 (+ 1 2) => 3           // This works 

Throws below error!

; eval (current-form): (ns examples)
; Compile error in /home/shinto/Shinto/Personal/Learn/Development/Clojure/clojure-by-example/app/examples/src/examples/cor
;   unknown global in strict mode: ns
; 
;   (:gen-class))
;                                                                                                                         
; * Try looking to see if there's a typo.
; * Try using the _G table instead, eg. _G.ns if you really want a global.
; * Try moving this code to somewhere that ns is in scope.
; * Try binding ns as a local in the scope of this code.

Running :ConjureCljSessionFresh gives

; Sponsored by @ketansrivastav _                                                                                          
; --------------------------------------------------------------------------------                                        
; localhost:44444 (connected): app/examples/.nrepl-port                                                                   
; --------------------------------------------------------------------------------                                        
; localhost:44444 (disconnected): app/examples/.nrepl-port         

I am trying to connect to the nREPL server running inside a container at port 44444.

$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

The session refresh and telnet logs suggest the session is getting disconnected, I guess! What might be the reason, I can clearly see the nREPL server running in headless mode.

I was trying to use docker to bring up a readymade developer environment for Clojure with NeoVim. It's not ready yet, it can be found here https://github.com/cshintov/clojure-by-example. Might need a little bit of work to make it run on other than my system. I've hard coded uid/gid in Dockerfile, etc.

Olical commented 3 years ago

Hmm this looks like you're trying to evaluate Fennel/Lua within a Clojure buffer. Maybe your filetype is fennel or your Conjure config is telling it to eval Fennel code from .clj files?

thecontinium commented 3 years ago

I have seen a very similar problem in evaluating a Clojure namespace.

cshintov commented 3 years ago

The code is from clojure project created using lein. It might be the second scenario. How do I fix it?

I didn't do any additional configuration. Just ran nrepl server in the container and started evaluating.

One interesting thing I were able to evaulate (+ 1 2) even without running the nrepl server.

Olical commented 3 years ago

(+ 1 2) will work fine since it's evaluating your Clojure code as Fennel and (+ 1 2) works in either language. The error is a clue, it's a Lua error, all of this is Lua related.

; * Try looking to see if there's a typo.
; * Try using the _G table instead, eg. _G.ns if you really want a global.
; * Try moving this code to somewhere that ns is in scope.
; * Try binding ns as a local in the scope of this code.

So you're not evaluating as Clojure and I'm not sure why 🤔 do you have syntax highlighting enabled so Neovim knows what language you're working with?

Can you reproduce the same error with the built in babashka auto REPL or a Clojure CLI nREPL or even one from running lein repl? If it works fine with those then we know it's the REPL but I suspect it's some Neovim configuration, but I'm completely guessing as to what setting could be doing this. I have no idea right now. It could be extra Conjure config, it could be filetype things or even to do with syntax highlighting.

Conjure has no reason to eval clojure as fennel unless it is told to really, do you have any config for Conjure around swapping filetypes or some extra config for fennel / clojure to improve highlighting?

cshintov commented 3 years ago

I have no extra config, I'm new to Clojure and I'm just starting out using it with Neovim. So it's all default config.

I came to know the existence of fennel through this plugin only. And never worked with Lua. So I don't know what's causing neovim/conjure to think a ".clj" file to be Lua/Fennel.

Is there anyway to debug this, anywhere conjure logs or even inspect its the current config?

cshintov commented 3 years ago

I was trying to avoid installing clojure/lein on the host and use the container instead. But now I did install them on the host and it is working without any issues. So it's not Conjure/Neovim, rather my setup that's causing the problem! But the error message was confusing. What do you think?

Do you know a way to work with a containerized dev environment?

Olical commented 3 years ago

I'm kinda stumped on why it would select the wrong language 🤔 Conjure doesn't try to work out the language, it just trusts the "filetype" which is determined by the neovim config. The only debug tooling is let g:conjure#debug = v:true but that won't show you how it decides the language really, might have soooome hints?

If you see it again, I'd like to see what :set filetype displays, that's the only thing I can think to check really.

stuartrexking commented 2 years ago

@cshintov I suspect this is an issue with the file paths in the Docker container being different to your host.

See g:conjure#path_subs