tguichaoua
tguichaoua

Reputation: 173

vscode language configuration brackets definition : how to handle bracket in string?

I'm writing a VScode extensions to support a script language I'm developing. I try to enable brackets definition to support pair bracket colorization but when the bracket is inside a string it's not ignored :

enter image description here

How can I tell vscode to skip the string ?

The language-configuration.json file:

{
    "brackets": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
    ],
    "autoClosingPairs": [
        {
            "open": "{",
            "close": "}"
        },
        {
            "open": "[",
            "close": "]"
        },
        {
            "open": "(",
            "close": ")"
        },
        {
            "open": "'",
            "close": "'",
            "notIn": [
                "string",
                "comment"
            ]
        },
        {
            "open": "\"",
            "close": "\"",
            "notIn": [
                "string"
            ]
        },
        {
            "open": "`",
            "close": "`",
            "notIn": [
                "string",
                "comment"
            ]
        },
        {
            "open": "/**",
            "close": " */",
            "notIn": [
                "string"
            ]
        }
    ],
    "surroundingPairs": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
        ["'", "'"],
        ["\"", "\""],
        ["`", "`"]
    ],
}

Upvotes: 0

Views: 120

Answers (1)

tguichaoua
tguichaoua

Reputation: 173

I found out that even if the LSP adds semantics, I have to provide a grammar file to help vscode to identify strings.

{
  "scopeName": "source.X",
  "patterns": [{ "include": "#string" }],
  "repository": {
    "string": {
      "begin": "\\\"",
      "end": "\\\"",
      "name": "string"
    }
  }
}

Upvotes: 1

Related Questions