mirror of
https://github.com/atom/atom.git
synced 2026-02-07 13:14:55 -05:00
Replace LoadTextMatePackagesTask with async grammar loading
This commit is contained in:
@@ -3,7 +3,6 @@ _ = require 'underscore'
|
||||
Package = require 'package'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
Theme = require 'theme'
|
||||
LoadTextMatePackagesTask = require 'load-text-mate-packages-task'
|
||||
|
||||
messageIdCounter = 1
|
||||
originalSendMessageToBrowserProcess = atom.sendMessageToBrowserProcess
|
||||
@@ -46,7 +45,7 @@ _.extend atom,
|
||||
textPackagePath = _.find @getPackagePaths(), (path) -> fs.base(path) is 'text.tmbundle'
|
||||
pack = Package.build(textPackagePath)
|
||||
@loadedPackages.push(pack)
|
||||
pack.load()
|
||||
pack.load(sync: true)
|
||||
|
||||
loadPackages: ->
|
||||
textMatePackages = []
|
||||
@@ -54,12 +53,7 @@ _.extend atom,
|
||||
for path in paths
|
||||
pack = Package.build(path)
|
||||
@loadedPackages.push(pack)
|
||||
if pack instanceof TextMatePackage
|
||||
textMatePackages.push(pack)
|
||||
else
|
||||
pack.load()
|
||||
|
||||
new LoadTextMatePackagesTask(textMatePackages).start() if textMatePackages.length > 0
|
||||
pack.load()
|
||||
|
||||
activatePackages: ->
|
||||
pack.activate() for pack in @loadedPackages
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
|
||||
module.exports =
|
||||
loadPackage: (path) ->
|
||||
callTaskMethod('packageLoaded', new TextMatePackage(path).readGrammars())
|
||||
@@ -1,26 +0,0 @@
|
||||
Task = require 'task'
|
||||
|
||||
module.exports =
|
||||
class LoadTextMatePackagesTask extends Task
|
||||
|
||||
constructor: (@packages) ->
|
||||
super('load-text-mate-packages-handler')
|
||||
|
||||
started: ->
|
||||
@loadNextPackage()
|
||||
|
||||
loadNextPackage: ->
|
||||
unless @packages.length
|
||||
@done()
|
||||
syntax.trigger 'grammars-loaded'
|
||||
return
|
||||
|
||||
@package = @packages.shift()
|
||||
@loadPackage(@package.path)
|
||||
|
||||
loadPackage: (path) ->
|
||||
@callWorkerMethod('loadPackage', path)
|
||||
|
||||
packageLoaded: (grammars) ->
|
||||
@package.loadGrammars(grammars)
|
||||
@loadNextPackage()
|
||||
@@ -10,6 +10,16 @@ class TextMateGrammar
|
||||
@readFromPath: (path) ->
|
||||
fs.readPlist(path)
|
||||
|
||||
@load: (path, done) ->
|
||||
fs.readObjectAsync path, (err, object) ->
|
||||
if err
|
||||
done(err)
|
||||
else
|
||||
done(null, new TextMateGrammar(object))
|
||||
|
||||
@loadSync: (path) ->
|
||||
new TextMateGrammar(fs.readObject(path))
|
||||
|
||||
name: null
|
||||
fileTypes: null
|
||||
scopeName: null
|
||||
|
||||
@@ -5,6 +5,7 @@ plist = require 'plist'
|
||||
_ = require 'underscore'
|
||||
TextMateGrammar = require 'text-mate-grammar'
|
||||
CSON = require 'cson'
|
||||
async = require 'async'
|
||||
|
||||
module.exports =
|
||||
class TextMatePackage extends Package
|
||||
@@ -17,38 +18,39 @@ class TextMatePackage extends Package
|
||||
@syntaxesPath = fsUtils.join(@path, "Syntaxes")
|
||||
@grammars = []
|
||||
|
||||
load: ->
|
||||
try
|
||||
load: ({sync}={}) ->
|
||||
if sync
|
||||
@loadGrammarsSync()
|
||||
else
|
||||
@loadGrammars()
|
||||
catch e
|
||||
console.warn "Failed to load package at '#{@path}'", e.stack
|
||||
this
|
||||
@loadScopedProperties()
|
||||
|
||||
legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage', 'cson', 'json']
|
||||
|
||||
loadGrammars: (done) ->
|
||||
fsUtils.isDirectoryAsync @syntaxesPath, (isDirectory) =>
|
||||
if isDirectory
|
||||
fsUtils.listAsync @syntaxesPath, @legalGrammarExtensions, (err, paths) =>
|
||||
return console.log("Error loading grammars of TextMate package '#{@path}':", err.stack, err) if err
|
||||
async.eachSeries paths, @loadGrammarAtPath, done
|
||||
|
||||
loadGrammarAtPath: (path, done) =>
|
||||
TextMateGrammar.load path, (err, grammar) =>
|
||||
return console.log("Error loading grammar at path '#{path}':", err.stack ? err) if err
|
||||
@addGrammar(grammar)
|
||||
|
||||
loadGrammarsSync: ->
|
||||
for path in fsUtils.list(@syntaxesPath, @legalGrammarExtensions) ? []
|
||||
@addGrammar(TextMateGrammar.loadSync(path))
|
||||
|
||||
addGrammar: (grammar) ->
|
||||
@grammars.push(grammar)
|
||||
syntax.addGrammar(grammar)
|
||||
|
||||
activate: -> # no-op
|
||||
|
||||
getGrammars: -> @grammars
|
||||
|
||||
readGrammars: ->
|
||||
grammars = []
|
||||
for grammarPath in fsUtils.list(@syntaxesPath)
|
||||
try
|
||||
grammars.push(TextMateGrammar.readFromPath(grammarPath))
|
||||
catch e
|
||||
console.warn "Failed to load grammar at path '#{grammarPath}'", e.stack
|
||||
grammars
|
||||
|
||||
addGrammar: (rawGrammar) ->
|
||||
grammar = new TextMateGrammar(rawGrammar)
|
||||
@grammars.push(grammar)
|
||||
syntax.addGrammar(grammar)
|
||||
|
||||
loadGrammars: (rawGrammars) ->
|
||||
rawGrammars = @readGrammars() unless rawGrammars?
|
||||
|
||||
@grammars = []
|
||||
@addGrammar(rawGrammar) for rawGrammar in rawGrammars
|
||||
@loadScopedProperties()
|
||||
|
||||
loadScopedProperties: ->
|
||||
for { selector, properties } in @getScopedProperties()
|
||||
syntax.addProperties(selector, properties)
|
||||
@@ -70,10 +72,10 @@ class TextMatePackage extends Package
|
||||
|
||||
getTextMatePreferenceObjects: ->
|
||||
preferenceObjects = []
|
||||
if fs.exists(@preferencesPath)
|
||||
for preferencePath in fs.list(@preferencesPath)
|
||||
if fsUtils.exists(@preferencesPath)
|
||||
for preferencePath in fsUtils.list(@preferencesPath)
|
||||
try
|
||||
preferenceObjects.push(fs.readObject(preferencePath))
|
||||
preferenceObjects.push(fsUtils.readObject(preferencePath))
|
||||
catch e
|
||||
console.warn "Failed to parse preference at path '#{preferencePath}'", e.stack
|
||||
preferenceObjects
|
||||
|
||||
Reference in New Issue
Block a user