rodolphebarbanneau / python-docstring-highlighter

Syntax highlighting for Python Docstring in VSCode.
https://marketplace.visualstudio.com/items?itemName=rodolphebarbanneau.python-docstring-highlighter
MIT License
52 stars 2 forks source link

Example for changing the setting #1

Closed cheginit closed 7 months ago

cheginit commented 8 months ago

This sounds like a very useful extension, thanks for making it available!

I have some difficulty changing the settings. I want to set the style to numpy. From your documentation, I couldn't figure out exactly how to change the style in setting.json. I tried adding "docstring.type": "numpy", but it didn't work.

rodolphebarbanneau commented 7 months ago

Hello, thank you for your feedback!

I understand you're looking to change the "style type" similar to numpy or google within the extension. While the extension doesn't offer a direct option to switch between these specific styles, it does provide a feature for theming through the use of scopes. You can explore this in the customization section (customization). Here, you'll find that some scopes are designed to target specific style types, including ones like "numpy".

This extension is particularly beneficial when dealing with third-party libraries, whose documentation styles may vary. When you introspect the code from these libraries, the extension's highlighting feature will highlight documentation no matter what style is used.

Keep in mind this extension is for highlighting only, it doesn't enforce any style rules.

cheginit commented 7 months ago

I see. So, out of the box, it should support numpy-style docstring highlighting. I always used this style for my docstrings, but when I installed this extension, it didn't correctly highlight the args, like the demo. Here's what I see when I open a function from numpy:

image

So, it's not detecting arg names or types, and seems to be working partially.

rodolphebarbanneau commented 7 months ago

I think the issue is with your theme that may blends the scopes color. Bellow you'll see what I get with the modern dark theme in VSCode:

Screenshot 2024-03-17 at 20 14 04

You can analyze this on your side:

Screenshot 2024-03-17 at 20 36 34

As you can see, the extension adds a bunch of scopes and VSCode will look up for the first scope that implements a style. In my example, it's the punctuation.definition.tag style that is used (standard scope as I don't have custom theming). You can override this behavior by adding this in you settings.json file for instance:

"editor.tokenColorCustomizations": {
  "textMateRules": [
    {
      "scope": "docstring.variable",
      "settings": {
        "fontStyle": "bold underline",
        "foreground": "#569cd6",
      }
    },
  ]
}

Then you can play around to make it as you like!

cheginit commented 7 months ago

Ah, that's right. I am using One Dark. That's neat! I ended up using this:

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "docstring.variable.placeholder",
                "settings": {
                    "fontStyle": "bold",
                    "foreground": "#569cd6",
                },
            },
            {
                "scope": "docstring.variable.end",
                "settings": {
                    "foreground": "#a1c1dc92",
                },
            }
        ]
    }

to get:

image

Thanks for the help!