microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.86k stars 29.51k forks source link

JSDoc Crash #34164

Closed NightfallAlicorn closed 7 years ago

NightfallAlicorn commented 7 years ago
Extension Author (truncated) Version
vscode-standardjs che 1.1.8
code-spell-checker str 1.3.9
vjass vas 0.0.8
const { EventEmitter } = require('events')

module.exports = class TelegramBot extends EventEmitter {
  /**
   * Create a Telegram bot.
   * @param {string} token - Bot token provided by BotFather.
   * @param {Object} [settings] - Optional settings.
   * @param {boolean} [settings.debug - Print getUpdate results in console.
   * @param {number} settings.number - Interval for each update check.
   */
  constructor (token, settings) {
    super()
  }
}

I'm currently following this guide on how to add optional JSDoc param with default value. http://usejsdoc.org/tags-param.html#parameters-with-properties


Steps to Reproduce:

  1. Place the cursor at the end of "* @param {boolean} [settings.debug".
  2. Then type =. Visual Studio Code hangs for like 10 seconds and then prompts to keep waiting or reopen the window.

Reproduces without extensions: Yes

NightfallAlicorn commented 7 years ago

The crash doesn't occur if the description "- Print getUpdate results in console." isn't already on the line.

mjbvz commented 7 years ago

Root cause seems to be this expression in the jsdoc grammar:

{
    "name": "variable.other.jsdoc",
    "match": "(?x)\n(\\[)\\s*\n[\\w$]+\n(?:\n  (?:\\[\\])?                                        # Foo[ ].bar properties within an array\n  \\.                                                # Foo.Bar namespaced parameter\n  [\\w$]+\n)*\n(?:\n  \\s*\n  (=)                                                # [foo=bar] Default parameter value\n  \\s*\n  (\n    # The inner regexes are to stop the match early at */ and to not stop at escaped quotes\n    (?:\n      \"(?:(?:\\*(?!/))|(?:\\\\(?!\"))|[^*\\\\])*?\" |  # [foo=\"bar\"] Double-quoted\n      '(?:(?:\\*(?!/))|(?:\\\\(?!'))|[^*\\\\])*?' |  # [foo='bar'] Single-quoted\n      \\[ (?:(?:\\*(?!/))|[^*])*? \\] |              # [foo=[1,2]] Array literal\n      (?:(?:\\*(?!/))|[^*])*?                        # Everything else\n    )*\n  )\n)?\n\\s*(?:(\\])((?:[^*\\s]|\\*[^\\s/])+)?|(?=\\*/))",
    "captures": {
        "1": {
            "name": "punctuation.definition.optional-value.begin.bracket.square.jsdoc"
        },
        "2": {
            "name": "keyword.operator.assignment.jsdoc"
        },
        "3": {
            "name": "source.embedded.js"
        },
        "4": {
            "name": "punctuation.definition.optional-value.end.bracket.square.jsdoc"
        },
        "5": {
            "name": "invalid.illegal.syntax.jsdoc"
        }
    },
    "begin": "\\[",
    "end": "\\]|(?=\\*/)",
    "patterns": [

    ]
}

I believe this expression is causing oniguruma to hang

mjbvz commented 7 years ago

Moved upstream to https://github.com/Microsoft/TypeScript-TmLanguage/issues/515 I have a PR out with a fix on that repo