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

[Py] - Print root module and module function comments #4027

Merged
merged 5 commits into from
Jan 28, 2025

Conversation

alfonsogarciacaro
Copy link
Member

Hey there! Cool project ;)

Just a small PR to print root module and module function comments in Python so the linter stops complaining.

Example:

/// A gratuitous example of a module that depends
/// on another module
module Module2

/// Adds two numbers
/// and returns the result
let add x y = 
    Module1.add x y + 4

becomes:

"""A gratuitous example of a module that depends on
another module
"""
from Module1.module1 import add as add_1

def add(x: int, y: int) -> int:
    """Adds two numbers
    and returns the result
    """
    return add_1(x, y) + 4

I had to modify the signature of FSharp2Fable.fsi and the Compiler interface, I hope that's ok, but let me know if another way is preferred.

Cheers!

@pkese
Copy link
Contributor

pkese commented Jan 28, 2025

Omg @alfonsogarciacaro

It's soooooo nice to see you here again.

Warmest regards. I hope you're doing well wherever you are.

@ncave
Copy link
Collaborator

ncave commented Jan 28, 2025

I'm very glad to hear from you again, @alfonsogarciacaro, I hope all is well with you and best wishes!

This looks good, just needs the linting (dotnet fantomas .)

@MangelMaxime
Copy link
Member

Hello @alfonsogarciacaro, glad to hear from you.

Tips if you run ./build.sh at least once, then the formatting will happen automatically on authoring commit.

@MangelMaxime MangelMaxime merged commit 9949737 into fable-compiler:main Jan 28, 2025
12 checks passed
@TheAngryByrd
Copy link

👋 Glad good to see you again! @alfonsogarciacaro

@ncave
Copy link
Collaborator

ncave commented Jan 28, 2025

Perhaps we could retain the comments for every module, instead of just the root module, with a slight update to the Fable AST:

type ModuleDecl =
    {
        Name: string
        Entity: EntityRef
        Members: Declaration list
        XmlDoc: string option   // <--- new optional property
    }

It is an optional property so it shouldn't be technically a breaking change.
I know it's not that useful for target languages that flatten their modules like JS/TS,
but it can still be helpful to output the comments for inner modules.

@alfonsogarciacaro
Copy link
Member Author

Thank you @pkese, @ncave, @MangelMaxime, @TheAngryByrd for the warm welcome ❤️ ...and for accepting the PR.
The youngest is finally about to start primary school and work is a bit less crazy now, so stress is slowly coming back to manageable levels. Not sure if I can dedicate much time to open source again, but playing with Fable 5 is a lot of fun!

@MangelMaxime
Wow, there is a lot of useful stuff in the repo now! Actually, I did run build.sh once but Husky gave me an error, so I just commented out the line that activates it for now. I need to look into that.

@ncave
That makes a lot of sense, the only reason I didn't add the comment to the Module declaration is Fable AST erases it, so I had to find another way to pass the info. But adding the XmlDoc to the ModuleDecl as well sounds like the right thing to do.

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