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

let crystal tool expand find target location into the deep of require #8987

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

makenowjust
Copy link
Contributor

@makenowjust makenowjust commented Apr 1, 2020

Fixed #6098

As a side effect, crystal tool expand can expand require statement now.
I think it may help us.

Example:

$ cat -n test.cr
     1	macro test
     2	  def to_json
     3	    "hey"
     4	  end
     5	end
     6
     7	class Test
     8	  test
     9	end
$ cat -n main.cr
     1	require "./test"
     2	p Test.new.to_json
$ # issue is fixed.
$ bin/crystal tool expand -c test.cr:8:3 main.cr
1 expansion found
expansion 1:
   test

# expand macro 'test' (test.cr:1:1)
~> def to_json
     "hey"
   end

$ # now `require` can be expanded.
$ bin/crystal tool expand -c main.cr:1:1 main.cr
1 expansion found
expansion 1:
   require "./test"

~>
   # /Users/makenowjust/Projects/github.com/MakeNowJust/crystal/test.cr
   macro test
     def to_json
       "hey"
     end
   end
   class Test
     test
   end

# expand macro 'test' (/Users/makenowjust/Projects/github.com/MakeNowJust/crystal/test.cr:1:1)
~>
   # /Users/makenowjust/Projects/github.com/MakeNowJust/crystal/test.cr
   macro test
     def to_json
       "hey"
     end
   end
   class Test
     def to_json
       "hey"
     end
   end

Note that spec is missing for now.
Because there are no foundation to write tool expand spec over multiple files currently.
How to write spec is better...?

…ire` (fixed crystal-lang#6098)

As a side effect, `crystal tool expand` can expand `require` statement now.
I think it may help us.

Note that spec is missing for now.
Because there are no foundation to write `tool expand` spec over multiple files currently.
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

Successfully merging this pull request may close these issues.

[crystal tool expand] Can not expand macro in class body of included files.
1 participant