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

Pug syntax highlight #295

Closed
jasonlyu123 opened this issue Jul 9, 2020 · 7 comments · Fixed by #645
Closed

Pug syntax highlight #295

jasonlyu123 opened this issue Jul 9, 2020 · 7 comments · Fixed by #645
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers

Comments

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jul 9, 2020

Is your feature request related to a problem? Please describe.
Provide basic support for pug markup. Related: #106

Describe the solution you'd like
VSCode's syntax highlight is done by Textmate grammar. Basically it's defining some regex pattern to tokenize the code. And we could include other languages' rules as long as vscode knows how to deal with the included language.

I am not using pug so I don't know about pug syntax. It would be great if anyone with more experience with svelte-pug can help.

General guide on how to implement it
It's not hard to implement. First, fork this repo and follow the development instruction. Follow the vscode's official guide for syntax hightlight. Add the patterns needed to the syntax file which is located in packages/svelte-vscode/syntax.

It seems like syntax for the pug in svelte is similar to Vue's. So we could probably copy some code from vetur

This for defining a block to start and end identifying pug syntax:
https://github.com/vuejs/vetur/blob/master/syntaxes/vue.tmLanguage.json#L87

This for telling vscode that we have embedded pug code
https://github.com/vuejs/vetur/blob/master/package.json#L119

These two would add the basic syntax highlight. What's left would be adding svelte specific syntax like +each('posts as post') under pug patterns. Add more patterns and link them to the existing syntax token.
For example each block:

        "svelte-pug-each": {
            "begin": "(\\+)(each)\\(",
            "beginCaptures": {
                "1": {
                    "name": "punctuation.definition.tag.begin.svelte"
                },
                "2": {
                    "name": "keyword.control.conditional"
                }
            },
            "end": "\\)",
            "endCaptures": {
                "0": {
                    "name": "punctuation.definition.tag.end.svelte"
                }
            },
            "patterns": [
                {
                    "begin": "'",
                    "end": "\\s(as)\\s+",
                    "endCaptures": {
                        "1": {
                            "name": "keyword.control"
                        }
                    },
                    "patterns": [
                        {
                            "include": "source.ts"
                        }
                    ]
                }
            ]
        }
@jasonlyu123 jasonlyu123 added feature request New feature or request good first issue Good for newcomers labels Jul 9, 2020
@jasonlyu123
Copy link
Member Author

It seems like the svelte-preprocess' pug syntax is using pug's existing syntax. So we could just copy the corresponding syntax from vscode's pug syntax and modify it to suit our need

@dummdidumm
Copy link
Member

Basic highlighting done through #371 . Maybe this is already enough? The svelte-specific syntax seems to highlight just fine.

@b1mind
Copy link

b1mind commented Aug 2, 2020

@dummdidumm YAY!!
image

Seems to be working, not sure why but it seems partially break in the if/else params . I thought it was template lits at first but as shown in the screen even without the colors are a bit off.

Also the component coloring below the template element seems to change (which does not really matter unless your mixing in html too like I am here for demo).

Super happy about seeing this progress, sorry I was late to test it.

@b1mind
Copy link

b1mind commented Aug 31, 2020

I appreciate you working on this. So I am finally able to get back to my Svelte project and noticed something is def killing the highlighting.

EDIT= removed image while it was passing it was not valid syntax for use with Svelte vars inside a element prop via preprocessors readme.

it seems to break with the " when defining some things within ( ) in loops and if checks though.

@rodshtein
Copy link

JSDoc is't work for pug.
For example It works on html tag inside pug template

image

Component
image

dummdidumm pushed a commit that referenced this issue Oct 30, 2020
Adds improved syntax highlighting when using Pug with Svelte. Uses injected grammars - this way the original Pug grammar is kept as it is, and does not have to be cloned.
#295, #106
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Oct 30, 2020
@hoishing
Copy link

Thanks for the great work! btw, seems inline function is not supported at the moment, say on:click="{ () => doSomething }" will raise errors.

@dummdidumm
Copy link
Member

Intellisense support is tracked in #106 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release. good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants