atom / language-javascript

JavaScript language package for Atom
Other
193 stars 235 forks source link

Adding comments to JavaScript file causes Atom to hang. #26

Closed cbarrick closed 10 years ago

cbarrick commented 10 years ago

I'm on Atom 0.92.0 with Language Javascript 0.24.0. The issue doesn't happen with this plugin disabled. No logs in the dev console or Console.app that I can find.

There is a thread on the forums: http://discuss.atom.io/t/bug-adding-comment-to-javascript-file-crashes-atom/6786

Steps to reproduce:

  1. Take the source below.
  2. Put the cursor at the very beginning
  3. Press return
  4. Press up
  5. Press /

    Expected:

A "/" character should be entered on a new line at the top of the document

Actual:

Atom hangs.

Sample source:

/// The parser's job is to read some source and extract the markdown. The hard part of the parsing
/// is handled by a packrat parser generated from `grammar/docparser.peg`. This module wraps the
/// parser to provide a higher-level interface.

var docparser = require('../grammar/docparser');

docparser.Parser.DocBlock = {
    isDocBlock: true,

    // Extracts the markdown from the node.
    getDocs: function () {
        var docs = '';
        this.elements.forEach(function (line) {
            docs += line.docs.textValue;
        })
        return docs;
    }
}

/// `parse(source)`
/// --------------------------------------------------
/// **TODO**: Summary
///
/// ### Arguments
/// 1. `source` *(String)*: The source code to parse.
///
/// ### Returns
/// *(Array of Strings)*: The blocks of markdown documentation in the source.

exports.parse = function (source) {
    var ast = docparser.parse(source);
    var docs = [];
    ast.elements.forEach(function (block) {
        if (block.isDocBlock) {
            docs.push(block.getDocs());
        }
    })
    return docs;
}
ChrisJefferson commented 10 years ago

The bug is I believe an interaction between

"end": "(?!\\G)",

in "punctuation.whitespace.comment.leading.js".

and the 'punctuation.definition.string.begin.js' rule:

"begin": "(?<=[=(:]|^|return|&&|\\|\\||!)\\s*(/)(?![/*+{}?])"

As editing either of these seems to fix matters.

You can read http://textmate.1073791.n5.nabble.com/The-use-of-G-in-single-line-comments-td25933.html for a discussion of how this rule operates in textmate.

Now, I'm not really sure what these rules are doing to be honest

ChrisJefferson commented 10 years ago

Ignoring the fact that, as I say, I don't know what I'm doing, if I change the definition of punctuation.definition.string.begin.js begin from the current value to (so just changing the ?![ into ?=/[^), so:

   "begin": "(?<=[=(:]|^|return|&&|\\|\\||!)\\s*(/)(?=/[^/*+{}?])"

That seems to fix the problem. I copied that from textmate's current javascript bundle.

kevinsawicki commented 10 years ago

This looks to have been fixed by https://github.com/atom/language-javascript/commit/212b6ada88179ad41fcf9e4eba04ef6ce74eff31 so I'm going to close this out here, sorry for the delay, but it should be fixed in the latest Atom release, 0.125

baelter commented 9 years ago

I'm experiencing this on 0.178.0

Toggling comments via editor:toggle-line-comments works fine but adding or removing comments manually hangs atom. Only in js files.

50Wliu commented 9 years ago

Can you reproduce this in safe mode (atom --safe)?

baelter commented 9 years ago

No I can not reproduce in --safe. It is the compilation of suggestion list that hangs atom.

baelter commented 9 years ago

Sorry, not exclusive to javascript. Just observed the same bug in ruby.

izuzak commented 9 years ago

@baelter Sounds like a possible problem in autocomplete-plus (since you're not able to reproduce the problem in safe mode). Have you reported the issue over there as well? If so, can you add a link here for reference? Thanks.