Closed ePaul closed 8 years ago
I don’t think I can do this without typechecking the code, sorry.
Yes Lucas you're right about that.
Although you could do it with a crappy implementation that doesn't try to disambiguate inner scoped declarations and just looks at the import list.
I guess that would actually work almost all of the time… if you have an inner scoped sh
value, then sh
as annotation will be an error anyways.
Hang on, I missed this bit:
Mentioning them with
--inlineAnnotations
doesn't seem to help either.
This should definitely work. What’s your exact invocation?
I'm currently not at that computer, I will check again in the evening ... I think it was something like this:
ceylon format --inlineAnnotations 'sh fo va default actual' source/codegolf/tinylisp63352/expressions.ceylon
I also tried with a =
instead of the space after --inlineAnnotations
, no difference. Should it be comma-separated? (Then the documentation needs to be changed.)
Update: I tried again ... if using --inlineAnnotations 'sh fo va default actual'
, it doesn't destroy the annotation formatting, but it doesn't restore it either. So if the input is like either example in my first post, it stays this way.
Unfortunately the formatter in the IDE doesn't seem to have a way of configuring any formatting options, so it "destroys" it on the next Source → Format, even if I manually fix everything :-/
Wow, this took me a while to figure out. Here’s what happened:
ceylon format file.ceylon
. The formatter, unexpectedly, put newlines after your annotations.ceylon format --inlineAnnotations 'sh fo va default actual' file.ceylon
on the same file. With these inlineAnnotations
, the formatter didn’t enforce line breaks after these annotations… but it also didn’t explicitly remove the line breaks that the previous run had introduced.In other words, running ceylon format --inlineAnnotations 'sh fo va default actual'
on the following file:
import ceylon.language {
sh=shared,
fo=formal
}
interface X {
sh fo V v(S t);
sh fo G g;
}
indeed leaves it untouched – but if you already have line breaks, the formatter keeps them.
I think I’ll change it so that inline annotations will always be forced to have no line breaks after them.
I'm recently doing code golf in Ceylon, and one of the tricks to get a shorter program is using alias-imports for everything which appears several times.
One of my recent programs started this way (after being formatted):
(
G
,V
andS
are classes defined lower down.)I actually would expect the formatter to format the interface like this:
The formatter doesn't seem to recognize the aliases as inline annotations, and formats them as "normal" annotations on separate lines.
Mentioning them with
--inlineAnnotations
doesn't seem to help either.(I'm using the 1.2.0 version.)