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

Add support for using directive in java files #639

Merged
merged 6 commits into from
Feb 21, 2022

Conversation

ghostbuster91
Copy link
Contributor

This closes #533

Joint work with @mtk, @romanowski in the framework of the issue spree.

val content = value(PreprocessingUtil.maybeRead(j.path))
val scopePath = ScopePath.fromPath(j.path)
val ExtractedDirectives(_, directives0) =
value(from(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could enrich the DirectiveError here with the information that it happened in the java context but the DirectiveError is an opaque class.

Copy link
Member

@romanowski romanowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, the UX parts needs to be polished. We can also do it as a follow up PR, especially that we need to update documentation etc.

logger.diagnostic(msg, positions = Seq(position))
}

val usedDirectives =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a situation when Java file starts with following code:

using foo 1
//> using bar 2

User will get a warning that bar is ignored and error that foo is unsupported what is a bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to resolve priority only against supported directives?

if (supportedDirectives.contains(usedDirectives.getKind()))
Right(ExtractedDirectives(offset, strictDirectives))
else
Left(new DirectiveErrors(::(s"Unsupported using directive kind ${usedDirectives.getKind}", Nil)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message may be confusing since in general keyword using directives are supported but not in the context of Java files and message should reflect that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I've just realized that we do not provide a location where are the problematic cases. I think we should use something similar UnusedDirectiveError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message may be confusing since in general keyword using directives are supported but not in the context of Java files and message should reflect that.

Agree.

The problem is that higher layers cannot refine error messages from lower layers as they are opaque in the current error design. Here we call same function ExtractedDirectives.from from two different context: scala and java. Each of these context should enrich the message. If only DirectiveErrors was a case class...

I can change that but I am afraid that it will makes this PR much bigger.

@romanowski
Copy link
Member

@ghostbuster91 we are cutting a release and we needed #618 that introduce conflicts with your PR. I am happy to fix the merge conflicts for you, just let me know if I should do it.

@ghostbuster91
Copy link
Contributor Author

@ghostbuster91 we are cutting a release and we needed #618 that introduce conflicts with your PR. I am happy to fix the merge conflicts for you, just let me know if I should do it.

Feel free, I don't mind doing it either way.

@ghostbuster91
Copy link
Contributor Author

ghostbuster91 commented Feb 10, 2022

When I tried running ./mill -i scala https://gist.github.com/dacr/e4d928a85acd580b4a756fd7ff36a735 I got the same error as in the original issue. However when I run the script locally (./mill -i scala Issue533UsingLibForJava.java) it doesn't fail but helloWorlds doesn't get printed either. Any idea what is the reason behind such behavior?

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.

Support "using lib" for java scripts
2 participants