Skip to content

Add a custom role to toggle between snake_case and PascalCase syntax #4406

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Nov 25, 2020

snake_case is still used by default, but the user can switch to PascalCase if they use C#. This choice is persisted to the browser's localStorage. This helps decrease the cognitive load for C# users when reading the documentation.

Class reference links have their link text changed automatically to match the user's preference.

Inline code literals have to be converted manually to account for special cases. (Sometimes, going from GDScript to C# involves more than just changing the casing from snake_case to PascalCase.)

Preview

Animation

TODO

  • See whether we can associate data attributes in Sphinx to avoid reflows during page load and have correct display when JavaScript is disabled. I've looked briefly and haven't found any way to do that.
  • Consider using automatic conversion for inline code literals instead of doing it manually. It would be less work for documentation and class reference contributors, but I'm not sure if we can reasonably cover all use cases this way.
  • Modify editor/editor_help.cpp to understand the [snakepascal]snake_case;;PascalCase[/snakepascal] tag.
  • Modify doc/tools/makerst.py to generate :snakepascal: roles from [snakepascal] blocks.
  • Test automatic conversion rules in more real-world scenarios. It probably involves testing in production due to the amount of documentation 🙂

@Feniks-Gaming
Copy link
Contributor

I would suggest renaming it to "GDScript Code Examples" and "C# Code Examples" otherwise some people may be confused that those too can be used interchangeably in thier code.

@Calinou
Copy link
Member Author

Calinou commented Nov 25, 2020

I would suggest renaming it to "GDScript Code Examples" and "C# Code Examples" otherwise some people may be confused that those too can be used interchangeably in thier code.

I've considered naming the options "GDScript" and "C#" instead of "snake_case" and "PascalCase", but there is no 1:1 mapping between syntax styles and languages. For instance, if you use GDNative or a C++ module, you're going to use snake_case.

@Feniks-Gaming
Copy link
Contributor

Maybe then add snake_case(GDScript) and PascalCase? Likely people who are using something else than GDScript are already experienced enough to figure out what coding style they should follow. This will help brand new who meet the engine for a first time to use the right style while still leaving others to use the Syntax that represents their language

@Calinou
Copy link
Member Author

Calinou commented Nov 25, 2020

Maybe then add snake_case(GDScript) and PascalCase?

There's already a tooltip for each option telling you which languages each syntax is used in. I think that's enough 🙂

@Feniks-Gaming
Copy link
Contributor

Okay that's fair.

@Calinou Calinou force-pushed the add-snake-pascal-toggle branch from a76cd68 to 2671ca8 Compare December 4, 2020 18:25
…yntax

TODO:

- See whether we can associate data attributes in Sphinx to avoid
  reflows during page load and have correct display when JavaScript
  is disabled.
- Modify `doc/tools/makerst.py` to take this role into account.
- Test automatic conversion rules in more real-world scenarios.
  It probably involves testing in production due to the amount
  of documentation :)
@Calinou Calinou force-pushed the add-snake-pascal-toggle branch from 2671ca8 to cb7212f Compare February 15, 2021 22:41
@akien-mga akien-mga self-requested a review March 19, 2021 12:50
@mhilbrunner
Copy link
Member

mhilbrunner commented Jul 6, 2021

Now that we updated sphinx-tabs in #4995: the new Sphinx tabs tries to remember the active tab (GDScript vs. C#) too between page loads it seems.

Maybe we can

  1. re-use that information
  2. toggle this automatically whenever you switch between GDScript/C# tabs
  3. maybe make this toggle those tabs automatically too

And while its indeed not a perfect or correct mapping, I'm somewhat leaning towards labelling it 'GDscript/C#' too, may be less confusing to new users while those who know C++ etc. will still likely know what to do/press?

Edit: besides this discussion, love this work :) Way less mental overhead for me as a C# user!

@VinnNo
Copy link

VinnNo commented Oct 26, 2021

I like this a lot! I think it could potentially be a good foundation for dividing the docs across different languages. Though, I think having language specific tabs would be more intuitive and scalable than the writing style tabs. Overall, I think this is a fantastic stepping stone. Now, how would we proceed on populating the docs with C# counterparts to start with, using this?

@YuriSizov YuriSizov added the content:website Issues related to adding website features and fixing bugs, whether on the front or back-end label Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content:website Issues related to adding website features and fixing bugs, whether on the front or back-end enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add toggle to documentation for C# API, such as PascalCase method names
5 participants