Create a warning notification when buffer has a watch error

This commit is contained in:
Ben Ogle
2015-01-08 17:10:59 -08:00
parent 8435826e8a
commit b8efbedee1
2 changed files with 33 additions and 5 deletions

View File

@@ -51,6 +51,25 @@ describe "Project", ->
editor.saveAs(tempFile)
expect(atom.project.getPaths()[0]).toBe path.dirname(tempFile)
describe "when a watch error is thrown from the TextBuffer", ->
editor = null
beforeEach ->
waitsForPromise ->
atom.project.open(require.resolve('./fixtures/dir/a')).then (o) -> editor = o
it "creates a warning notification", ->
atom.notifications.onDidAddNotification noteSpy = jasmine.createSpy()
editor.buffer.emitter.emit 'will-throw-watch-error',
handle: jasmine.createSpy()
error: new Error('SomeError')
expect(noteSpy).toHaveBeenCalled()
notification = noteSpy.mostRecentCall.args[0]
expect(notification.getType()).toBe 'warning'
expect(notification.getDetail()).toBe 'SomeError'
describe ".open(path)", ->
[absolutePath, newBufferHandler] = []

View File

@@ -39,9 +39,7 @@ class Project extends Model
@emitter = new Emitter
@buffers ?= []
for buffer in @buffers
do (buffer) =>
buffer.onDidDestroy => @removeBuffer(buffer)
@subscribeToBuffer(buffer) for buffer in @buffers
Grim.deprecate("Pass 'paths' array instead of 'path' to project constructor") if path?
paths ?= _.compact([path])
@@ -297,11 +295,11 @@ class Project extends Model
addBuffer: (buffer, options={}) ->
@addBufferAtIndex(buffer, @buffers.length, options)
buffer.onDidDestroy => @removeBuffer(buffer)
@subscribeToBuffer(buffer)
addBufferAtIndex: (buffer, index, options={}) ->
@buffers.splice(index, 0, buffer)
buffer.onDidDestroy => @removeBuffer(buffer)
@subscribeToBuffer(buffer)
@emit 'buffer-created', buffer
buffer
@@ -330,6 +328,17 @@ class Project extends Model
else
@on 'buffer-created', (buffer) -> callback(buffer)
subscribeToBuffer: (buffer) ->
buffer.onDidDestroy => @removeBuffer(buffer)
buffer.onWillThrowWatchError ({error, handle}) =>
handle()
atom.notifications.addWarning """
Unable to read file after file change event.
Make sure you have permission to access the file.
""",
detail: error.message
dismissable: true
# Deprecated: delegate
registerOpener: (opener) ->
deprecate("Use Workspace::addOpener instead")