Merge pull request #7778 from atom/ns-mb-suppress-line-measurement-exceptions

Suppress line measurement exceptions and gather data to solve them
This commit is contained in:
Nathan Sobo
2015-07-08 12:43:55 -05:00
5 changed files with 41 additions and 23 deletions

View File

@@ -721,17 +721,12 @@ class Atom extends Model
Section: Private
###
assert: (condition, message, metadata) ->
assert: (condition, message, callback) ->
return true if condition
error = new Error("Assertion failed: #{message}")
Error.captureStackTrace(error, @assert)
if metadata?
if typeof metadata is 'function'
error.metadata = metadata()
else
error.metadata = metadata
callback?(error)
@emitter.emit 'did-fail-assertion', error

View File

@@ -346,17 +346,44 @@ class LinesTileComponent
rangeForMeasurement ?= document.createRange()
iterator = document.createNodeIterator(lineNode, NodeFilter.SHOW_TEXT, AcceptFilter)
textNode = iterator.nextNode()
textNodeLength = textNode.length
textNodeIndex = 0
nextTextNodeIndex = textNode.textContent.length
while nextTextNodeIndex <= charIndex
textNode = iterator.nextNode()
textNodeLength = textNode.length
textNodeIndex = nextTextNodeIndex
nextTextNodeIndex = textNodeIndex + textNode.textContent.length
i = charIndex - textNodeIndex
rangeForMeasurement.setStart(textNode, i)
rangeForMeasurement.setEnd(textNode, i + charLength)
if i + charLength <= textNodeLength
rangeForMeasurement.setEnd(textNode, i + charLength)
else
rangeForMeasurement.setEnd(textNode, textNodeLength)
atom.assert false, "Expected index to be less than the length of text node while measuring", (error) =>
editor = @presenter.model
screenRow = tokenizedLine.screenRow
bufferRow = editor.bufferRowForScreenRow(screenRow)
error.metadata = {
grammarScopeName: editor.getGrammar().scopeName
screenRow: screenRow
bufferRow: bufferRow
softWrapped: editor.isSoftWrapped()
softTabs: editor.getSoftTabs()
i: i
charLength: charLength
textNodeLength: textNode.length
}
error.privateMetadataDescription = "The contents of line #{bufferRow + 1}."
error.privateMetadata = {
lineText: editor.lineTextForBufferRow(bufferRow)
}
error.privateMetadataRequestName = "measured-line-text"
charWidth = rangeForMeasurement.getBoundingClientRect().width
@presenter.setScopedCharacterWidth(scopes, char, charWidth)

View File

@@ -296,10 +296,12 @@ class TokenizedBuffer extends Model
# undefined. This should paper over the problem but we want to figure out
# what is happening:
tokenizedLine = @tokenizedLineForRow(row)
atom.assert tokenizedLine?, "TokenizedLine is defined", =>
metadata:
atom.assert tokenizedLine?, "TokenizedLine is defined", (error) =>
error.metadata = {
row: row
rowCount: @tokenizedLines.length
}
return false unless tokenizedLine?
return false if @buffer.isRowBlank(row) or tokenizedLine.isComment()