izhangzhihao / intellij-rainbow-brackets

🌈Rainbow Brackets for IntelliJ based IDEs/Android Studio/HUAWEI DevEco Studio/Fleet
https://plugins.jetbrains.com/plugin/10080-rainbow-brackets
GNU General Public License v3.0
4.47k stars 214 forks source link

Pug Language Support #897

Closed CS-Birb closed 3 years ago

CS-Birb commented 3 years ago

Your programming language(s)

Pug

Expected Behavior

Current Behavior

Pug appears to be entirely unsupported currently. No difference is noticeable whether the plugin is enabled or disabled.

Code snippet for reproduce (for bugs)

doctype html
head
    title Pug
    script(type='text/javascript').
        if (foo) bar(1 + 5)
body
    h1 Pug - node template engine
    #container.col
        p You are amazing
        p Pug is a terse and simple templating language.

(Credit to https://html-to-pug.com/)

Your Environment

WebStorm 2020.3.2
Build #WS-203.7148.54, built on January 25, 2021
Licensed to Connor McCormick
Subscription is active until April 15, 2021.
Runtime version: 11.0.9.1+11-b1145.77 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1007M
Cores: 2
Non-Bundled Plugins: String Manipulation, com.andrey4623.rainbowcsv, com.microsoft.vso.idea, zielu.gittoolbox, mobi.hsz.idea.gitignore, com.jetbrains.codeWithMe, tv.twelvetone.intellij.plugins.intellivue, com.intellij.lang.jsgraphql, izhangzhihao.rainbow.brackets, ru.adelf.idea.dotenv
izhangzhihao commented 3 years ago

image

What is your expectation exactly?

CS-Birb commented 3 years ago

Sorry for the poor explanation in my initial feature request.

The HTML equivalent for this pug code would be as follows (w/ Rainbowified Tag Names): image

While the pug side is unsupported and nested elements are ignored. image

My hope is that Pug can be supported to achieve an output like the following: image (Apologies for the rough image manipulation)

izhangzhihao commented 3 years ago
XmlFile:Dummy.pug(0,255)
  PsiElement(DOCUMENT)(0,255)
    PsiElement(XML_DOCTYPE)(0,12)
      PsiElement(DOCTYPE_KEYWORD)('doctype')(0,7)
      XmlText(7,12)
        PsiWhiteSpace(' ')(7,8)
        XmlToken:XML_DATA_CHARACTERS('html')(8,12)
    PsiElement(EOL)('\n')(12,13)
    JadeTagImpl(TAG)(13,95)
      XmlToken:XML_TAG_NAME('head')(13,17)
      PsiElement(INDENT)('\n    ')(17,22)
      JadeTagImpl(TAG)(22,31)
        XmlToken:XML_TAG_NAME('title')(22,27)
        XmlText(27,31)
          PsiWhiteSpace(' ')(27,28)
          XmlToken:XML_DATA_CHARACTERS('Pug')(28,31)
      PsiElement(INDENT)('\n    ')(31,36)
      JadeTagImpl(TAG)(36,95)
        XmlToken:XML_TAG_NAME('script')(36,42)
        PsiElement(LPAREN)('(')(42,43)
        PsiElement(JADE_PSEUDO_WHITESPACE)(43,43)
          <empty list>
        JadeAttributeImpl(XML_ATTRIBUTE)(43,65)
          XmlToken:XML_NAME('type')(43,47)
          PsiElement(EQ)('=')(47,48)
          PsiElement(XML_ATTRIBUTE_VALUE)(48,65)
            JSInJadeEmbeddedContentImpl:EMBEDDED_EXPRESSION(48,65)
              JSLiteralExpression(48,65)
                PsiElement(JS:STRING_LITERAL)(''text/javascript'')(48,65)
        PsiElement(RPAREN)(')')(65,66)
        PsiElement(DOT)('.')(66,67)
        PsiElement(INDENT)('\n        ')(67,76)
        PsiElement(BLOCK)(76,95)
          JSInJadeEmbeddedContentImpl:JADE_EMBEDDED_WRAPPER: EMBEDDED_CONTENT(76,95)
            JSIfStatement(76,95)
              PsiElement(JS:IF_KEYWORD)('if')(76,78)
              PsiWhiteSpace(' ')(78,79)
              PsiElement(JS:LPAR)('(')(79,80)
              JSReferenceExpression(80,83)
                PsiElement(JS:IDENTIFIER)('foo')(80,83)
              PsiElement(JS:RPAR)(')')(83,84)
              PsiWhiteSpace(' ')(84,85)
              JSExpressionStatement(85,95)
                JSCallExpression(85,95)
                  JSReferenceExpression(85,88)
                    PsiElement(JS:IDENTIFIER)('bar')(85,88)
                  JSArgumentList(88,95)
                    PsiElement(JS:LPAR)('(')(88,89)
                    JSBinaryExpression(89,94)
                      JSLiteralExpression(89,90)
                        PsiElement(JS:NUMERIC_LITERAL)('1')(89,90)
                      PsiWhiteSpace(' ')(90,91)
                      PsiElement(JS:PLUS)('+')(91,92)
                      PsiWhiteSpace(' ')(92,93)
                      JSLiteralExpression(93,94)
                        PsiElement(JS:NUMERIC_LITERAL)('5')(93,94)
                    PsiElement(JS:RPAR)(')')(94,95)
    PsiElement(EOL)('\n')(95,96)
    JadeTagImpl(TAG)(96,255)
      XmlToken:XML_TAG_NAME('body')(96,100)
      PsiElement(INDENT)('\n    ')(100,105)
      JadeTagImpl(TAG)(105,134)
        XmlToken:XML_TAG_NAME('h1')(105,107)
        XmlText(107,134)
          PsiWhiteSpace(' ')(107,108)
          XmlToken:XML_DATA_CHARACTERS('Pug')(108,111)
          PsiWhiteSpace(' ')(111,112)
          XmlToken:XML_DATA_CHARACTERS('-')(112,113)
          PsiWhiteSpace(' ')(113,114)
          XmlToken:XML_DATA_CHARACTERS('node')(114,118)
          PsiWhiteSpace(' ')(118,119)
          XmlToken:XML_DATA_CHARACTERS('template')(119,127)
          PsiWhiteSpace(' ')(127,128)
          XmlToken:XML_DATA_CHARACTERS('engine')(128,134)
      PsiElement(INDENT)('\n    ')(134,139)
      JadeTagImpl(TAG)(139,255)
        JadeAttributeImpl(XML_ATTRIBUTE)(139,149)
          PsiElement(XML_NAME)(139,139)
            <empty list>
          PsiElement(XML_ATTRIBUTE_VALUE)(139,149)
            JadeTagIdImpl(TAG_ID)('#container')(139,149)
        JadeAttributeImpl(XML_ATTRIBUTE)(149,153)
          PsiElement(XML_NAME)(149,149)
            <empty list>
          PsiElement(XML_ATTRIBUTE_VALUE)(149,153)
            JadeClassImpl(CLASS)(149,153)
              PsiElement(DOT)('.')(149,150)
              JadeClassNameImpl(TAG_CLASS)('col')(150,153)
        PsiElement(INDENT)('\n        ')(153,162)
        JadeTagImpl(TAG)(162,179)
          XmlToken:XML_TAG_NAME('p')(162,163)
          XmlText(163,179)
            PsiWhiteSpace(' ')(163,164)
            XmlToken:XML_DATA_CHARACTERS('You')(164,167)
            PsiWhiteSpace(' ')(167,168)
            XmlToken:XML_DATA_CHARACTERS('are')(168,171)
            PsiWhiteSpace(' ')(171,172)
            XmlToken:XML_DATA_CHARACTERS('amazing')(172,179)
        PsiElement(INDENT)('\n        ')(179,188)
        JadeTagImpl(TAG)(188,255)
          XmlToken:XML_TAG_NAME('p')(188,189)
          XmlText(189,236)
            PsiWhiteSpace(' ')(189,190)
            XmlToken:XML_DATA_CHARACTERS('Pug')(190,193)
            PsiWhiteSpace(' ')(193,194)
            XmlToken:XML_DATA_CHARACTERS('is')(194,196)
            PsiWhiteSpace(' ')(196,197)
            XmlToken:XML_DATA_CHARACTERS('a')(197,198)
            PsiWhiteSpace(' ')(198,199)
            XmlToken:XML_DATA_CHARACTERS('terse')(199,204)
            PsiWhiteSpace(' ')(204,205)
            XmlToken:XML_DATA_CHARACTERS('and')(205,208)
            PsiWhiteSpace(' ')(208,209)
            XmlToken:XML_DATA_CHARACTERS('simple')(209,215)
            PsiWhiteSpace(' ')(215,216)
            XmlToken:XML_DATA_CHARACTERS('templating')(216,226)
            PsiWhiteSpace(' ')(226,227)
            XmlToken:XML_DATA_CHARACTERS('language.')(227,236)
          PsiElement(INDENT)('\n            ')(236,249)
          JadeTagImpl(TAG)(249,255)
            XmlToken:XML_TAG_NAME('p')(249,250)
            XmlText(250,255)
              PsiWhiteSpace(' ')(250,251)
              XmlToken:XML_DATA_CHARACTERS('test')(251,255)

Very interesting PSI structure, the XmlToken:XML_TAG_NAME never closed, (sure that make sense for Pug lang), but is required a new implementation since current implementation only works for "paired" XmlToken:XML_TAG_NAME.

izhangzhihao commented 3 years ago

I guess that will make you happy, please support us if you like this plugin.

image