mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
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.
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user