mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Make TextMate snippets loading immune to hidden files & invalid plist
closes #143
This commit is contained in:
committed by
Kevin Sawicki
parent
59ac9de8c3
commit
0d63d6459d
1
spec/fixtures/packages/textmate-package.tmbundle/Snippets/.hidden-file
vendored
Normal file
1
spec/fixtures/packages/textmate-package.tmbundle/Snippets/.hidden-file
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am hidden so I shouldn't be loaded
|
||||
1
spec/fixtures/packages/textmate-package.tmbundle/Snippets/invalid.plist
vendored
Normal file
1
spec/fixtures/packages/textmate-package.tmbundle/Snippets/invalid.plist
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am not a valid plist but that shouldn't cause a crisis
|
||||
@@ -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 """
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user