annotate-extension icon indicating copy to clipboard operation
annotate-extension copied to clipboard

Use a Javascript parser instead of reqular expressions

Open Hopiu opened this issue 10 years ago • 6 comments

Hi David, Referring to #27 I think too, that the design of the extension should be rethought. As a first suggestion I'd like to propose to switch to a JS parser to identify functions (and possibly other things to annotate) instead of using regular expressions. Codemirror uses acorn.js anyway for code completion, so why not use it too to generate the jsdocs? What's you opinion on that?

As a start I wrote my first brackets plugin from scratch which uses acorn.js and can be found at: https://github.com/Hopiu/brackets-annotate-extension

(Of course I won't publish the plugin in the extension repo)

Hopiu avatar Apr 01 '14 08:04 Hopiu

I agree with Hopiu, acorn looks like it can make our lives easier. I would suggest to create an object like

function JSDocsObject (string) {
    //@constructor...    
}

JSDocsObject.prototype = {
//----------------------------------------------
//          PRIVATE METHODS
//----------------------------------------------
    _getReturnType : function() {...},
//----------------------------------------------
//          PUBLIC METHODS
//----------------------------------------------
    genJSDocs: function() {}
}

ajorquera avatar Apr 03 '14 18:04 ajorquera

I agree with you guys, regexps can only go so far. I have no experience with acorn though, and I'm just wondering if this isn't a bit oversized for the job. @Hopiu , from your experience, what do you think? Do you think it's suited, performance wise?

davidderaedt avatar Apr 03 '14 19:04 davidderaedt

Performance wise I think it's not a problem. If it's a bit oversized, ummm, maybe but still I think it's better to use a parser than regexps that will never understand the code.

@davidderaedt How about creating a new branch where we could start getting something together?

@ajorquera Let's use the coding guidelines from https://github.com/adobe/brackets/wiki/Brackets-Coding-Conventions


Generally, isn't there something like the CodeHintManager but targeting Docs? I mean, JS is not the only language that needs Documentation.

Hopiu avatar Apr 04 '14 08:04 Hopiu

Good question about the CodeHintManager, I'll try to investigate that. In the meantime, I'm creating the acorn branch. Not sure I'll have the time to actually code anything before a while though, so feel free to go crazy. ;)

davidderaedt avatar Apr 04 '14 08:04 davidderaedt

Sorry @Hopiu I don't quite understand the purpose of the link you sent me. I mean, it doesn't talk about coding conventions for creating objects. I just wanted for us to focus on creating them.

ajorquera avatar Apr 04 '14 09:04 ajorquera

@ajorquera Oh, sorry I got that wrong. It's absolutely fine for me creating such an object.

Hopiu avatar Apr 04 '14 15:04 Hopiu