equiet / recognizer

A concept for advanced developer tools
MIT License
375 stars 10 forks source link

Coffeescript support #4

Open vinz243 opened 10 years ago

vinz243 commented 10 years ago

Hi, I think your extsnion is really good and useful, but sadly I use CoffeeScript. Could you add CoffeeScript support some day ?

equiet commented 10 years ago

Hi. CoffeeScript support is definitely something I would like to add as I prefer CoffeeScript too. However, do not expect CoffeeScript support anytime soon. There are so many things on the roadmap that have higher priority and are also easier to do.

vinz243 commented 10 years ago

For the moment I am very busy but some time i'll try to send PR.

vinz243 commented 10 years ago

I am sorry for being stupid, but I don't know it works. Could you quickly explain in a 2 lines please?

equiet commented 10 years ago

I'm sorry, I probably won't fit this into 2 lines. The code is not stable yet and any kind of API is entirely missing. :/

In short, Recognizer reads JavaScript code from every file which is open (i.e. in a working set) in Brackets. Each file is instrumented separately using Instrumenter.js. It works like this:

CoffeeScript support is difficult for various reasons. You need to create an AST of CoffeeScript code. Each node in AST has to know its location in the original code. This is quite difficult, since CoffeeScript needs to be first compiled to JavaScript. AST then contains location of expressions in a JavaScript file. You would need to find way how to convert it back to CoffeeScript source, probably using source maps (but this still isn't 1:1 conversion and you would have to make).

vinz243 commented 10 years ago

OK thank you very much I will take a, look a this!

vinz243 commented 10 years ago

After some research CoffeescriptRedux can return an AST tree with line numbers. Example

foo() 

will give

{
  "body": {
    "statements": [{
      "function": {
        "data": "foo",
        "line": 1,
        "column": 1,
        "offset": 0,
        "raw": "foo"
      },
      "arguments": [],
      "raw": "foo()",
      "line": 1,
      "column": 1,
      "offset": 0
    }],
    "line": 1,
    "column": 1,
    "offset": 0,
    "raw": "foo()"
  },
  "line": 1,
  "column": 1,
  "offset": 0,
  "raw": "foo()"
}
equiet commented 10 years ago

Thanks, I wasn't aware of this. This could make CoffeeScript support significantly easier.

vinz243 commented 10 years ago

The only problem is that the AST tree given by CoffeescriptRedux and by esprima might not be structured equally.

vinz243 commented 10 years ago

I was wondering, where does it detect the value of a var?

equiet commented 10 years ago

In var foo = bar; only the right side is instrumented (var foo = logProbe(bar);) for now. Is that what you meant?

vinz243 commented 10 years ago

No in which file in which funtion

equiet commented 10 years ago

In TracedDocument.js in updateProbeValues I call a JavaScript runtime and retrieve the values of all probes in the file. The result is passed to insertProbes where I create the markers and tooltips one by one.

vinz243 commented 10 years ago

Thank you very much!

Anachron commented 10 years ago

How's it going here? I would love to see CoffeeScript support!

vinz243 commented 10 years ago

I can't run recognizer, I get [Recognizer] Error connecting to tracer in main.js

equiet commented 10 years ago

@Vinz243 I've just pushed the latest version to the Registry, could you please try it again?

vinz243 commented 10 years ago

It isnt in the registry, I just forked recognizer, then cloned it and add it (symlink) into the bracket extension folder (user). I am on win 7 32