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

Commented out CSS string breaks syntax highlighting for rest of file #6

Open
MorningLightMountain713 opened this issue Nov 4, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@MorningLightMountain713
Copy link

MorningLightMountain713 commented Nov 4, 2023

Eg

    class Test(Widget):
        # DEFAULT_CSS = """
        #     Test {
        #         width: auto;
        #         height: auto;
        #     }
        # """

Makes the rest of the file change colors. The first triple quote is still visible.

Here is a screenshot:

Screenshot 2023-11-04 at 8 14 58 AM

Normal:

Screenshot 2023-11-04 at 8 16 12 AM
@rodrigogiraoserrao rodrigogiraoserrao added the bug Something isn't working label Nov 6, 2023
@rodrigogiraoserrao rodrigogiraoserrao self-assigned this Nov 6, 2023
@rodrigogiraoserrao
Copy link
Collaborator

Hey @MorningLightMountain713, thanks for reporting this issue!

As a temporary workaround, may I suggest that you comment out the DEFAULT_CSS with triple single-quotes?
Like so:

class Test(Widget):
    '''
    DEFAULT_CSS = """
        Test {
            width: auto;
            height: auto;
        }
    """
    '''

This won't break highlighting for the remainder of the file.

@willmcgugan
Copy link
Contributor

@rodrigogiraoserrao What would be involved in fixing this?

@rodrigogiraoserrao
Copy link
Collaborator

@rodrigogiraoserrao What would be involved in fixing this?

A “quick & dirty” solution:
right now, we detect TCSS inside Python by using a regex that looks for things like DEFAULT_CSS = """ and the matching """.
I could change the regex to make sure that the only thing coming before the class variable is whitespace.

Pathological cases like the one below would still fail, but maybe they're so pathological that it is ok:

class Test(Widget):
    some_class_var = 3; DEFAULT_CSS = """Test { width: auto; height; auto }"""

For the more foolproof solution I'd need to check the VS Code extension docs.

@willmcgugan
Copy link
Contributor

I see. I assumed it was more clever than that. So it would break if you used single quotes?

If regex is the only solution then I think it will be difficult if not impossible to completely guard against it.

@rodrigogiraoserrao
Copy link
Collaborator

No, it doesn't break with single quotes and I think the quick & dirty fix is well worth it.

The whole grammar is a bunch of regular expressions because that's just the format for syntax highlighting, there's not much I can do about it.
You can see here, here, here, and here, the four regular expressions that find TCSS embedded in Python.
They can be improved a bit, but like you say they'll hardly ever be perfect.

For smarter things, I think we'd need a language server that runs in the background.
If we end up doing things like linting action names + action methods, message handler methods, watcher methods, etc, you may end up having a language server in the future either way.
As of now, I have no idea how difficult it is to have a basic one running, but I've seen docs pages about it.

@willmcgugan
Copy link
Contributor

Given there is a workaround, suggest we park this for now. We can revisit it in the future to make it a bit smarter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants