Is there a reasonable way to debug init.coffee plugin?


#1

While writing a plugin I tried to view variable values on certain steps. Tried console.log() but it didn’t show anything in the console and debugger doesn’t seem to do anything. Haven’t found anything suitable in the API docs.


#2

The problem is that the coding inside init.coffee only takes effect when you restart Atom. You can use ctrl-shift-f5.

Using the console works for me, though a type of watch-table would have been nice. If you share some code someone might propose some detailed help.

Would it help you if you could use Javascript instead of Coffeescript?


#3

ctrl-shift-f5 is what I generally do, yes. Here’s the code, you’d definitely find it familiar. it works fine as far as I can tell, but I’d like to be able to peek inside the variables:

atom.commands.add 'atom-text-editor', 'custom:process-report', ->

  editor = atom.workspace.getActiveTextEditor()

  regs=[] ; res=[]
  regs.push /""(?!;)/g           ; res.push "'" # double quotes to single
  regs.push /;"([A-Z])/g         ; res.push ';$1' # quoted descriptions
  regs.push /('|\.)"(;)/g        ; res.push '$1$2' # quoted descriptions - closing
  regs.push /\s#/g               ; res.push ';' # division after tracker
  regs.push /(\d):\s/g           ; res.push '$1;' # division after task number
  regs.push /Task;/g             ; res.push '"Tracker";"Number";"Topic";'  # additional fields after separation
  regs.push /(\n[A-Za-z\s]+;)/g  ; res.push '$1"";"";' # blank fields after name

  debugger;
  console.log(regs); # that does nothing. Doesn't display anything in the console at least.

  buffer=editor.getText()

  for i in [0..regs.length-1]
    buffer=buffer.replace(regs[i],res[i])

  editor.setText(buffer)

CoffeeScript is fine. I believe one should resort to js only in the most dire circumstances :slight_smile:


#4

This is unusual. Try adding something like console.log("Hello!") to the outermost indentation level and see if that displays.


#5

Hello.

Could you explain further - - what is the issue?

  • The influence of debugger - see red - code execution paused.
  • Console reports on array elements
  • Position of pause indicated in (?)source tracker
  • Watch indicates variables used (look out for expansion arrow)

Can you see the same situation?
Trigger functionality
(Development tools: ctrl-shift-i)


#6

So I was looking in the wrong place. And it works… almost:

The problem is - when I click either of debugger buttons to resume I get:

image

All the time.


#7

Hi.

Not a nice problem you have there. If I was in your shoes, I would have already had Notepad++ and Python add-in do the work instead of Atom.

My first instinct is to look at the first inside-function code line. I always use an escape routed call:

  return unless editor = atom.workspace.getActiveTextEditor()

Out of good-practice I recommend you use this.

The alternate would be:

  if !(editor = atom.workspace.getActiveTextEditor())
    console.log "Code aborted: No active editor found."
    return

I have no idea what your background is. I am putting down some ideas for fault-finding. Forgive me if this is not helpful for your level of experience.

What you need to do is to isolate the cause of the problem. That means getting rid of all outside influences that may effect the execution of the code.


  1. First use a small test text piece on your code.

  1. Next, test the piece I executed (see below). Is it possible for you to execute it without issue?
DETAIL
atom.commands.add 'atom-text-editor', 'custom:process-report', ->
  regs=[] ; res=[]
  regs.push /""(?!;)/g           ; res.push "'" # double quotes to single
  regs.push /;"([A-Z])/g         ; res.push ';$1' # quoted descriptions
  regs.push /('|\.)"(;)/g        ; res.push '$1$2' # quoted descriptions - closing
  regs.push /\s#/g               ; res.push ';' # division after tracker
  regs.push /(\d):\s/g           ; res.push '$1;' # division after task number
  regs.push /Task;/g             ; res.push '"Tracker";"Number";"Topic";'  # additional fields after separation
  regs.push /(\n[A-Za-z\s]+;)/g  ; res.push '$1"";"";' # blank fields after name

  debugger;
  console.log(regs); # that does nothing. Doesn't display anything in the console at least.

  1. Add in the lines excluding the for-loop:
    editor=...,
    buffer=..., and
    editor.setText(buffer)
  • First test with a small text sample.
  • Next use bigger actual sized sample.
  • Results?

  1. Lastly add the for-loop.
  • First test with a small text sample.
  • Next use bigger actual sized sample.
  • Lastly check with an “invalid” file.
  • Results?

What is your findings? Any ideas that sprang to mind?

Good luck.
dP


#8

Since I’m not trying to cram an enterprise-size app into init.coffee… what it does is actually fine, even with the crash - before the crash the debugger displays all the variables and works as intended as far as I can say. If no one else gets the same crash I would guess some package is interfering with the engine. Will check it out sometime on a vanilla atom.