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

Categorize async Python keyword as a primary keyword when used in function declaration #210

Closed
j-d-ha opened this issue Dec 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@j-d-ha
Copy link
Contributor

j-d-ha commented Dec 9, 2024

Describe the need of your request

First off, I love this plugin, and it's the first plugin I install when setting up any JetBrains IDE. Thank you for building and maintaining it!

I have noticed that the async Python keyword is not properly themed when it is followed by the def keyword to match VSCode. With this theme enabled in PyCharm, the async keyword is always categorized and themed as a secondary keyword. By contrast, in VSCode, the async keyword is themed as a primary keyword if it is followed by def as part of a function declaration but themed as a secondary keyword everywhere else. Below are screenshots showing this.

VSCode
image

PyCharm
image

It would be cool if the categorization of the async keyword could be conditional based on how it's used.

Proposed solution

Since secondary keyword categorization and color assignment is handled by an annotator that extends the BaseAnnotator class, it is possible to get a given element's next sibling inside of the getKeywordType method. This allows for the primary vs secondary keyword categorization for the async keyword based on if the async keyword's next sibling is a def keyword.

I have already tested the bellow code and it works! I have added a screenshot to demonstrate this:

image

Note that the async keyword is now categorized and colored as a primary keyword when followed by a def keyword, but when the async keyword is followed by any other keyword it is categorized and colored as a secondary keyword`

// logic for other keywords
"async" -> {
    type =
        generateSequence(element.nextSibling) { it.nextSibling }
            .firstOrNull { it !is PsiWhiteSpace }
            ?.let { nextWord ->
                when {
                    nextWord.elementType == PyTokenTypes.DEF_KEYWORD -> DEFAULT_KEYWORD
                    isJupyterNoteBook(element) -> SECONDARY_KEYWORD_WITH_BG_JUPYTER
                    else -> SECONDARY_KEYWORD_WITH_BG
                }
            }
            ?: if (isJupyterNoteBook(element)) SECONDARY_KEYWORD_WITH_BG_JUPYTER
            else SECONDARY_KEYWORD_WITH_BG
}

Alternatives you've considered

No response

Additional context

No response

@j-d-ha j-d-ha added the enhancement New feature or request label Dec 9, 2024
dinbtechit added a commit that referenced this issue Dec 9, 2024
…or-async

Feature for #210 - Categorize async Python keyword as a primary keyword when used in function declaration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants