Check if file exists before reading

Closes #153
This commit is contained in:
Kevin Sawicki
2013-01-22 13:49:35 -08:00
parent 2cb622c417
commit 7c3141783b
2 changed files with 19 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
RootView = require 'root-view'
OutlineView = require 'outline-view'
TagGenerator = require 'outline-view/src/tag-generator'
fs = require 'fs'
describe "OutlineView", ->
[rootView, outlineView, setArraySpy] = []
@@ -152,6 +153,21 @@ describe "OutlineView", ->
expect(rootView.getActiveEditor().getPath()).toBe rootView.project.resolve("tagged-duplicate.js")
expect(rootView.getActiveEditor().getCursorBufferPosition()).toEqual [0,4]
describe "when the tag is in a file that doesn't exist", ->
beforeEach ->
fs.move(rootView.project.resolve("tagged-duplicate.js"), rootView.project.resolve("tagged-duplicate-renamed.js"))
afterEach ->
fs.move(rootView.project.resolve("tagged-duplicate-renamed.js"), rootView.project.resolve("tagged-duplicate.js"))
it "doesn't display the tag", ->
rootView.open("tagged.js")
editor = rootView.getActiveEditor()
editor.setCursorBufferPosition([8,14])
editor.trigger 'outline-view:jump-to-declaration'
expect(outlineView.list.children('li').length).toBe 1
expect(outlineView.list.children('li:first').find('.function-name')).toHaveText 'tagged.js'
describe "project outline", ->
it "displays all tags", ->
rootView.open("tagged.js")

View File

@@ -102,7 +102,9 @@ class OutlineView extends SelectList
getTagLine: (tag) ->
pattern = $.trim(tag.pattern?.replace(/(^^\/\^)|(\$\/$)/g, '')) # Remove leading /^ and trailing $/
return unless pattern
for line, index in fs.read(@rootView.project.resolve(tag.file)).split('\n')
file = @rootView.project.resolve(tag.file)
return unless fs.isFile(file)
for line, index in fs.read(file).split('\n')
return new Point(index, 0) if pattern is $.trim(line)
jumpToDeclaration: ->