Only load TextMate packages as needed in specs

Also: when a TextMate package is deactivated, remove its grammars
This commit is contained in:
Corey Johnson & Nathan Sobo
2013-03-25 17:31:01 -06:00
committed by Nathan Sobo
parent 8340a084d3
commit 8437f3ff7f
14 changed files with 70 additions and 20 deletions

View File

@@ -32,9 +32,14 @@ class Syntax
addGrammar: (grammar) ->
@grammars.push(grammar)
for fileType in grammar.fileTypes
@grammarsByFileType[fileType] = grammar
@grammarsByScopeName[grammar.scopeName] = grammar
@grammarsByFileType[fileType] = grammar for fileType in grammar.fileTypes
@grammarsByScopeName[grammar.scopeName] = grammar
removeGrammar: (grammar) ->
if _.include(@grammars, grammar)
_.remove(@grammars, grammar)
delete @grammarsByFileType[fileType] for fileType in grammar.fileTypes
delete @grammarsByScopeName[grammar.scopeName]
setGrammarOverrideForPath: (path, scopeName) ->
@grammarOverridesByPath[path] = scopeName
@@ -46,7 +51,9 @@ class Syntax
@grammarOverridesByPath = {}
selectGrammar: (filePath, fileContents) ->
return @grammarsByFileType["txt"] ? @nullGrammar unless filePath
@grammarOverrideForPath(filePath) ?
@grammarByFirstLineRegex(filePath, fileContents) ?
@grammarByPath(filePath) ?

View File

@@ -36,7 +36,8 @@ class TextMatePackage extends Package
syntax.addProperties(selector, properties)
deactivate: ->
# we should remove grammars and unregister properties, snippets, etc
syntax.removeGrammar(grammar) for grammar in @grammars
# we should also unregister properties, snippets, etc
legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage']