recognizer icon indicating copy to clipboard operation
recognizer copied to clipboard

Coffeescript support

Open vinz243 opened this issue 10 years ago • 17 comments

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

vinz243 avatar May 02 '14 16:05 vinz243

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.

equiet avatar May 02 '14 20:05 equiet

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

vinz243 avatar May 02 '14 21:05 vinz243

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

vinz243 avatar May 04 '14 18:05 vinz243

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:

  • Source is parsed and converted to AST using esprima
  • esprima also keeps original position of every node in AST
  • AST is then recursively traversed and modified to include log statements
  • escodegen then regenerates new code from the instrumented AST and replaces the original
  • a tracer snippet (tracer.js) is added to each file, which contains a unique identifier and definitions of all log functions
  • using TracerManager.js I connect to each tracer (each files has one) and regularly poll it for all saved logs

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).

equiet avatar May 04 '14 19:05 equiet

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

vinz243 avatar May 04 '14 21:05 vinz243

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()"
}

vinz243 avatar May 07 '14 19:05 vinz243

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

equiet avatar May 07 '14 21:05 equiet

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

vinz243 avatar May 08 '14 10:05 vinz243

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

vinz243 avatar May 13 '14 13:05 vinz243

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

equiet avatar May 13 '14 13:05 equiet

No in which file in which funtion

vinz243 avatar May 13 '14 14:05 vinz243

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.

equiet avatar May 14 '14 09:05 equiet

Thank you very much!

vinz243 avatar May 15 '14 17:05 vinz243

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

Anachron avatar May 26 '14 10:05 Anachron

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

vinz243 avatar May 26 '14 15:05 vinz243

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

equiet avatar May 29 '14 04:05 equiet

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

vinz243 avatar May 29 '14 09:05 vinz243