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

Fix syntax highlighting for param tag #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EvilGenius13
Copy link
Contributor

Closes: https://github.com/Shopify/developer-tools-team/issues/557
Note There is some code from the description PR that I have in here to ensure everything is working. I will rebase once we merge that.

What is this PR doing?

There was a syntax highlighting error when you would have a hyphen in a variable name before the hyphen used to show a description in a param tag.

For example"
@param {String} title - The title of the product would properly highlight the code.
@param {String} my-title - The title of the product would stop highlighting properly after my-

This is because we were matching on the first hyphen found. I've reworked the matching and now we look for the first space after the variable name. This is a lot more robust.

The changes work even if you don't add the variable type such as {String}

Before:
image

After:
image

This commit fixes an issue where the param tag would incorrectly
match the first "-" found and comment anything after it.
This broke snake case variables and other similar cases.
Copy link

@aswamy aswamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple comments, but overall good 👍

{
"include": "#liquid_doc_fallback_tag"
}
]
},
"liquid_doc_param_tag": {
"match": "(@param)\\s+(?:({[^}]*}?)\\s+)?([a-zA-Z_]\\w*)?",
"match": "(@param)\\s+(?:({[^}]*}?)\\s+)?([a-zA-Z_][\\w-]*)?(?:\\s+(.*))?",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"match": "(@param)\\s+(?:({[^}]*}?)\\s+)?([a-zA-Z_][\\w-]*)?(?:\\s+(.*))?",
"match": "(@param)\\s+(?:({[^}]*}?)\\s+)?(\\[?[a-zA-Z_][\\w-]*\\]?)?(?:\\s+(.*))?",

Let's also capture optional params

"match": "(@description)\\b",
"captures": {
"1": {
"name": "storage.type.class.liquid"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the contents of description, example, and param in string-color rather than comment-color?

I know why we chose comment (since JS doc also appears as a comment), but we should really only use comments for our comment tag or text nodes instead of doc tag.

image

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

Successfully merging this pull request may close these issues.

2 participants