Make TextMate snippets loading immune to hidden files & invalid plist

closes #143
This commit is contained in:
Nathan Sobo
2013-01-24 17:33:42 -07:00
committed by Kevin Sawicki
parent 59ac9de8c3
commit 0d63d6459d
4 changed files with 22 additions and 2 deletions

View File

@@ -0,0 +1 @@
I am hidden so I shouldn't be loaded

View File

@@ -0,0 +1 @@
I am not a valid plist but that shouldn't cause a crisis

View File

@@ -228,6 +228,7 @@ describe "Snippets extension", ->
expect(console.warn.calls.length).toBeGreaterThan 0
it "loads snippets from all TextMate packages with snippets", ->
spyOn(console, 'warn').andCallThrough()
jasmine.unspy(LoadSnippetsTask.prototype, 'start')
snippets.loaded = false
snippets.loadAll()
@@ -245,6 +246,10 @@ describe "Snippets extension", ->
}
"""
# warn about junk-file, but don't even try to parse a hidden file
expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.length).toBeGreaterThan 0
describe "Snippets parser", ->
it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", ->
bodyTree = snippets.parser.parse """

View File

@@ -6,8 +6,21 @@ module.exports =
loadTextmateSnippets: (path) ->
snippetsDirPath = fs.join(path, 'Snippets')
snippets = fs.list(snippetsDirPath).map (snippetPath) ->
fs.readPlist(snippetPath)
snippets = []
for snippetsPath in fs.list(snippetsDirPath)
logWarning = ->
console.warn "Error reading TextMate snippets file '#{snippetsPath}'"
continue if fs.base(snippetsPath).indexOf('.') is 0
try
if object = fs.readPlist(snippetsPath)
snippets.push(object) if object
else
logWarning()
catch e
logWarning()
@snippetsLoaded(@translateTextmateSnippets(snippets))
loadAtomSnippets: (path) ->