Translate TextMate snippets in the worker thread

Might as well do as much work there as possible.
This commit is contained in:
Nathan Sobo
2013-01-24 15:45:09 -07:00
committed by Kevin Sawicki
parent 0726987896
commit ea65c63862
2 changed files with 15 additions and 16 deletions

View File

@@ -1,11 +1,14 @@
fs = require 'fs'
TextMatePackage = require 'text-mate-package'
module.exports =
snippetsLoaded: (snippets) -> callTaskMethod('snippetsLoaded', snippets)
loadTextmateSnippets: (path) ->
snippetsDirPath = fs.join(path, 'Snippets')
snippets = fs.list(snippetsDirPath).map (snippetPath) ->
fs.readPlist(snippetPath)
@snippetsLoaded(snippets)
@snippetsLoaded(@translateTextmateSnippets(snippets))
loadAtomSnippets: (path) ->
snippetsDirPath = fs.join(path, 'snippets')
@@ -18,4 +21,14 @@ module.exports =
console.warn "Error reading snippets file '#{snippetsPath}'"
@snippetsLoaded(snippets)
snippetsLoaded: (snippets) -> callTaskMethod('snippetsLoaded', snippets)
translateTextmateSnippets: (tmSnippets) ->
atomSnippets = {}
for { scope, name, content, tabTrigger } in tmSnippets
if scope
scope = TextMatePackage.cssSelectorFromScopeSelector(scope)
else
scope = '*'
snippetsForScope = (atomSnippets[scope] ?= {})
snippetsForScope[name] = { prefix: tabTrigger, body: content }
[atomSnippets]

View File

@@ -24,19 +24,5 @@ class LoadSnippetsTask extends Task
@callWorkerMethod(method, @packageBeingLoaded.path)
snippetsLoaded: (snippets) ->
if @packageBeingLoaded instanceof TextMatePackage
snippets = @translateTextmateSnippets(snippets)
@snippets.add(snippet) for snippet in snippets
@loadNextPackageSnippets()
translateTextmateSnippets: (tmSnippets) ->
atomSnippets = {}
for { scope, name, content, tabTrigger } in tmSnippets
if scope
scope = TextMatePackage.cssSelectorFromScopeSelector(scope)
else
scope = '*'
snippetsForScope = (atomSnippets[scope] ?= {})
snippetsForScope[name] = { prefix: tabTrigger, body: content }
[atomSnippets]