Wait until TextMate packages are activated to add grammars/properties

My plan is to cache the loading of packages so we don't have to load
them from the disk repeatedly in specs. The first step of this is
ensuring that load has no side-effects.
This commit is contained in:
Nathan Sobo
2013-03-22 18:52:06 -06:00
parent 187263173b
commit 7a4f5ad9d1
2 changed files with 16 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ _.extend atom,
loadedThemes: []
pendingBrowserProcessCallbacks: {}
loadedPackages: []
activePackages: []
activatedAtomPackages: []
atomPackageStates: {}
presentingModal: false
@@ -50,7 +51,12 @@ _.extend atom,
pack.load()
activatePackages: ->
pack.activate() for pack in @loadedPackages
for pack in @loadedPackages
@activePackages.push(pack)
pack.activate()
isPackageActive: (pack) ->
_.include(@activePackages, pack)
getLoadedPackages: ->
_.clone(@loadedPackages)

View File

@@ -31,6 +31,11 @@ class TextMatePackage extends Package
TextMatePackage.getLoadQueue().push(this)
@loadScopedProperties()
activate: ->
syntax.addGrammar(grammar) for grammar in @grammars
for { selector, properties } in @scopedProperties
syntax.addProperties(selector, properties)
legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage', 'cson', 'json']
loadGrammars: (done) ->
@@ -52,30 +57,22 @@ class TextMatePackage extends Package
addGrammar: (grammar) ->
@grammars.push(grammar)
syntax.addGrammar(grammar)
activate: -> # no-op
syntax.addGrammar(grammar) if atom.isPackageActive(this)
getGrammars: -> @grammars
loadScopedProperties: ->
for { selector, properties } in @getScopedProperties()
syntax.addProperties(selector, properties)
getScopedProperties: ->
scopedProperties = []
@scopedProperties = []
for grammar in @getGrammars()
if properties = @propertiesFromTextMateSettings(grammar)
selector = syntax.cssSelectorFromScopeSelector(grammar.scopeName)
scopedProperties.push({selector, properties})
@scopedProperties.push({selector, properties})
for {scope, settings} in @getTextMatePreferenceObjects()
if properties = @propertiesFromTextMateSettings(settings)
selector = syntax.cssSelectorFromScopeSelector(scope) if scope?
scopedProperties.push({selector, properties})
scopedProperties
@scopedProperties.push({selector, properties})
getTextMatePreferenceObjects: ->
preferenceObjects = []