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

Namespace Metadata Breaks Evaluation #204

Closed
semperos opened this issue May 6, 2021 · 7 comments
Closed

Namespace Metadata Breaks Evaluation #204

semperos opened this issue May 6, 2021 · 7 comments

Comments

@semperos
Copy link

semperos commented May 6, 2021

Howdy 👋

clj-style will transform metadata like this:

(ns ^{:clj-kondo/config {:lint-as '{my-awesome/defn-like-macro clojure.core/defn}}} foo)

Into metadata like this:

(ns ^{:clj-kondo/config {:lint-as (quote {my-awesome/defn-like-macro clojure.core/defn})}} foo)

The ' version works fine with Conjure. The quote version does not and gives the following error if you invoke, for example, ConjureEvalRootForm:

; eval (root-form): (ns ^{:clj-kondo/config {:lint-as (quote {my-awesome/d...
; Namespace not found: ^{:clj-kondo/config

Thanks in advance for any time you have to help!

@Olical
Copy link
Owner

Olical commented May 8, 2021

Thank you for raising this! I'm investigating now, I suspect it's to do with Lua's string pattern matching system not working quite how I thought it was. Luckily this area is easy to unit test, adding your examples there now 😄

@Olical
Copy link
Owner

Olical commented May 8, 2021

Okay, should be fixed on develop! Let me know if that's done the trick for you! Thank you for catching it, I just had to swap some lines around, stripping the metadata part of the ns before I try to extract other information.

@semperos
Copy link
Author

@Olical Thanks a million! 🎉 Works as expected.

@Olical Olical closed this as completed in 627dc89 May 15, 2021
@NoahTheDuke
Copy link

I believe this is broken when the metadata is across multiple lines. Below is the minimal number of lines I could get it to fail:

(ns 
  ^{:doc "A BDD testing framework.
         
         
         
         
         
         asdf
         
         
         asdf
         asdf
         asdfasdf
         as
         dfasdf
         asdfasdfasdf
         asd
         as
         dfasdfasdf
         asdfasdfasdf
         asdf
         asdf
         "
   }
  lazytest.core
  (:refer-clojure :exclude [test])
  (:require
   [clojure.test]
   [lazytest.context :as ctx]
   [lazytest.malli]
   [lazytest.suite :as suite]
   [lazytest.test-case :as test-case])
  (:import
   (lazytest ExpectationFailed)))

Version: conjure commit 6d2bc7f
neovim: 0.10.0

@Olical
Copy link
Owner

Olical commented Oct 20, 2024

This is due to this limit which we could raise significantly really, maybe even just the whole file.

conjure/doc/conjure.txt

Lines 765 to 774 in 6d2bc7f

*g:conjure#extract#context_header_lines*
`g:conjure#extract#context_header_lines`
How many lines of the file should be checked for a context
(namespace name) such as `(module foo.bar)` or `(ns foo.bar)`
which is used for setting the right context for evaluations.
If you have buffers with huge comment headers you may want to set
this higher.
If a specific buffer isn't extracting the context correctly, you
can override it by setting `b:conjure#context`.
Default: `24`

I think I added it because it's checked on every evaluation and I didn't want to add too much pre-work to each evaluation, just in case HUGE buffers slowed down some machines.

The worst case scenario that a user would notice though would be as follows:

  • Slow machine
  • Large buffer
  • No namespace / module name so we search to the end trying to find it

That's actually quite unlikely... so maybe I'll default this value to nil and have nil mean infinite. So if a user is working in a project or language that would benefit from it then they can set it, but most users won't need it.

Olical added a commit that referenced this issue Oct 20, 2024
This may be slow for some people, but I think it makes sense as the
default on the whole.
@Olical
Copy link
Owner

Olical commented Oct 20, 2024

Changed the default on the main branch to -1 which means "all lines". Also updated the documentation.

@NoahTheDuke
Copy link

Thank you. I should have checked the configuration before posting.

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

3 participants