From 5da5bf94b60b0fe8e61862db4c59fbf2a28ab16d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki & Nathan Sobo Date: Fri, 22 Feb 2013 14:24:43 -0700 Subject: [PATCH] Add 'editor:save-debug-snapshot' command. Closes #191. This saves the state of the rendered lines, the display buffer, the tokenized buffer, and the buffer to a file. If a problem arises with rendering, hopefully we can use it to diagnose in which layer things went awry. --- spec/app/editor-spec.coffee | 14 ++++++++++++++ src/app/buffer.coffee | 16 +++++++++++----- src/app/display-buffer.coffee | 6 ++++++ src/app/edit-session.coffee | 6 ++++++ src/app/editor.coffee | 34 ++++++++++++++++++++++++++------- src/app/tokenized-buffer.coffee | 6 ++++++ 6 files changed, 70 insertions(+), 12 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 1cb279da1..17c89d3d2 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2859,3 +2859,17 @@ describe "Editor", -> editor.trigger 'editor:undo-close-session' expect(editor.getPath()).toBe fixturesProject.resolve('sample.js') expect(editor.getActiveEditSessionIndex()).toBe 0 + + describe "editor:save-debug-snapshot", -> + it "saves the state of the rendered lines, the display buffer, and the buffer to a file of the user's choosing", -> + saveDialogCallback = null + spyOn(atom, 'showSaveDialog').andCallFake (callback) -> saveDialogCallback = callback + spyOn(fs, 'write') + + editor.trigger 'editor:save-debug-snapshot' + + expect(atom.showSaveDialog).toHaveBeenCalled() + saveDialogCallback('/tmp/state') + expect(fs.write).toHaveBeenCalled() + expect(fs.write.argsForCall[0][0]).toBe '/tmp/state' + expect(typeof fs.write.argsForCall[0][1]).toBe 'string' diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index 0200bddeb..0cf84f7a7 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -419,11 +419,6 @@ class Buffer return match[0][0] != '\t' undefined - logLines: (start=0, end=@getLastRow())-> - for row in [start..end] - line = @lineForRow(row) - console.log row, line, line.length - getRepo: -> @project?.repo checkoutHead: -> @@ -442,4 +437,15 @@ class Buffer fileExists: -> @file.exists() + logLines: (start=0, end=@getLastRow())-> + for row in [start..end] + line = @lineForRow(row) + console.log row, line, line.length + + getDebugSnapshot: -> + lines = ['Buffer:'] + for row in [0..@getLastRow()] + lines.push "#{row}: #{@lineForRow(row)}" + lines.join('\n') + _.extend(Buffer.prototype, EventEmitter) diff --git a/src/app/display-buffer.coffee b/src/app/display-buffer.coffee index 4abe7adcc..c029a1124 100644 --- a/src/app/display-buffer.coffee +++ b/src/app/display-buffer.coffee @@ -419,4 +419,10 @@ class DisplayBuffer logLines: (start, end) -> @lineMap.logLines(start, end) + getDebugSnapshot: -> + lines = ["Display Buffer:"] + for screenLine, row in @lineMap.linesForScreenRows(0, @getLastRow()) + lines.push "#{row}: #{screenLine.text}" + lines.join('\n') + _.extend DisplayBuffer.prototype, EventEmitter diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 77e8360f2..f2f9bbbe9 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -820,5 +820,11 @@ class EditSession @displayBuffer.tokenizedBuffer.resetScreenLines() grammarChanged + getDebugSnapshot: -> + [ + @displayBuffer.getDebugSnapshot() + @displayBuffer.tokenizedBuffer.getDebugSnapshot() + ].join('\n\n') + _.extend(EditSession.prototype, EventEmitter) _.extend(EditSession.prototype, Subscriber) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index c4fcf1bdb..74dcb6fb6 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -194,6 +194,7 @@ class Editor extends View 'editor:duplicate-line': @duplicateLine 'editor:undo-close-session': @undoDestroySession 'editor:toggle-indent-guide': => config.set('editor.showIndentGuide', !config.get('editor.showIndentGuide')) + 'editor:save-debug-snapshot': @saveDebugSnapshot documentation = {} for name, method of editorBindings @@ -1226,16 +1227,9 @@ class Editor extends View lineElementForScreenRow: (screenRow) -> @renderedLines.children(":eq(#{screenRow - @firstRenderedScreenRow})") - logScreenLines: (start, end) -> - @activeEditSession.logScreenLines(start, end) - toggleLineCommentsInSelection: -> @activeEditSession.toggleLineCommentsInSelection() - logRenderedLines: -> - @renderedLines.find('.line').each (n) -> - console.log n, $(this).text() - pixelPositionForBufferPosition: (position) -> @pixelPositionForScreenPosition(@screenPositionForBufferPosition(position)) @@ -1348,3 +1342,29 @@ class Editor extends View copyPathToPasteboard: -> path = @getPath() pasteboard.write(path) if path? + + saveDebugSnapshot: -> + atom.showSaveDialog (path) => + fs.write(path, @getDebugSnapshot()) if path + + getDebugSnapshot: -> + [ + "Debug Snapshot: #{@getPath()}" + @getRenderedLinesDebugSnapshot() + @activeEditSession.getDebugSnapshot() + @getBuffer().getDebugSnapshot() + ].join('\n\n') + + getRenderedLinesDebugSnapshot: -> + lines = ['Rendered Lines:'] + firstRenderedScreenRow = @firstRenderedScreenRow + @renderedLines.find('.line').each (n) -> + lines.push "#{firstRenderedScreenRow + n}: #{$(this).text()}" + lines.join('\n') + + logScreenLines: (start, end) -> + @activeEditSession.logScreenLines(start, end) + + logRenderedLines: -> + @renderedLines.find('.line').each (n) -> + console.log n, $(this).text() diff --git a/src/app/tokenized-buffer.coffee b/src/app/tokenized-buffer.coffee index 9e0930bf0..70e982e28 100644 --- a/src/app/tokenized-buffer.coffee +++ b/src/app/tokenized-buffer.coffee @@ -226,4 +226,10 @@ class TokenizedBuffer line = @lineForScreenRow(row).text console.log row, line, line.length + getDebugSnapshot: -> + lines = ["Tokenized Buffer:"] + for screenLine, row in @linesForScreenRows(0, @getLastRow()) + lines.push "#{row}: #{screenLine.text}" + lines.join('\n') + _.extend(TokenizedBuffer.prototype, EventEmitter)