Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to eval or run tests when namespace is camelCase #432

Closed
lamp opened this issue Aug 18, 2022 · 7 comments
Closed

Unable to eval or run tests when namespace is camelCase #432

lamp opened this issue Aug 18, 2022 · 7 comments

Comments

@lamp
Copy link

lamp commented Aug 18, 2022

Hi,

I'm working in a codebase where I am required to have namespaces in the form:

(ns someName.core)
;; and
(ns someName.core-test)

The folder structure matches the namespace declaration, so src/someName/core.clj and test/someName/core_test.clj

When in these namespaces I am unable to eval or run any tests, when doing so there is no output whatsoever.

After switching the folder structure and namespaces to all be lower case this is no longer an issue, eval and IcedTest* all work as expected.

I have only checked this while using clojure cli, but I don't think there would be any difference with any other tool.

I'm happy to try and fix it myself if I could get some pointers as to where it might be, I did look here but without a little help I am probably going to waste a lot of time.

Many thanks for the project, I find it very useful.

@liquidz
Copy link
Owner

liquidz commented Aug 18, 2022

@lamp Thanks for your reporting!
Hmm, I could not reproduce the problem in my environment.
With the following files, I could evaluate and run tests.

  • deps.edn
    {:paths ["src" "test"]
     :deps {org.clojure/clojure {:mvn/version "1.11.1"}}}
  • src
    • someName
      • core.clj
        (ns someName.core)
        
        (defn foo
          [a]
          (inc a))
  • test
    • someName
      • core_test.clj
        (ns someName.core-test
          (:require
            [clojure.test :as t]
            [someName.core :as sut]))
        
        (t/deftest foo-test
          (t/is (= 2 (sut/foo 1))))

Could you confirm that you can reproduce the problem or not with minimal configuration?
https://liquidz.github.io/vim-iced/#minimal_configuration

@lamp
Copy link
Author

lamp commented Aug 19, 2022

Hey @liquidz ,

Thanks for the reply, I did as you asked and created a sample app using clojure -Tnew app :name myUsername/mynewapp with deps-new as this is as close to what was used to build the real application with which I am working.

I was able to reproduce it with:

  • iced repl
  • mynewapp/ nvim -u ./test_config.vim .
  • go to src/myUsername/mynewapp.clj
  • Connect to REPL
  • attempt to evaluate the contents of the comment statement (and either nothing happens or the an error complaining that println does not exist)
  • go to src/myUsername/test.clj (namespace is myusername.test)
  • attempt to evaulate the contents of the comment statement, which works perfectly.

The only difference I can see is that in one file the namespace starts with myUsername and the other with myusername.

I have attached my sample project for you to take a look, if you need anything else please let me know I will be happy to provide whatever I can.

mynewapp.zip

Additional information

  • NVIM: 0.7.2
  • Clojure: 1.11.1
  • OS X 12.5
  • Absolute latest version of iced as I had just git cloned it

@liquidz
Copy link
Owner

liquidz commented Aug 19, 2022

@lamp Thanks for your confirmation!
Reproduced. I'll try to find the cause.

liquidz added a commit that referenced this issue Aug 19, 2022
liquidz added a commit that referenced this issue Aug 19, 2022
@liquidz
Copy link
Owner

liquidz commented Aug 19, 2022

@lamp I found that ignorecase option is the cause.
Just released v3.10.3061, so could you try the latest version?

@liquidz
Copy link
Owner

liquidz commented Aug 19, 2022

I'm happy to try and fix it myself if I could get some pointers as to where it might be

Ah, sorry, I've fixed it here 😣
I don't know if this will be helpful, but here is the process to solve the problem.

When I reprocuded the problem, I tried to check debug messages with :let g:iced#debug = v:true.
Debug messages contain requests and responses between nREPL as follows.

DEBUG >>>: {'file': '/private/tmp/bar/mynewapp/src/myUsername/mynewapp.clj', 'id': 6, 'nrepl.middleware.print/stream?': 1, 'verbose': v:true, 'column': 3, 'line': 15, 'code': '(println "test")', 'session':'480cb143-4a4f-4a71-8e55-2a3cbd7c7346', 'ns': 'my', 'op': 'eval', 'callback': function('<80><fd>R66__resolve', [{'_rejections': [], 'then': function('<80><fd>R66__promise_then'), '_state': 0, '_vital_promise': 5, '_children': [], '_result': v:null, 'catch': function('<80><fd>R66__promise_catch'), '_fulfillments': [], '_has_floating_child': v:false, 'finally': function('<80><fd>R66__promise_finally')}])}
DEBUG <<<: d2:idi6e2:ns2:my7:session36:480cb143-4a4f-4a71-8e55-2a3cbd7c73466:statusl19:namespace-not-found4:done5:erroree
DEBUG <<<: d2:idi6e7:session36:480cb143-4a4f-4a71-8e55-2a3cbd7c73466:statusl4:doneee

The response(<<<) contains namespace-not-found error message, and the requested(>>>) namespace is 'ns': 'my'.
Thus I assumed that ignorecase option may be affected at this point.

:set ignorecase actually solves the problem, but I don't want to force ignorecase, so I checked the namespace detection process.

function! iced#nrepl#ns#name_by_buf() abort
let view = winsaveview()
let reg_save = @@
try
if iced#nrepl#ns#util#search() == 0
return ''
endif
" Move to next element head
silent normal! l
call sexp#move_to_adjacent_element('n', 0, 1, 0, 0)
" skip meta
let p = getcurpos()
if searchpos('\^', 'cn') == [p[1], p[2]]
call sexp#move_to_adjacent_element('n', 0, 1, 0, 0)
endif
return matchstr(getline('.'), '[a-z0-9.\-]\+', col('.') - 1)
finally
let @@ = reg_save
call winrestview(view)
endtry
endfunction

The matchstr function is using ignorecase like match function, I noticed that I forgot to specify A-Z as a pattern.
So I fixed the pattern in 2b6ec69.

@lamp
Copy link
Author

lamp commented Aug 20, 2022

Ah, sorry, I've fixed it here
Not a problem, thanks for fixing the bug.

I can confirm it now works perfectly in my demo app and the real one, thank you!

let g:iced#debug = v:true
Good to know about this, I did try looking for something in the docs but I must have missed it.

Thanks again

@liquidz
Copy link
Owner

liquidz commented Aug 23, 2022

@lamp Oh sorry, g:iced#debug is not described in documents.
I'll add them in #435.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants