Skip to content

[Bug] LanguageConfiguration autoClosingPairs' notIn field doesn't work for variable/variable.source classes #5076

@aitee

Description

@aitee

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

My goal is to have angle brackets as an autoClosingPair, but make an exception for codeblocks which are assigned the variable/variable.source classes for inlineBlock and multiline blocks respectively.

When I use variable/variable.source, the notIn doesn't respect the configuration and still autoCloses the open angle bracket in either type of codeblock.

https://microsoft.github.io/monaco-editor/playground.html?source=v0.54.0#XQAAAAIlDgAAAAAAAABBqQkHQ5NjdMpUO-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWS9TrQEnwCvCN-gv0cF0ZCJVqIjHtiA5OyQlKfQfukwlA4-QciyrnHYKQZCNTk9qxuoMyPJJ3eDaKYsbOmofW1VrpCD9u_PvVtbJrtU8E8nBDRz0FkUt2jqE3qBWJZ9JkbhhNyGrTnrhphWOqL9qn7H8DtHmnhazdiLY03KKyxLVjPJv2eCTie9yFByxTeaSNBF6bvOX9W2pYy7dTUXb1NAk5c2cVweUi_6Rqfz0UTdvAGtf0ARXA2lcJk9MMQrgfpO0JyOkiVRUgQPybwiFcbI_7xMvyJBNYG7cvlD_i1AeJl3RMiIUtSAg3GhbqIX0qTOdJr4Sk-GxR2oJCI70D5dkzGmtGwbRpvEBjsacmhdU63f9N_0fPuNYhVqcFWrpvKSFVPtYKMf4tQ2-cS1NarnQCS9a2byDr7gPaOTU8ArCvyAHq-0ZWRGWdUwxxxH1he9k4dmFMurgzH7ZVRzVoVe_LhtW8L7jvyCmGB8qMFgS6LajlvvsLey38xvXfYHD_sBszleSOHitfbgrk3CgrobIvN5eeu3r1f0zushj3WcYaWeue-UZ7YjBPc7i1w4AppyLKMcXXUorYbzDSQ-HSjEiqI3o614HApm_hjRm34JRJ9O-amHkRxMdx5am3Mdwl9YW6yXwOpPll0Z7Hd9E_0ouEeeLUFOekSQ65BPRvPGxH3gW7Jx4MHUQo42uD5uL3xtN5OhrRs-GYb-veHoCI3c91ty4ZpxWER9RwYpFFOf_NFsZTaKKbY0evFs_ynGskleS3_hPdIBZtfMWyo_4tqucdPUWFs0RvRIhhkWWw1Re1HLpwOpXFEQXaBRVsCzs7wcJpFVApOd7rMHTUbCRin_O62G0mXycR6C3h5R7pSdrGEJndeb0_Efqh3fA3rstfuL0k4s7PHkjJAP-uaoe9uZmCNBEQDqV7gMGv6lWiEvmN8sZ20esxun1CKiN-lgljilfat1N1wJazfjrgpsJdIE6sLRPzIFLZjFdB4Y4v68h675V-eYQTQnwYGvhF4FW0or6VChsCIO8-GT7S1RvTL_0GePY8B5udO8eAePMEWIQNR4KEjvy0MF9HF_OPE7GgHNXJKE7DUqOXek7TvvhtbZvndVL2TxD401VgiJbrY0-dmrrs0Wgx7J1igcAK8bATazhWSMOHYjcKDufpEWSqGAvc7v0jPWCfglhkDHjNLhnbGGR9Par2fXGWSFYeekE-_3NS4diZsfMNXnltNoYjiF2hxmpd4MqhEgiqbkOKrBUZT_U6FNcNDLLjlv7oevbIPgdF7YfaO2o-1bfJdTMtW3ZAQZSsbCNQRJKwP_mSQifgwXhPfFoIvhiZvlkvE_cGORq5dggTwsP3qhSzkrKx8O1NrTk0pwLZHniML4Fhu2kJ743IlWHbQds2F5wrQIGepMvIRXmon-i9tVAYS2dXA0Goj86BfUfaqcEl_suNND8Op3-btGzp2rB8nmYNxiMOumPP6bh6nGBhuAFrK-xCpup4qfWZBjHVFySsbmyBfEUnmPtLY7jKMra2IHkcUeuX7ynEn4xen9kBnatwBygxGWvyk9JAD9yEoIReYe8Dz-D416D3R6RWM57W4utFvOBGoVyv1zohuGO5EGvGP1Ef9mhEntp8H3j9SHOZaSS_8RU2pK5rD8StHXLf8bBHmIhlW4CeKM4hIVBBooiKjTKjoCCIPXyteB1dq1_h1HrPXiwF4xrQ6We___dzBcs

Monaco Editor Playground Code

const conf = {
  comments: {
    blockComment: ["<!--", "-->"],
  },
  brackets: [
    ["{", "}"],
    ["[", "]"],
    ["(", ")"],
  ],
  autoClosingPairs: [
    { open: "{", close: "}" },
    { open: "[", close: "]" },
    { open: "(", close: ")" },
    { open: "`", close: "`", notIn: ["string", "comment"] },
    { open: "", close: "", notIn: ["string", "comment"] },
    { open: "<", close: ">", notIn: ["string", "variable", "variable.source"]  },
  ],
  surroundingPairs: [
    { open: "(", close: ")" },
    { open: "[", close: "]" },
    { open: "`", close: "`" },
  ],
  folding: {
    markers: {
      start: new RegExp("^\\s*<!--\\s*#?region\\b.*-->"),
      end: new RegExp("^\\s*<!--\\s*#?endregion\\b.*-->"),
    },
  },
  wordPattern: /(-?\d*\.\d\w*)|(#\w)/g,
}

const language = {
  defaultToken: "",
  tokenPostfix: ".md",

  // escape codes
  control: /[\\`*_\[\]{}()#+\-\.!]/,
  noncontrol: /[^\\`*_\[\]{}()#+\-\.!]/,
  escapes: /\\(?:@control)/,

  // escape codes for javascript/CSS strings
  jsescapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,

  // non matched elements
  empty: [
    "area",
    "base",
    "basefont",
    "br",
    "col",
    "frame",
    "hr",
    "img",
    "input",
    "isindex",
    "link",
    "meta",
    "param",
  ],

  tokenizer: {
    root: [

      // headers (with #)
      [/^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/, ["white", "keyword", "keyword", "keyword"]],

      // headers (with =)
      [/^\s*(=+|\-+)\s*$/, "keyword"],

      // headers (with ***)
      [/^\s*((\*[ ]?)+)\s*$/, "meta.separator"],

      // quote
      [/^\s*>+/, "comment"],

      // list (starting with * or number)
      [/^\s*([\*\-+:]|\d+\.)\s/, "keyword"],

      // code block (4 spaces indent)
      [/^(\t|[ ]{4})[^ ].*$/, "string"],

      // code block (3 tilde)
      [/^\s*~~~\s*((?:\w|[\/\-#])+)?\s*$/, { token: "string", next: "@codeblock" }],

      // footnote reference
      [/\[\^\d+\]/, "footnote-ref"],

      // footnote definition
      [/\[\^\d+\]:\s+(.*)$/gm, "footnote-def"],

      // github style code blocks (with backticks and language)
      [
        /^\s*\s*((?:\w|[\/\-#])+).*$/,
        { token: "string", next: "@codeblockgh", nextEmbedded: "$1" },
      ],

      // github style code blocks (with backticks but no language)
      [/^\s*\s*$/, { token: "string", next: "@codeblock" }],

      // markup within lines
      { include: "@linecontent" },
    ],

    codeblock: [
      [/^\s*~~~\s*$/, { token: "string", next: "@pop" }],
      [/^\s*\s*$/, { token: "string", next: "@pop" }],
      [/.*$/, "variable.source"],
    ],

    // github style code blocks
    codeblockgh: [
      [/\s*$/, { token: "string", next: "@pop", nextEmbedded: "@pop" }],
      [/[^`]+/, "variable.source"],
    ],

    linecontent: [
      // inline code blocks
      [/`([^`\\]|\\[`\\])*`/, "variable"],

    ],


    comment: [
      [/[^<\-]+/, "comment.content"],
      [/-->/, "comment", "@pop"],
      [/<!--/, "comment.content.invalid"],
      [/[<\-]/, "comment.content"],
    ],

  },
}

monaco.languages.setLanguageConfiguration("markdown", conf)
monaco.languages.setMonarchTokensProvider("markdown", language)

// // Hover on each property to see its docs!
const editor = monaco.editor.create(document.getElementById("container"), {
    value:"\n\n\n\n``",
	language: "markdown",
	automaticLayout: true,
});

Reproduction Steps

Type an open angle bracket (<) into the multiline and inline blocks.

Actual (Problematic) Behavior

The open angle bracket is auto closed.

Expected Behavior

Expected it to not auto close based on the notIn configuration of autoClosingPairs for the angle brackets.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions