Add NullGrammar to obviate synchronous load of text grammar on start

It's also an extremely simple grammar, so we'll do less work to
initially tokenize open buffers before loading their real grammars.
This commit is contained in:
Nathan Sobo 2013-03-20 19:38:37 -06:00
parent a2f72882d7
commit 2416ff19a4
4 changed files with 13 additions and 9 deletions

View File

@ -41,12 +41,6 @@ _.extend atom,
packageStates[pack.name] = @atomPackageStates[pack.name]
packageStates
loadTextPackage: ->
textPackagePath = _.find @getPackagePaths(), (path) -> fs.base(path) is 'text.tmbundle'
pack = Package.build(textPackagePath)
@loadedPackages.push(pack)
pack.load(sync: true)
loadPackages: ->
textMatePackages = []
paths = @getPackagePaths().filter (path) -> fs.base(path) isnt 'text.tmbundle'

View File

@ -0,0 +1,9 @@
Token = require 'token'
module.exports =
class NullGrammar
name: "Null Grammar"
scopeName: 'text.plain.null-grammar'
tokenizeLine: (line) ->
{ tokens: [new Token(value: line, scopes: ['null-grammar.text.plain'])] }

View File

@ -4,6 +4,7 @@ Specificity = require 'specificity'
{$$} = require 'space-pen'
fs = require 'fs-utils'
EventEmitter = require 'event-emitter'
NullGrammar = require 'null-grammar'
module.exports =
class Syntax
@ -14,6 +15,7 @@ class Syntax
@globalProperties = {}
@scopedPropertiesIndex = 0
@scopedProperties = []
@nullGrammar = new NullGrammar
addGrammar: (grammar) ->
@grammars.push(grammar)
@ -22,7 +24,7 @@ class Syntax
@grammarsByScopeName[grammar.scopeName] = grammar
selectGrammar: (filePath, fileContents) ->
return @grammarsByFileType["txt"] unless filePath
return @grammarsByFileType["txt"] ? @nullGrammar unless filePath
extension = fs.extension(filePath)?[1..]
if filePath and extension.length == 0
@ -31,7 +33,7 @@ class Syntax
@grammarByFirstLineRegex(filePath, fileContents) or
@grammarsByFileType[extension] or
@grammarByFileTypeSuffix(filePath) or
@grammarsByFileType["txt"]
@grammarsByFileType["txt"] ? @nullGrammar
grammarByFileTypeSuffix: (filePath) ->
for fileType, grammar of @grammarsByFileType

View File

@ -52,7 +52,6 @@ window.startup = ->
handleWindowEvents()
config.load()
atom.loadTextPackage()
keymap.loadBundledKeymaps()
atom.loadThemes()
atom.loadPackages()