Add 'Sync' to end of Project's synchronous open methods
Remove 'Async' from Project's asynchronous open methods
Esse commit está contido em:
@@ -31,7 +31,7 @@ describe "editor.", ->
|
||||
|
||||
describe "opening-buffers.", ->
|
||||
benchmark "300-line-file.", ->
|
||||
buffer = project.bufferForPath('medium.coffee')
|
||||
buffer = project.bufferForPathSync('medium.coffee')
|
||||
|
||||
describe "empty-file.", ->
|
||||
benchmark "insert-delete", ->
|
||||
|
||||
@@ -6,7 +6,7 @@ describe "DisplayBuffer", ->
|
||||
beforeEach ->
|
||||
tabLength = 2
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
buffer = project.bufferForPath('sample.js')
|
||||
buffer = project.bufferForPathSync('sample.js')
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength})
|
||||
changeHandler = jasmine.createSpy 'changeHandler'
|
||||
displayBuffer.on 'changed', changeHandler
|
||||
@@ -154,7 +154,7 @@ describe "DisplayBuffer", ->
|
||||
|
||||
describe "when a newline is inserted, deleted, and re-inserted at the end of a wrapped line (regression)", ->
|
||||
it "correctly renders the original wrapped line", ->
|
||||
buffer = project.buildBuffer(null, '')
|
||||
buffer = project.buildBufferSync(null, '')
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, editorWidthInChars: 30, softWrap: true})
|
||||
|
||||
buffer.insert([0, 0], "the quick brown fox jumps over the lazy dog.")
|
||||
@@ -206,7 +206,7 @@ describe "DisplayBuffer", ->
|
||||
beforeEach ->
|
||||
displayBuffer.destroy()
|
||||
buffer.release()
|
||||
buffer = project.bufferForPath('two-hundred.txt')
|
||||
buffer = project.bufferForPathSync('two-hundred.txt')
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength})
|
||||
displayBuffer.on 'changed', changeHandler
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ describe "Project replication", ->
|
||||
projectHome2 = path.join(__dirname, 'fixtures', 'replication', 'home-2')
|
||||
config.set('core.projectHome', projectHome1)
|
||||
project1 = new Project(path.join(projectHome1, 'project'))
|
||||
project1.bufferForPath('file-1.txt')
|
||||
project1.bufferForPath('file-1.txt')
|
||||
project1.bufferForPathSync('file-1.txt')
|
||||
project1.bufferForPathSync('file-1.txt')
|
||||
expect(project1.getBuffers().length).toBe 1
|
||||
|
||||
doc1 = project1.getState()
|
||||
@@ -39,13 +39,13 @@ describe "Project replication", ->
|
||||
expect(project2.getBuffers()[0].getPath()).not.toBe project1.getBuffers()[0].getPath()
|
||||
|
||||
it "replicates insertion and removal of open buffers", ->
|
||||
project2.bufferForPath('file-2.txt')
|
||||
project2.bufferForPathSync('file-2.txt')
|
||||
expect(project1.getBuffers().length).toBe 2
|
||||
expect(project2.getBuffers()[0].getRelativePath()).toBe project1.getBuffers()[0].getRelativePath()
|
||||
expect(project2.getBuffers()[1].getRelativePath()).toBe project1.getBuffers()[1].getRelativePath()
|
||||
expect(project2.getBuffers()[0].getRelativePath()).not.toBe project1.getBuffers()[0].getPath()
|
||||
expect(project2.getBuffers()[1].getRelativePath()).not.toBe project1.getBuffers()[1].getPath()
|
||||
|
||||
project1.removeBuffer(project1.bufferForPath('file-2.txt'))
|
||||
project1.removeBuffer(project1.bufferForPathSync('file-2.txt'))
|
||||
expect(project1.getBuffers().length).toBe 1
|
||||
expect(project2.getBuffers()[0].getRelativePath()).toBe project1.getBuffers()[0].getRelativePath()
|
||||
|
||||
@@ -17,7 +17,7 @@ describe "Project", ->
|
||||
deserializedProject?.destroy()
|
||||
|
||||
it "destroys unretained buffers and does not include them in the serialized state", ->
|
||||
project.bufferForPath('a')
|
||||
project.bufferForPathSync('a')
|
||||
expect(project.getBuffers().length).toBe 1
|
||||
deserializedProject = deserialize(project.serialize())
|
||||
expect(deserializedProject.getBuffers().length).toBe 0
|
||||
@@ -206,19 +206,19 @@ describe "Project", ->
|
||||
runs ->
|
||||
expect(totalBytes).toBe fs.statSync(filePath).size
|
||||
|
||||
describe ".bufferForPath(path)", ->
|
||||
describe ".bufferForPathSync(path)", ->
|
||||
describe "when opening a previously opened path", ->
|
||||
it "does not create a new buffer", ->
|
||||
buffer = project.bufferForPath("a").retain()
|
||||
expect(project.bufferForPath("a")).toBe buffer
|
||||
buffer = project.bufferForPathSync("a").retain()
|
||||
expect(project.bufferForPathSync("a")).toBe buffer
|
||||
|
||||
alternativeBuffer = project.bufferForPath("b").retain().release()
|
||||
alternativeBuffer = project.bufferForPathSync("b").retain().release()
|
||||
expect(alternativeBuffer).not.toBe buffer
|
||||
buffer.release()
|
||||
|
||||
it "creates a new buffer if the previous buffer was destroyed", ->
|
||||
buffer = project.bufferForPath("a").retain().release()
|
||||
expect(project.bufferForPath("a").retain().release()).not.toBe buffer
|
||||
buffer = project.bufferForPathSync("a").retain().release()
|
||||
expect(project.bufferForPathSync("a").retain().release()).not.toBe buffer
|
||||
|
||||
describe ".bufferForPathAsync(path)", ->
|
||||
[buffer] = []
|
||||
|
||||
@@ -4,7 +4,7 @@ describe "Selection", ->
|
||||
[buffer, editSession, selection] = []
|
||||
|
||||
beforeEach ->
|
||||
buffer = project.buildBuffer('sample.js')
|
||||
buffer = project.buildBufferSync('sample.js')
|
||||
editSession = new EditSession(buffer: buffer, tabLength: 2)
|
||||
selection = editSession.getSelection()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ describe "TextBuffer replication", ->
|
||||
[buffer1, buffer2] = []
|
||||
|
||||
beforeEach ->
|
||||
buffer1 = project.buildBuffer('sample.js')
|
||||
buffer1 = project.buildBufferSync('sample.js')
|
||||
buffer1.insert([0, 0], 'changed\n')
|
||||
doc1 = buffer1.getState()
|
||||
doc2 = doc1.clone(new Site(2))
|
||||
|
||||
@@ -9,7 +9,7 @@ describe 'TextBuffer', ->
|
||||
beforeEach ->
|
||||
filePath = require.resolve('./fixtures/sample.js')
|
||||
fileContents = fs.read(filePath)
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
|
||||
afterEach ->
|
||||
buffer?.release()
|
||||
@@ -23,12 +23,12 @@ describe 'TextBuffer', ->
|
||||
describe "when a file exists for the path", ->
|
||||
it "loads the contents of that file", ->
|
||||
filePath = require.resolve './fixtures/sample.txt'
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
expect(buffer.getText()).toBe fs.read(filePath)
|
||||
|
||||
it "does not allow the initial state of the buffer to be undone", ->
|
||||
filePath = require.resolve './fixtures/sample.txt'
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
buffer.undo()
|
||||
expect(buffer.getText()).toBe fs.read(filePath)
|
||||
|
||||
@@ -36,13 +36,13 @@ describe 'TextBuffer', ->
|
||||
it "is modified and is initially empty", ->
|
||||
filePath = "does-not-exist.txt"
|
||||
expect(fs.exists(filePath)).toBeFalsy()
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
expect(buffer.isModified()).toBeTruthy()
|
||||
expect(buffer.getText()).toBe ''
|
||||
|
||||
describe "when no path is given", ->
|
||||
it "creates an empty buffer", ->
|
||||
buffer = project.bufferForPath(null)
|
||||
buffer = project.bufferForPathSync(null)
|
||||
expect(buffer .getText()).toBe ""
|
||||
|
||||
describe "path-changed event", ->
|
||||
@@ -52,7 +52,7 @@ describe 'TextBuffer', ->
|
||||
filePath = path.join(__dirname, "fixtures", "atom-manipulate-me")
|
||||
newPath = "#{filePath}-i-moved"
|
||||
fs.writeSync(filePath, "")
|
||||
bufferToChange = project.bufferForPath(filePath)
|
||||
bufferToChange = project.bufferForPathSync(filePath)
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
bufferToChange.on 'path-changed', eventHandler
|
||||
|
||||
@@ -84,7 +84,7 @@ describe 'TextBuffer', ->
|
||||
buffer.release()
|
||||
filePath = temp.openSync('atom').path
|
||||
fs.writeSync(filePath, "first")
|
||||
buffer = project.bufferForPath(filePath).retain()
|
||||
buffer = project.bufferForPathSync(filePath).retain()
|
||||
|
||||
afterEach ->
|
||||
buffer.release()
|
||||
@@ -155,7 +155,7 @@ describe 'TextBuffer', ->
|
||||
beforeEach ->
|
||||
filePath = "/tmp/atom-file-to-delete.txt"
|
||||
fs.writeSync(filePath, 'delete me')
|
||||
bufferToDelete = project.bufferForPath(filePath)
|
||||
bufferToDelete = project.bufferForPathSync(filePath)
|
||||
filePath = bufferToDelete.getPath() # symlinks may have been converted
|
||||
|
||||
expect(bufferToDelete.getPath()).toBe filePath
|
||||
@@ -213,7 +213,7 @@ describe 'TextBuffer', ->
|
||||
buffer.release()
|
||||
filePath = "/tmp/atom-tmp-file"
|
||||
fs.writeSync(filePath, 'delete me')
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
@@ -226,7 +226,7 @@ describe 'TextBuffer', ->
|
||||
filePath = "/tmp/atom-tmp-file"
|
||||
fs.writeSync(filePath, '')
|
||||
buffer.release()
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
@@ -250,7 +250,7 @@ describe 'TextBuffer', ->
|
||||
filePath = "/tmp/atom-tmp-file"
|
||||
fs.writeSync(filePath, '')
|
||||
buffer.release()
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
@@ -274,7 +274,7 @@ describe 'TextBuffer', ->
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
expect(fs.exists(filePath)).toBeFalsy()
|
||||
buffer.release()
|
||||
buffer = project.bufferForPath(filePath)
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
@@ -297,12 +297,12 @@ describe 'TextBuffer', ->
|
||||
|
||||
it "returns false for an empty buffer with no path", ->
|
||||
buffer.release()
|
||||
buffer = project.bufferForPath(null)
|
||||
buffer = project.bufferForPathSync(null)
|
||||
expect(buffer.isModified()).toBeFalsy()
|
||||
|
||||
it "returns true for a non-empty buffer with no path", ->
|
||||
buffer.release()
|
||||
buffer = project.bufferForPath(null)
|
||||
buffer = project.bufferForPathSync(null)
|
||||
buffer.setText('a')
|
||||
expect(buffer.isModified()).toBeTruthy()
|
||||
buffer.setText('\n')
|
||||
@@ -452,7 +452,7 @@ describe 'TextBuffer', ->
|
||||
beforeEach ->
|
||||
filePath = '/tmp/temp.txt'
|
||||
fs.writeSync(filePath, "")
|
||||
saveBuffer = project.bufferForPath(filePath)
|
||||
saveBuffer = project.bufferForPathSync(filePath)
|
||||
saveBuffer.setText("blah")
|
||||
|
||||
it "saves the contents of the buffer to the path", ->
|
||||
@@ -486,7 +486,7 @@ describe 'TextBuffer', ->
|
||||
|
||||
describe "when the buffer has no path", ->
|
||||
it "throws an exception", ->
|
||||
saveBuffer = project.bufferForPath(null)
|
||||
saveBuffer = project.bufferForPathSync(null)
|
||||
saveBuffer.setText "hi"
|
||||
expect(-> saveBuffer.save()).toThrow()
|
||||
|
||||
@@ -510,7 +510,7 @@ describe 'TextBuffer', ->
|
||||
filePath = '/tmp/temp.txt'
|
||||
fs.remove filePath if fs.exists(filePath)
|
||||
|
||||
saveAsBuffer = project.bufferForPath(null).retain()
|
||||
saveAsBuffer = project.bufferForPathSync(null).retain()
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
saveAsBuffer.on 'path-changed', eventHandler
|
||||
|
||||
@@ -525,7 +525,7 @@ describe 'TextBuffer', ->
|
||||
newPath = "/tmp/new.txt"
|
||||
fs.writeSync(originalPath, "")
|
||||
|
||||
saveAsBuffer = project.bufferForPath(originalPath).retain()
|
||||
saveAsBuffer = project.bufferForPathSync(originalPath).retain()
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
saveAsBuffer.on 'changed', changeHandler
|
||||
saveAsBuffer.saveAs(newPath)
|
||||
@@ -547,7 +547,7 @@ describe 'TextBuffer', ->
|
||||
filePath = path.join(__dirname, "fixtures", "atom-manipulate-me")
|
||||
newPath = "#{filePath}-i-moved"
|
||||
fs.writeSync(filePath, "")
|
||||
bufferToChange = project.bufferForPath(filePath)
|
||||
bufferToChange = project.bufferForPathSync(filePath)
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
bufferToChange.on 'path-changed', eventHandler
|
||||
|
||||
@@ -948,7 +948,7 @@ describe 'TextBuffer', ->
|
||||
it "restores the previous unsaved state of the buffer", ->
|
||||
buffer.release()
|
||||
|
||||
buffer = project.bufferForPath()
|
||||
buffer = project.bufferForPathSync()
|
||||
buffer.setText("abc")
|
||||
|
||||
state = buffer.serialize()
|
||||
|
||||
@@ -20,7 +20,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
describe "@deserialize(state)", ->
|
||||
it "constructs a tokenized buffer with the same buffer and tabLength setting", ->
|
||||
buffer = project.bufferForPath('sample.js')
|
||||
buffer = project.bufferForPathSync('sample.js')
|
||||
tokenizedBuffer1 = new TokenizedBuffer(buffer: buffer, tabLength: 4)
|
||||
tokenizedBuffer2 = deserialize(tokenizedBuffer1.serialize())
|
||||
expect(tokenizedBuffer2.buffer).toBe tokenizedBuffer1.buffer
|
||||
@@ -28,7 +28,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
describe "when the buffer is destroyed", ->
|
||||
beforeEach ->
|
||||
buffer = project.bufferForPath('sample.js')
|
||||
buffer = project.bufferForPathSync('sample.js')
|
||||
tokenizedBuffer = new TokenizedBuffer({buffer})
|
||||
startTokenizing(tokenizedBuffer)
|
||||
|
||||
@@ -40,7 +40,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
describe "when the buffer contains soft-tabs", ->
|
||||
beforeEach ->
|
||||
buffer = project.bufferForPath('sample.js')
|
||||
buffer = project.bufferForPathSync('sample.js')
|
||||
tokenizedBuffer = new TokenizedBuffer({buffer})
|
||||
startTokenizing(tokenizedBuffer)
|
||||
tokenizedBuffer.on "changed", changeHandler = jasmine.createSpy('changeHandler')
|
||||
@@ -320,7 +320,7 @@ describe "TokenizedBuffer", ->
|
||||
describe "when the buffer contains hard-tabs", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('coffee-script-tmbundle', sync: true)
|
||||
buffer = project.bufferForPath('sample-with-tabs.coffee')
|
||||
buffer = project.bufferForPathSync('sample-with-tabs.coffee')
|
||||
tokenizedBuffer = new TokenizedBuffer({buffer})
|
||||
startTokenizing(tokenizedBuffer)
|
||||
|
||||
@@ -350,7 +350,7 @@ describe "TokenizedBuffer", ->
|
||||
describe "when the buffer contains surrogate pairs", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
buffer = project.buildBuffer 'sample-with-pairs.js', """
|
||||
buffer = project.buildBufferSync 'sample-with-pairs.js', """
|
||||
'abc\uD835\uDF97def'
|
||||
//\uD835\uDF97xyz
|
||||
"""
|
||||
@@ -389,7 +389,7 @@ describe "TokenizedBuffer", ->
|
||||
atom.activatePackage('ruby-tmbundle', sync: true)
|
||||
atom.activatePackage('ruby-on-rails-tmbundle', sync: true)
|
||||
|
||||
buffer = project.bufferForPath(null, "<div class='name'><%= User.find(2).full_name %></div>")
|
||||
buffer = project.bufferForPathSync(null, "<div class='name'><%= User.find(2).full_name %></div>")
|
||||
tokenizedBuffer = new TokenizedBuffer({buffer})
|
||||
tokenizedBuffer.setGrammar(syntax.selectGrammar('test.erb'))
|
||||
fullyTokenize(tokenizedBuffer)
|
||||
@@ -408,7 +408,7 @@ describe "TokenizedBuffer", ->
|
||||
buffer.release()
|
||||
|
||||
it "returns the correct token (regression)", ->
|
||||
buffer = project.bufferForPath('sample.js')
|
||||
buffer = project.bufferForPathSync('sample.js')
|
||||
tokenizedBuffer = new TokenizedBuffer({buffer})
|
||||
fullyTokenize(tokenizedBuffer)
|
||||
expect(tokenizedBuffer.tokenForPosition([1,0]).scopes).toEqual ["source.js"]
|
||||
@@ -417,7 +417,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
describe ".bufferRangeForScopeAtPosition(selector, position)", ->
|
||||
beforeEach ->
|
||||
buffer = project.bufferForPath('sample.js')
|
||||
buffer = project.bufferForPathSync('sample.js')
|
||||
tokenizedBuffer = new TokenizedBuffer({buffer})
|
||||
fullyTokenize(tokenizedBuffer)
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ class Project
|
||||
if resource
|
||||
Q(resource)
|
||||
else
|
||||
@bufferForPathAsync(filePath).then (buffer) =>
|
||||
@bufferForPath(filePath).then (buffer) =>
|
||||
@buildEditSessionForBuffer(buffer, options)
|
||||
|
||||
# Private: Only be used in specs
|
||||
@@ -194,7 +194,7 @@ class Project
|
||||
for opener in @openers
|
||||
return resource if resource = opener(filePath, options)
|
||||
|
||||
@buildEditSessionForBuffer(@bufferForPath(filePath), options)
|
||||
@buildEditSessionForBuffer(@bufferForPathSync(filePath), options)
|
||||
|
||||
# Public: Retrieves all {EditSession}s for all open files.
|
||||
#
|
||||
@@ -219,13 +219,13 @@ class Project
|
||||
new Array(@buffers...)
|
||||
|
||||
# Private: Only to be used in specs
|
||||
bufferForPath: (filePath, text) ->
|
||||
bufferForPathSync: (filePath, text) ->
|
||||
absoluteFilePath = @resolve(filePath)
|
||||
|
||||
if filePath
|
||||
existingBuffer = _.find @buffers, (buffer) -> buffer.getPath() == absoluteFilePath
|
||||
|
||||
existingBuffer ? @buildBuffer(absoluteFilePath, text)
|
||||
existingBuffer ? @buildBufferSync(absoluteFilePath, text)
|
||||
|
||||
# Private: Given a file path, this retrieves or creates a new {TextBuffer}.
|
||||
#
|
||||
@@ -236,19 +236,19 @@ class Project
|
||||
# text - The {String} text to use as a buffer, if the file doesn't have any contents
|
||||
#
|
||||
# Returns a promise that resolves to the {TextBuffer}.
|
||||
bufferForPathAsync: (filePath, text) ->
|
||||
bufferForPath: (filePath, text) ->
|
||||
absoluteFilePath = @resolve(filePath)
|
||||
if absoluteFilePath
|
||||
existingBuffer = _.find @buffers, (buffer) -> buffer.getPath() == absoluteFilePath
|
||||
|
||||
Q(existingBuffer ? @buildBufferAsync(absoluteFilePath, text))
|
||||
Q(existingBuffer ? @buildBuffer(absoluteFilePath, text))
|
||||
|
||||
# Private:
|
||||
bufferForId: (id) ->
|
||||
_.find @buffers, (buffer) -> buffer.id is id
|
||||
|
||||
# Private: DEPRECATED
|
||||
buildBuffer: (absoluteFilePath, initialText) ->
|
||||
buildBufferSync: (absoluteFilePath, initialText) ->
|
||||
buffer = new TextBuffer({project: this, filePath: absoluteFilePath, initialText})
|
||||
buffer.load()
|
||||
@addBuffer(buffer)
|
||||
@@ -260,7 +260,7 @@ class Project
|
||||
# text - The {String} text to use as a buffer
|
||||
#
|
||||
# Returns a promise that resolves to the {TextBuffer}.
|
||||
buildBufferAsync: (absoluteFilePath, initialText) ->
|
||||
buildBuffer: (absoluteFilePath, initialText) ->
|
||||
buffer = new TextBuffer({project: this, filePath: absoluteFilePath, initialText})
|
||||
buffer.loadAsync().then (buffer) =>
|
||||
@addBuffer(buffer)
|
||||
|
||||
@@ -32,7 +32,7 @@ class TokenizedBuffer
|
||||
@state = optionsOrState
|
||||
|
||||
# TODO: This needs to be made async, but should wait until the new Telepath changes land
|
||||
@buffer = project.bufferForPath(optionsOrState.get('bufferPath'))
|
||||
@buffer = project.bufferForPathSync(optionsOrState.get('bufferPath'))
|
||||
else
|
||||
{ @buffer, tabLength } = optionsOrState
|
||||
@state = site.createDocument
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário