mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Translate TextMate snippets in the worker thread
Might as well do as much work there as possible.
This commit is contained in:
committed by
Kevin Sawicki
parent
0726987896
commit
ea65c63862
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user