Don’t use atom.assert global in DisplayBuffer

This commit is contained in:
Nathan Sobo
2015-10-03 09:19:46 -06:00
parent edd666b845
commit dc0709ef9e
8 changed files with 36 additions and 22 deletions

View File

@@ -175,7 +175,8 @@ class Atom extends Model
@workspace = new Workspace({
@config, @project, packageManager: @packages, grammarRegistry: @grammars,
notificationManager: @notifications, setRepresentedFilename: @setRepresentedFilename.bind(this),
setDocumentEdited: @setDocumentEdited.bind(this), @clipboard, viewRegistry: @views
setDocumentEdited: @setDocumentEdited.bind(this), @clipboard, viewRegistry: @views,
assert: @assert.bind(this)
})
@themes.workspace = @workspace

View File

@@ -30,9 +30,10 @@ class DisplayBuffer extends Model
@deserialize: (state, atomEnvironment) ->
state.tokenizedBuffer = TokenizedBuffer.deserialize(state.tokenizedBuffer)
state.config = atomEnvironment.config
state.assert = atomEnvironment.assert
new this(state)
constructor: ({tabLength, @editorWidthInChars, @tokenizedBuffer, buffer, ignoreInvisibles, @largeFileMode, @config}={}) ->
constructor: ({tabLength, @editorWidthInChars, @tokenizedBuffer, buffer, ignoreInvisibles, @largeFileMode, @config, @assert}={}) ->
super
@emitter = new Emitter
@@ -99,7 +100,9 @@ class DisplayBuffer extends Model
largeFileMode: @largeFileMode
copy: ->
newDisplayBuffer = new DisplayBuffer({@buffer, tabLength: @getTabLength(), @largeFileMode, @config})
newDisplayBuffer = new DisplayBuffer({
@buffer, tabLength: @getTabLength(), @largeFileMode, @config, @assert
})
for marker in @findMarkers(displayBufferId: @id)
marker.copy(displayBufferId: newDisplayBuffer.id)
@@ -1067,8 +1070,8 @@ class DisplayBuffer extends Model
tokenizedLinesCount = @tokenizedBuffer.getLineCount()
bufferLinesCount = @buffer.getLineCount()
atom.assert screenLinesCount is tokenizedLinesCount, "Display buffer line count out of sync with tokenized buffer", (error) ->
@assert screenLinesCount is tokenizedLinesCount, "Display buffer line count out of sync with tokenized buffer", (error) ->
error.metadata = {screenLinesCount, tokenizedLinesCount, bufferLinesCount}
atom.assert screenLinesCount is bufferLinesCount, "Display buffer line count out of sync with buffer", (error) ->
@assert screenLinesCount is bufferLinesCount, "Display buffer line count out of sync with buffer", (error) ->
error.metadata = {screenLinesCount, tokenizedLinesCount, bufferLinesCount}

View File

@@ -79,6 +79,7 @@ class TextEditor extends Model
state.clipboard = atomEnvironment.clipboard
state.viewRegistry = atomEnvironment.views
state.project = atomEnvironment.project
state.assert = atomEnvironment.assert.bind(atomEnvironment)
new this(state)
constructor: (params={}) ->
@@ -88,7 +89,7 @@ class TextEditor extends Model
@softTabs, @scrollRow, @scrollColumn, initialLine, initialColumn, tabLength,
softWrapped, @displayBuffer, buffer, suppressCursorCreation, @mini, @placeholderText,
lineNumberGutterVisible, largeFileMode, @config, @notificationManager, @clipboard,
@viewRegistry, @project
@viewRegistry, @project, @assert
} = params
throw new Error("Must pass a config parameter when constructing TextEditors") unless @config?
@@ -96,6 +97,7 @@ class TextEditor extends Model
throw new Error("Must pass a clipboard parameter when constructing TextEditors") unless @clipboard?
throw new Error("Must pass a viewRegistry parameter when constructing TextEditors") unless @viewRegistry?
throw new Error("Must pass a project parameter when constructing TextEditors") unless @project?
throw new Error("Must pass an assert parameter when constructing TextEditors") unless @assert?
@emitter = new Emitter
@disposables = new CompositeDisposable
@@ -103,7 +105,10 @@ class TextEditor extends Model
@selections = []
buffer ?= new TextBuffer
@displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrapped, ignoreInvisibles: @mini, largeFileMode, @config})
@displayBuffer ?= new DisplayBuffer({
buffer, tabLength, softWrapped, ignoreInvisibles: @mini, largeFileMode,
@config, @assert
})
@buffer = @displayBuffer.buffer
for marker in @findMarkers(@getSelectionMarkerAttributes())
@@ -470,7 +475,7 @@ class TextEditor extends Model
softTabs = @getSoftTabs()
newEditor = new TextEditor({
@buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true,
@config, @notificationManager, @clipboard, @viewRegistry, @project
@config, @notificationManager, @clipboard, @viewRegistry, @project, @assert
})
for marker in @findMarkers(editorId: @id)
marker.copy(editorId: newEditor.id, preserveFolds: true)

View File

@@ -21,7 +21,7 @@ class TokenizedBuffer extends Model
configSettings: null
changeCount: 0
@deserialize: (state) ->
@deserialize: (state, atomEnvironment) ->
state.buffer = atom.project.bufferForPathSync(state.bufferPath)
new this(state)

View File

@@ -28,9 +28,11 @@ class Workspace extends Model
{
@packageManager, @config, @project, @grammarRegistry, @notificationManager,
@clipboard, @viewRegistry, @setRepresentedFilename, @setDocumentEdited
@clipboard, @viewRegistry, @setRepresentedFilename, @setDocumentEdited, @assert
} = params
debugger unless @assert?
@emitter = new Emitter
@openers = []
@destroyedItemURIs = []
@@ -458,7 +460,7 @@ class Workspace extends Model
@buildTextEditor(_.extend({buffer, largeFileMode}, options))
buildTextEditor: (params) ->
new TextEditor(_.extend({@config, @notificationManager, @clipboard, @viewRegistry, @project}, params))
new TextEditor(_.extend({@config, @notificationManager, @clipboard, @viewRegistry, @project, @assert}, params))
# Public: Asynchronously reopens the last-closed item's URI if it hasn't already been
# reopened.