Skip to content

Scaladoc: Refactor snippet compiler reporting #13351

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

Merged

Conversation

pikinier20
Copy link
Contributor

No description provided.

@pikinier20 pikinier20 requested a review from BarkingBad August 21, 2021 18:42
@pikinier20 pikinier20 force-pushed the scaladoc/snippet-compiler-reporting branch from d3b17d0 to d8e6e1b Compare August 23, 2021 07:55
@@ -129,16 +129,12 @@ abstract class MarkupConversion[T](val repr: Repr)(using dctx: DocContext) {
val path = s.source.map(_.path)
val pathBasedArg = dctx.snippetCompilerArgs.get(path)
val data = SnippetCompilerDataCollector[qctx.type](qctx).getSnippetCompilerData(s, s)
val sourceFile: dotty.tools.dotc.util.SourceFile = s.pos.fold(dotty.tools.dotc.util.NoSource)(_.sourceFile.asInstanceOf[dotty.tools.dotc.util.SourceFile])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get rid of this cast as well? How should we handle failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll refactor this cast. In 99.99% cases there will be source file associated with symbol, especially in end-users projects. Maybe we should just produce warning/info with information that snippet compiler couldn't obtain source files for certain snippets and due to that the positions might not be accurate?

Copy link
Contributor

Choose a reason for hiding this comment

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

In which situation would there be no files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not so fluent with the compiler internals but I can guess that there might be a problem with symbols created synthetically in compiler? For some reason the Position in Symbol is optional, maybe @smarter can provide there some information.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know the context here, if it's a symbol coming from sources it should always have a source associated with it, but you can use s.source to access that just like you do above instead of going through s.pos.

Copy link
Contributor Author

@pikinier20 pikinier20 Aug 23, 2021

Choose a reason for hiding this comment

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

s.source is available only using compiler API of symbol but we need to cast between Quotes API and Compiler API either way. I think that smarter's solution is better because it's used in some places of Scaladoc and seems stable. This way we get SourceFile instead of Option[SourceFile] but still we need to handle NoSource. Actually, I think that getting NoSource is not a failure and should be supported.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I didn't realize it wasn't available in the quotes API, yeah we should try to uniformize these things.

but we need to cast between Quotes API and Compiler API

This is something we absolutely need to get rid of in the future (scaladoc should only use the public API, anything missing in the public API needs to be added to it), so I would caution against making the problem worse by doing even more casting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

99% of casting is done in file called SyntheticSupport, maybe we should take a look at it and create an issue containing all things missing in public API? That was actually a purpose of this file

Copy link
Member

Choose a reason for hiding this comment

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

create an issue containing all things missing in public API?

sounds good yes

@pikinier20 pikinier20 force-pushed the scaladoc/snippet-compiler-reporting branch from d8e6e1b to f8d4168 Compare August 23, 2021 10:39
@pikinier20 pikinier20 merged commit a585969 into scala:master Aug 23, 2021
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
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.

5 participants