-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Introduce crystal --stdin-filename source flag #4571
Introduce crystal --stdin-filename source flag #4571
Conversation
1bd3250
to
f911595
Compare
src/compiler/crystal/command.cr
Outdated
if is_fake_source_filename | ||
sources = [Compiler::Source.new(filenames.first, STDIN.gets_to_end)] | ||
else | ||
sources = gather_sources(filenames.not_nil!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.not_nil!
ain't needed here, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Sija. Just refactored code, and it's ok.
Bad naming. Without documentation it's impossible to understand what "fake source" means; it's even confusing (why would my source code be fake?). I'd prefer having |
How about |
--stdin-filepath looks good. |
f911595
to
03476ea
Compare
Code refactored, |
Urgh. Why not just |
@ysbaddaden because it's not very descriptive. I'd assume that |
@ysbaddaden This is for on-the-fly linters to check source code buffer. Every source file has its path, and it's important for relative "require". Nothing in practice can be built without knowledge of its path. |
Any chances to get it merged?) |
@RX14 please review this simple feature |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to allow combining both options the stding and additional files. I am not sure there is a use case for that and the order of the scripts might not be clear.
Due to this additional feature (combining stdin and actual files) some additional arrays are created. I think it could be refactored to avoid that.
In case the playground is removed from the compiler this function might come handy.
@bcardiff same thoughts as me. This is why I can't approve this. I think we just need one flag without arguments. |
@asterite use case - try to compile unsaved code in text editor buffer, which is modified version of on-disk There is So we need to provide original/proposed source file name. |
@akzhan Yes, but it should be:
That is,
In this case only the first filename will be used for the output, so the same should applied for the name for stdin. |
and which filename is used as proposed one for stdin stream in case of crystal file1.cr file2.cr --stdin is stdin file named file1.cr or file2.cr?
|
@akzhan The first one. I explain it in my comment. If you compile many files, the first one is used for the output name. Note that in your PR this is accepted:
I know this is less ambiguous because you specify the name with |
@asterite source file name required not for output (usually editor runs compiler without code generation). it is required to resolve relative It may be used for output too. But trouble is |
@akzhan What do you mean? |
I always think about compiling of multiple files and stdin. so I want to inform compiler where is stdin file originated. Your option - always inform compiler that first file is from stdin. But feel free to apply your option. |
… STDIN, closes crystal-lang#4561. Synopsys: ```bash cat src/math/math.cr | ./bin/crystal build --no-codegen --no-color -o /dev/null -f json --stdin-filename src/math/math.cr ```
03476ea
to
7085f3c
Compare
Renamed to |
Time to 🎲 |
to compile source from STDIN, closes #4561.
Synopsys
cat src/math/math.cr | ./bin/crystal build --no-codegen --no-color -o /dev/null -f json --stdin-filename src/math/math.cr