zed icon indicating copy to clipboard operation
zed copied to clipboard

Python: allow Docstring coloring different than other "strings"

Open krstp opened this issue 1 year ago • 5 comments

Check for existing issues

  • [X] Completed

Describe the feature

This is request to enable different Docstring coloring vs. other "strings". I say strings, because currently ZED does not differentiate between any regular string definition and Docstring. I would rather expect Docstring to be recognized to similar coloring as in-line comments or perfectly a separate color block.

If applicable, add mockups / screenshots to help present your vision of the feature

Current status of Docstring coloring: see attached screenshot. Notice log string statement has the same color as the """ Docstring text. IMHO, those two should definitely have separate colors. Notice also coloring of the in-line comment. I would sooner expect Docstring to have similar coloring to the comment text. Screenshot 2024-02-03 at 4 56 29 PM

What I would perfectly want to achieve: proposed

krstp avatar Feb 03 '24 23:02 krstp

I'd argue that docstrings should be considered doc comments for the purpose of syntax highlighting

jansol avatar Feb 03 '24 23:02 jansol

This is fine, all I care about is ability to specify diff color between those two.

krstp avatar Feb 05 '24 21:02 krstp

Reference to similar ticket: https://github.com/zed-industries/zed/issues/4296

krstp avatar Feb 05 '24 21:02 krstp

I specifically mentioned that because the user themes that landed in preview builds last week do have separate styles for "comment" and "comment.doc". So this would just be a matter of making the tree sitter definition categorize the doc strings correctly.

jansol avatar Feb 05 '24 21:02 jansol

Yeah, I've seen it. Needless to say it is not clear to me what comment.doc does affect. At least on python level I do not see it affecting code or any comments in any way. Thanks though for reiterating this.

krstp avatar Feb 05 '24 21:02 krstp

I took a stab at this in https://github.com/zed-industries/zed/pull/7585 and was able to get it working.

However, after a bit of further investigation, it seems that treating docstrings as comments/doc comments from a syntax highlighting perspective is a bit of a contentious topic, and both GitHub and VS Code seem to fall on the side of treating them as strings.

While I don't think treating docstrings as comments by default is the right choice, it does seem like a desirable feature to be able to style them separately, should you want to.

I ended up introducing a new string.doc syntax node for docstrings in https://github.com/zed-industries/zed/pull/7587.

By default, Python docstrings will be displayed using the string styles, but if you add a string.doc in your theme it will take precedence and allow you to style docstrings separately from strings.

maxdeviant avatar Feb 08 '24 19:02 maxdeviant

Thank you for taking care of this. And yes, this is what I had in mind. Can't wait to test it out with next release 🙏

krstp avatar Feb 08 '24 20:02 krstp

Is this live? I don’t see mt obe able to get it to work.

tommydangerous avatar Jun 02 '24 20:06 tommydangerous