From d36873f70217864508fe9a030254e1ae2f61b308 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 18 Jul 2012 11:19:25 -0700 Subject: [PATCH] Rename Project.open to Project.buildEditSessionForPath --- benchmark/benchmark-suite.coffee | 10 ++++-- spec/app/edit-session-spec.coffee | 4 +-- spec/app/editor-spec.coffee | 36 +++++++++---------- spec/app/project-spec.coffee | 18 +++++----- spec/app/root-view-spec.coffee | 8 ++--- spec/extensions/autocomplete-spec.coffee | 6 ++-- .../command-interpreter-spec.coffee | 4 +-- spec/extensions/fuzzy-finder-spec.coffee | 2 +- src/app/edit-session.coffee | 2 +- src/app/project.coffee | 3 +- src/app/root-view.coffee | 4 +-- 11 files changed, 51 insertions(+), 46 deletions(-) diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index 1c70248aa..db66ec394 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -17,6 +17,10 @@ describe "editor.", -> window.shutdown() delete atom.rootViewStates[$windowNumber] + describe "opening-buffers.", -> + benchmark "300-line-file.", -> + buffer = rootView.project.bufferForPath('medium.coffee') + describe "empty-file.", -> benchmark "insert-delete", -> editor.insertText('x') @@ -24,7 +28,7 @@ describe "editor.", -> describe "300-line-file.", -> beforeEach -> - editor.edit rootView.project.open('medium.coffee') + editor.edit rootView.project.buildEditSessionForPath('medium.coffee') describe "at-begining.", -> benchmark "insert-delete", -> @@ -45,11 +49,11 @@ describe "editor.", -> describe "9000-line-file.", -> benchmark "opening.", 5, -> - editor.edit rootView.project.open('huge.js') + editor.edit rootView.project.buildEditSessionForPath('huge.js') describe "after-opening.", -> beforeEach -> - editor.edit rootView.project.open('huge.js') + editor.edit rootView.project.buildEditSessionForPath('huge.js') benchmark "moving-to-eof.", 1, -> editor.moveCursorToBottom() diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index f2efa7d53..796c4905c 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -7,7 +7,7 @@ describe "EditSession", -> beforeEach -> buffer = new Buffer() - editSession = fixturesProject.open('sample.js', autoIndent: false) + editSession = fixturesProject.buildEditSessionForPath('sample.js', autoIndent: false) buffer = editSession.buffer lineLengths = buffer.getLines().map (line) -> line.length @@ -1319,7 +1319,7 @@ describe "EditSession", -> expect(editSession.getSelectedBufferRanges()).toEqual [[[1, 6], [1, 6]], [[1, 18], [1, 18]]] it "restores selected ranges even when the change occurred in another edit session", -> - otherEditSession = fixturesProject.open(editSession.getPath()) + otherEditSession = fixturesProject.buildEditSessionForPath(editSession.getPath()) otherEditSession.setSelectedBufferRange([[2, 2], [3, 3]]) otherEditSession.delete() diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 3bace9a2c..6600ca150 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -14,7 +14,7 @@ describe "Editor", -> getLineHeight = -> return cachedLineHeight if cachedLineHeight? - editorForMeasurement = new Editor(editSession: rootView.project.open('sample.js')) + editorForMeasurement = new Editor(editSession: rootView.project.buildEditSessionForPath('sample.js')) editorForMeasurement.attachToDom() cachedLineHeight = editorForMeasurement.lineHeight editorForMeasurement.remove() @@ -49,7 +49,7 @@ describe "Editor", -> rootView.height(8 * editor.lineHeight) rootView.width(50 * editor.charWidth) - editor.edit(rootView.project.open('two-hundred.txt')) + editor.edit(rootView.project.buildEditSessionForPath('two-hundred.txt')) editor.setCursorScreenPosition([5, 1]) editor.scrollTop(1.5 * editor.lineHeight) editor.scrollView.scrollLeft(44) @@ -113,7 +113,7 @@ describe "Editor", -> describe ".remove()", -> it "removes subscriptions from all edit session buffers", -> previousEditSession = editor.activeEditSession - otherEditSession = rootView.project.open(rootView.project.resolve('sample.txt')) + otherEditSession = rootView.project.buildEditSessionForPath(rootView.project.resolve('sample.txt')) expect(previousEditSession.buffer.subscriptionCount()).toBeGreaterThan 1 editor.edit(otherEditSession) @@ -125,7 +125,7 @@ describe "Editor", -> describe "when 'close' is triggered", -> it "closes active edit session and loads next edit session", -> - editor.edit(rootView.project.open()) + editor.edit(rootView.project.buildEditSessionForPath()) editSession = editor.activeEditSession spyOn(editSession, 'destroy').andCallThrough() spyOn(editor, "remove").andCallThrough() @@ -161,7 +161,7 @@ describe "Editor", -> otherEditSession = null beforeEach -> - otherEditSession = rootView.project.open() + otherEditSession = rootView.project.buildEditSessionForPath() describe "when the edit session wasn't previously assigned to this editor", -> it "adds edit session to editor", -> @@ -197,10 +197,10 @@ describe "Editor", -> beforeEach -> session0 = editor.activeEditSession - editor.edit(rootView.project.open('sample.txt')) + editor.edit(rootView.project.buildEditSessionForPath('sample.txt')) session1 = editor.activeEditSession - editor.edit(rootView.project.open('two-hundred.txt')) + editor.edit(rootView.project.buildEditSessionForPath('two-hundred.txt')) session2 = editor.activeEditSession describe ".setActiveEditSessionIndex(index)", -> @@ -277,7 +277,7 @@ describe "Editor", -> describe "when the current buffer has no path", -> selectedFilePath = null beforeEach -> - editor.edit(rootView.project.open()) + editor.edit(rootView.project.buildEditSessionForPath()) expect(editor.getPath()).toBeUndefined() editor.getBuffer().setText 'Save me to a new path' @@ -357,7 +357,7 @@ describe "Editor", -> spyOn(editor, 'pane').andReturn(fakePane) it "calls the corresponding split method on the containing pane with a new editor containing a copy of the active edit session", -> - editor.edit project.open("sample.txt") + editor.edit project.buildEditSessionForPath("sample.txt") editor.splitUp() expect(fakePane.splitUp).toHaveBeenCalled() [newEditor] = fakePane.splitUp.argsForCall[0] @@ -404,7 +404,7 @@ describe "Editor", -> it "emits event when editor receives a new buffer", -> eventHandler = jasmine.createSpy('eventHandler') editor.on 'editor-path-change', eventHandler - editor.edit(rootView.project.open(path)) + editor.edit(rootView.project.buildEditSessionForPath(path)) expect(eventHandler).toHaveBeenCalled() it "stops listening to events on previously set buffers", -> @@ -412,7 +412,7 @@ describe "Editor", -> oldBuffer = editor.getBuffer() editor.on 'editor-path-change', eventHandler - editor.edit(rootView.project.open(path)) + editor.edit(rootView.project.buildEditSessionForPath(path)) expect(eventHandler).toHaveBeenCalled() eventHandler.reset() @@ -1010,7 +1010,7 @@ describe "Editor", -> expect(editor.bufferPositionForScreenPosition(editor.getCursorScreenPosition())).toEqual [3, 60] it "does not wrap the lines of any newly assigned buffers", -> - otherEditSession = rootView.project.open() + otherEditSession = rootView.project.buildEditSessionForPath() otherEditSession.buffer.setText([1..100].join('')) editor.edit(otherEditSession) expect(editor.renderedLines.find('.line').length).toBe(1) @@ -1046,7 +1046,7 @@ describe "Editor", -> expect(editor.getCursorScreenPosition()).toEqual [11, 0] it "calls .setSoftWrapColumn() when the editor is attached because now its dimensions are available to calculate it", -> - otherEditor = new Editor(editSession: rootView.project.open('sample.js')) + otherEditor = new Editor(editSession: rootView.project.buildEditSessionForPath('sample.js')) spyOn(otherEditor, 'setSoftWrapColumn') otherEditor.setSoftWrap(true) @@ -1344,7 +1344,7 @@ describe "Editor", -> describe "when autoscrolling at the end of the document", -> it "renders lines properly", -> - editor.edit(rootView.project.open('two-hundred.txt')) + editor.edit(rootView.project.buildEditSessionForPath('two-hundred.txt')) editor.attachToDom(heightInLines: 5.5) expect(editor.renderedLines.find('.line').length).toBe 8 @@ -1510,7 +1510,7 @@ describe "Editor", -> describe "folding", -> beforeEach -> - editSession = rootView.project.open('two-hundred.txt') + editSession = rootView.project.buildEditSessionForPath('two-hundred.txt') buffer = editSession.buffer editor.edit(editSession) editor.attachToDom() @@ -1593,8 +1593,8 @@ describe "Editor", -> describe ".getOpenBufferPaths()", -> it "returns the paths of all non-anonymous buffers with edit sessions on this editor", -> - editor.edit(project.open('sample.txt')) - editor.edit(project.open('two-hundred.txt')) - editor.edit(project.open()) + editor.edit(project.buildEditSessionForPath('sample.txt')) + editor.edit(project.buildEditSessionForPath('two-hundred.txt')) + editor.edit(project.buildEditSessionForPath()) paths = editor.getOpenBufferPaths().map (path) -> project.relativize(path) expect(paths).toEqual = ['sample.js', 'sample.txt', 'two-hundred.txt'] diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index 8f3a13e0e..19d0f97eb 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -11,8 +11,8 @@ describe "Project", -> describe "when editSession is destroyed", -> it "removes edit session and calls destroy on buffer (if buffer is not referenced by other edit sessions)", -> - editSession = project.open("a") - anotherEditSession = project.open("a") + editSession = project.buildEditSessionForPath("a") + anotherEditSession = project.buildEditSessionForPath("a") buffer = editSession.buffer spyOn(buffer, 'destroy').andCallThrough() @@ -27,7 +27,7 @@ describe "Project", -> expect(buffer.destroy).toHaveBeenCalled() expect(project.editSessions.length).toBe 0 - describe ".open(path)", -> + describe ".buildEditSessionForPath(path)", -> [absolutePath, newBufferHandler, newEditSessionHandler] = [] beforeEach -> absolutePath = require.resolve('fixtures/dir/a') @@ -38,30 +38,30 @@ describe "Project", -> describe "when given an absolute path that hasn't been opened previously", -> it "returns a new edit session for the given path and emits 'new-buffer' and 'new-edit-session' events", -> - editSession = project.open(absolutePath) + editSession = project.buildEditSessionForPath(absolutePath) expect(editSession.buffer.getPath()).toBe absolutePath expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer expect(newEditSessionHandler).toHaveBeenCalledWith editSession describe "when given a relative path that hasn't been opened previously", -> it "returns a new edit session for the given path (relative to the project root) and emits 'new-buffer' and 'new-edit-session' events", -> - editSession = project.open('a') + editSession = project.buildEditSessionForPath('a') expect(editSession.buffer.getPath()).toBe absolutePath expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer expect(newEditSessionHandler).toHaveBeenCalledWith editSession describe "when passed the path to a buffer that has already been opened", -> it "returns a new edit session containing previously opened buffer and emits a 'new-edit-session' event", -> - editSession = project.open(absolutePath) + editSession = project.buildEditSessionForPath(absolutePath) newBufferHandler.reset() - expect(project.open(absolutePath).buffer).toBe editSession.buffer - expect(project.open('a').buffer).toBe editSession.buffer + expect(project.buildEditSessionForPath(absolutePath).buffer).toBe editSession.buffer + expect(project.buildEditSessionForPath('a').buffer).toBe editSession.buffer expect(newBufferHandler).not.toHaveBeenCalled() expect(newEditSessionHandler).toHaveBeenCalledWith editSession describe "when not passed a path", -> it "returns a new edit session and emits 'new-buffer' and 'new-edit-session' events", -> - editSession = project.open() + editSession = project.buildEditSessionForPath() expect(editSession.buffer.getPath()).toBeUndefined() expect(newBufferHandler).toHaveBeenCalledWith(editSession.buffer) expect(newEditSessionHandler).toHaveBeenCalledWith editSession diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 5bf2e5b80..ca5f85302 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -75,10 +75,10 @@ describe "RootView", -> editor2 = editor1.splitRight() editor3 = editor2.splitRight() editor4 = editor2.splitDown() - editor2.edit(rootView.project.open('dir/b')) - editor3.edit(rootView.project.open('sample.js')) + editor2.edit(rootView.project.buildEditSessionForPath('dir/b')) + editor3.edit(rootView.project.buildEditSessionForPath('sample.js')) editor3.setCursorScreenPosition([2, 3]) - editor4.edit(rootView.project.open('sample.txt')) + editor4.edit(rootView.project.buildEditSessionForPath('sample.txt')) editor4.setCursorScreenPosition([0, 2]) rootView.attachToDom() editor2.focus() @@ -455,7 +455,7 @@ describe "RootView", -> editor2 = rootView.getActiveEditor().splitLeft() path = rootView.project.resolve('b') - editor2.edit(rootView.project.open(path)) + editor2.edit(rootView.project.buildEditSessionForPath(path)) expect(pathChangeHandler).toHaveBeenCalled() expect(document.title).toBe rootView.project.resolve(path) diff --git a/spec/extensions/autocomplete-spec.coffee b/spec/extensions/autocomplete-spec.coffee index 5e865c8b1..cb8c6585a 100644 --- a/spec/extensions/autocomplete-spec.coffee +++ b/spec/extensions/autocomplete-spec.coffee @@ -10,7 +10,7 @@ describe "Autocomplete", -> miniEditor = null beforeEach -> - editor = new Editor(editSession: fixturesProject.open('sample.js')) + editor = new Editor(editSession: fixturesProject.buildEditSessionForPath('sample.js')) autocomplete = new Autocomplete(editor) miniEditor = autocomplete.miniEditor @@ -357,7 +357,7 @@ describe "Autocomplete", -> expect(wordList).toContain "quicksort" expect(wordList).not.toContain "Some" - editor.edit(fixturesProject.open('sample.txt')) + editor.edit(fixturesProject.buildEditSessionForPath('sample.txt')) wordList = autocomplete.wordList expect(wordList).not.toContain "quicksort" @@ -365,7 +365,7 @@ describe "Autocomplete", -> it 'stops listening to previous buffers change events', -> previousBuffer = editor.getBuffer() - editor.edit(fixturesProject.open('sample.txt')) + editor.edit(fixturesProject.buildEditSessionForPath('sample.txt')) spyOn(autocomplete, "buildWordList") previousBuffer.change([[0,0],[0,1]], "sauron") diff --git a/spec/extensions/command-interpreter-spec.coffee b/spec/extensions/command-interpreter-spec.coffee index 414948c4c..143f64754 100644 --- a/spec/extensions/command-interpreter-spec.coffee +++ b/spec/extensions/command-interpreter-spec.coffee @@ -9,7 +9,7 @@ describe "CommandInterpreter", -> beforeEach -> project = new Project(fixturesProject.resolve('dir/')) interpreter = new CommandInterpreter(fixturesProject) - editSession = fixturesProject.open('sample.js') + editSession = fixturesProject.buildEditSessionForPath('sample.js') buffer = editSession.buffer afterEach -> @@ -320,7 +320,7 @@ describe "CommandInterpreter", -> runs -> expect(operations.length).toBeGreaterThan 3 for operation in operations - editSession = project.open(operation.getPath()) + editSession = project.buildEditSessionForPath(operation.getPath()) operation.execute(editSession) expect(editSession.getSelectedText()).toMatch /a+/ editSession.destroy() diff --git a/spec/extensions/fuzzy-finder-spec.coffee b/spec/extensions/fuzzy-finder-spec.coffee index fb5c1a999..d5b2d6552 100644 --- a/spec/extensions/fuzzy-finder-spec.coffee +++ b/spec/extensions/fuzzy-finder-spec.coffee @@ -122,7 +122,7 @@ describe 'FuzzyFinder', -> describe "when the active editor only contains edit sessions for anonymous buffers", -> it "does not open", -> editor = rootView.getActiveEditor() - editor.edit(rootView.project.open()) + editor.edit(rootView.project.buildEditSessionForPath()) editor.loadPreviousEditSession() editor.destroyActiveEditSession() expect(editor.getOpenBufferPaths().length).toBe 0 diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 40fe58d83..67b1a8857 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -14,7 +14,7 @@ class EditSession @idCounter: 1 @deserialize: (state, project) -> - session = project.open(state.buffer) + session = project.buildEditSessionForPath(state.buffer) session.setScrollTop(state.scrollTop) session.setScrollLeft(state.scrollLeft) session.setCursorScreenPosition(state.cursorScreenPosition) diff --git a/src/app/project.coffee b/src/app/project.coffee index c947b20aa..503458548 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -21,6 +21,7 @@ class Project constructor: (path) -> @setPath(path) @editSessions = [] + @buffer = [] @setTabText(' ') @setAutoIndent(true) @setSoftTabs(true) @@ -84,7 +85,7 @@ class Project getSoftWrap: -> @softWrap setSoftWrap: (@softWrap) -> - open: (filePath, editSessionOptions={}) -> + buildEditSessionForPath: (filePath, editSessionOptions={}) -> @buildEditSession(@bufferForPath(filePath), editSessionOptions) buildEditSession: (buffer, editSessionOptions) -> diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 6115f9a8d..d8dca8e63 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -96,7 +96,7 @@ class RootView extends View allowActiveEditorChange = options.allowActiveEditorChange ? false unless editSession = @openInExistingEditor(path, allowActiveEditorChange) - editSession = @project.open(path) + editSession = @project.buildEditSessionForPath(path) editor = new Editor({editSession}) pane = new Pane(editor) @panes.append(pane) @@ -120,7 +120,7 @@ class RootView extends View editor.focus() return editSession - editSession = @project.open(path) + editSession = @project.buildEditSessionForPath(path) activeEditor.edit(editSession) editSession