Skip to content

Scala3doc: improve stdlib loading #10593

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

abgruszecki
Copy link
Contributor

@abgruszecki abgruszecki commented Dec 2, 2020

This PR fixes the issue that prevented us from loading stdlib together w/ other artifacts, and makes the doctool aware of stdlib patching going on in the compiler.

@abgruszecki abgruszecki changed the title Scala3doc/improve stdlib loading Scala3doc: improve stdlib loading Dec 2, 2020
@abgruszecki
Copy link
Contributor Author

Alright, there's one problem with this PR: it now documents multiple projects together, and those projects actually use different docstring syntax. See : https://scala3doc.virtuslab.com/pr-improve-stdlib-loading/scala3/-scala%203/-a-p-i/scala/-predef.html?query=object%20Predef%20extends%20LowPriorityImplicits .

@abgruszecki
Copy link
Contributor Author

@abgruszecki
Copy link
Contributor Author

Alright, there's one problem with this PR: it now documents multiple projects together, and those projects actually use different docstring syntax. See : https://scala3doc.virtuslab.com/pr-improve-stdlib-loading/scala3/-scala%203/-a-p-i/scala/-predef.html?query=object%20Predef%20extends%20LowPriorityImplicits .

The best fix I can think of is to set default syntax to wiki and add @syntax markdown to every comment outside of stdlib. @romanowski if you have a better idea, let me know; this'll be a problem when trying to document multiple projects as well, but I can't think of any good solution.

Copy link
Contributor

@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.

Generally I think we should try to not hardcode any stdlib related logic in doctool.

// NOTE we avoid documenting definitions in the magical stdLibPatches directory;
// the symbols there are "patched" through dark Dotty magic onto other stdlib
// definitions, so if we documented their origin, we'd get defs with duplicate DRIs
if !root.symbol.show.startsWith("scala.runtime.stdLibPatches") then
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should turn this into setting and do not hardcode in the logic itseld (I can see usage for excluding bits from documentation)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we have a separate issue for that? I can already see a bunch of things that would need to be considered with such an option (should the option take a list of full package names? a list of FQN string prefixes?) and I'd rather discuss them separately.

/** Extracts members while taking Dotty logic for patching the stdlib into account. */
def extractPatchedMembers: Seq[Member] = {
val ownMembers = c.extractMembers
def extractPatchMembers(sym: Symbol) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that logic be placed into TASY? I mean people may wan to parse tasty from stdlib and they will be really supprised what they will get

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tasty Reflect is already aware of how the compiler patches stdlib definitions. Our problem is that we rely on class bodies to document classes, and those aren't patched.

We can open a separate issue for patching class bodies as well.

@romanowski
Copy link
Contributor

I think we can use similat approach as for sourcelinks or we will use for extenrnal docs. So we can either pass a single value (as we do now) or pass pairs filePattern,wiki syntax since people may have similar problems in thier repos (e.g. when documenting shared code and new pieces for scala 3)

@abgruszecki
Copy link
Contributor Author

I think we can use similat approach as for sourcelinks or we will use for extenrnal docs. So we can either pass a single value (as we do now) or pass pairs filePattern,wiki syntax since people may have similar problems in thier repos (e.g. when documenting shared code and new pieces for scala 3)

I agree, but the filePattern should probably reference the path to the .tasty file we loaded the definition from, otherwise it will be painful to use. I looked into it and we can't get that right now.

Right now I'm looking into just defaulting to wiki syntax for stdlib docs. That may require the least changes to already-existing docstrings.

@romanowski
Copy link
Contributor

Lets merge it for now and remove hardcoded bits in follow up PRs

@abgruszecki abgruszecki merged commit 26ad497 into scala:master Dec 2, 2020
@abgruszecki abgruszecki deleted the scala3doc/improve-stdlib-loading branch December 2, 2020 18:11
@Kordyjan Kordyjan added this to the 3.0.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.

3 participants