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

Differentiate between tag and valuie #7

Closed
Bobronium opened this issue May 17, 2022 · 7 comments
Closed

Differentiate between tag and valuie #7

Bobronium opened this issue May 17, 2022 · 7 comments

Comments

@Bobronium
Copy link
Contributor

Problem

I'm porting Darcula theme from PyCharm and trying to achieve same look for docstrings.

Your extension works like a charm, however it doesn't differentiate between tag and its value, making it impossible to replicate PyCharm look, or do other customisations (e.g. highlight only param value, or highlight it s source):

PyCharm VSCode
image image
Details

My current json settings:

        {
            "scope": [
                "entity.name.tag.sphinx",
                "punctuation.definition.interpreted.sphinx"
            ],
            "settings": {
                "foreground": "#629755",
                "fontStyle": "italic bold underline"
            }
        },

Inspector:

image

Proposal

Introduce separate scope for tag value, e.g. entity.name.tag.value

Thank you for the awesome extension!

@Bobronium
Copy link
Contributor Author

I've made a regex with named groups:

(?P<open>:)(?P<tag>[A-z]{1,}[A-z0-9]*?)[\s]*?(?P<argument>[A-z]{1,}[A-z0-9]*?)?(?P<close>:)
example usage
docstr = """
:par32ram arg1: description
:param arg2: description
:type arg1: type description
:type arg1: type description
:return: return description
:rtype: the return type description
"""

for line in docstr.split("\n"):
    match = re.search(
        r"(?P<open>:)(?P<tag>[A-z]{1,}[A-z0-9]*?)[\s]*?(?P<argument>[A-z]{1,}[A-z0-9]*?)?(?P<close>:)",
        line
    )
    if match:
        print(match.groupdict())
output
{'open': ':', 'tag': 'par4m', 'argument': 'arg1', 'close': ':'}
{'open': ':', 'tag': 'param1', 'argument': 'arg2', 'close': ':'}
{'open': ':', 'tag': 'type', 'argument': 'arg1', 'close': ':'}
{'open': ':', 'tag': 'type', 'argument': 'arg1', 'close': ':'}
{'open': ':', 'tag': 'return', 'argument': None, 'close': ':'}
{'open': ':', 'tag': 'rtype', 'argument': None, 'close': ':'}

@leonhard-s
Copy link
Owner

Both VS Code and TextMate allegedly support named RegEx groups, but I have been unable to make them work in VS Code grammar definitions, so I will have to keep using indices to identify capture groups.

I have introduced the entity.name.tag.value.sphinx scope to the name portion of a named tag, with entity.name.tag.sphinx still being used for unnamed tags, the tag identifier itself, and the domain selector for cross-references:

Example screenshots from Development version

image

image

image

I have pushed the above changes to the develop branch if you wish to do further testing.

Please do let me know if you encounter any other issues with the current parsing behaviour. I originally created this extension to help me navigate my own projects, and scope name selection was therefore often governed by what provided good contrast in the themes I used most.

@leonhard-s
Copy link
Owner

Closing as this was implemented in fe1d69b.

@Bobronium
Copy link
Contributor Author

Thank you! Any ETA on releasing the update to marketplace?

1 similar comment
@Bobronium
Copy link
Contributor Author

Thank you! Any ETA on releasing the update to marketplace?

@leonhard-s
Copy link
Owner

I just published v0.2.0 on the VS Code Marketplace containing the new additions. It might take a few hours before it shows up due to caching, but it should become available to you over the course of the day.

Thank you for the contributions!

@Bobronium
Copy link
Contributor Author

Thank you for fast response and great extension!

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

No branches or pull requests

2 participants