Trigger 'grammars-loaded' when TextMate packages finish loading

This is a temporary solution so we can merge async textmate package
loading. I'd like to dispense with this event and consider each
grammar individually as they are loaded. But this makes the behavior
compatible with the old background-task-based behavior.
This commit is contained in:
Nathan Sobo 2013-03-22 17:34:35 -06:00
parent a05405370c
commit adcfcb7897

View File

@ -12,6 +12,12 @@ class TextMatePackage extends Package
@testName: (packageName) ->
/(\.|_|-)tmbundle$/.test(packageName)
@getLoadQueue: ->
return @loadQueue if @loadQueue
@loadQueue = async.queue (pack, done) -> pack.loadGrammars(done)
@loadQueue.drain = -> syntax.trigger 'grammars-loaded'
@loadQueue
constructor: ->
super
@preferencesPath = fsUtils.join(@path, "Preferences")
@ -22,7 +28,7 @@ class TextMatePackage extends Package
if sync
@loadGrammarsSync()
else
@loadGrammars()
TextMatePackage.getLoadQueue().push(this)
@loadScopedProperties()
legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage', 'cson', 'json']
@ -38,6 +44,7 @@ class TextMatePackage extends Package
TextMateGrammar.load path, (err, grammar) =>
return console.log("Error loading grammar at path '#{path}':", err.stack ? err) if err
@addGrammar(grammar)
done()
loadGrammarsSync: ->
for path in fsUtils.list(@syntaxesPath, @legalGrammarExtensions) ? []