Always load bundle preferences

Previously the scoped properties would not load if there weren't
any grammars in the bundle or if listing the grammars directory
failed.

Closes #570
This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-06-11 13:52:40 -07:00
parent c63536c682
commit 0c8f200d45
3 changed files with 34 additions and 17 deletions

View File

@@ -205,6 +205,18 @@ describe "the `atom` global", ->
atom.activatePackage('ruby-tmbundle', sync: true)
expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBe '# '
describe "when the package has no grammars but does have preferences", ->
it "loads the package's preferences as scoped properties", ->
jasmine.unspy(window, 'setTimeout')
spyOn(syntax, 'addProperties').andCallThrough()
atom.activatePackage('package-with-preferences-tmbundle')
waitsFor ->
syntax.addProperties.callCount > 0
runs ->
expect(syntax.getProperty(['.source.pref'], 'editor.increaseIndentPattern')).toBe '^abc$'
describe ".activatePackageConfig(id)", ->
it "calls the optional .activateConfigMenu method on the package's main module", ->
pack = atom.activatePackageConfig('package-with-activate-config')

View File

@@ -0,0 +1,7 @@
{
"name": "my preferences",
"scope": "source.pref",
"settings": {
"increaseIndentPattern": "^abc$"
}
}

View File

@@ -13,7 +13,10 @@ class TextMatePackage extends Package
@getLoadQueue: ->
return @loadQueue if @loadQueue
@loadQueue = async.queue (pack, done) -> pack.loadGrammars(done)
@loadQueue = async.queue (pack, done) ->
pack.loadGrammars ->
pack.loadScopedProperties(done)
@loadQueue
constructor: ->
@@ -44,21 +47,15 @@ class TextMatePackage extends Package
loadGrammars: (done) ->
fsUtils.isDirectoryAsync @getSyntaxesPath(), (isDirectory) =>
return done() unless isDirectory
fsUtils.listAsync @getSyntaxesPath(), @legalGrammarExtensions, (error, paths) =>
if error?
console.log("Error loading grammars of TextMate package '#{@path}':", error.stack, error)
done()
return
async.waterfall [
(next) =>
async.eachSeries paths, @loadGrammarAtPath, next
(next) =>
@loadScopedProperties()
next()
], done
if isDirectory
fsUtils.listAsync @getSyntaxesPath(), @legalGrammarExtensions, (error, paths) =>
if error?
console.log("Error loading grammars of TextMate package '#{@path}':", error.stack, error)
done()
else
async.eachSeries(paths, @loadGrammarAtPath, done)
else
done()
loadGrammarAtPath: (path, done) =>
TextMateGrammar.load path, (err, grammar) =>
@@ -105,7 +102,7 @@ class TextMatePackage extends Package
for {selector, properties} in @scopedProperties
syntax.addProperties(@path, selector, properties)
loadScopedProperties: ->
loadScopedProperties: (callback) ->
scopedProperties = []
for grammar in @getGrammars()
@@ -124,6 +121,7 @@ class TextMatePackage extends Package
if @isActive()
for {selector, properties} in @scopedProperties
syntax.addProperties(@path, selector, properties)
callback?()
@loadTextMatePreferenceObjects(preferenceObjects, done)
loadTextMatePreferenceObjects: (preferenceObjects, done) ->