Support loading CSON snippets from TextMate bundles

This commit is contained in:
Kevin Sawicki
2013-02-11 09:29:48 -08:00
parent c96874659e
commit 76a6ab9f03
3 changed files with 25 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
'name': 'Really'
'scope': 'source.alot'
'tabTrigger': 'really'
'content': 'I really like $1 alot$0'

View File

@@ -20,8 +20,10 @@ module.exports =
continue if fs.base(snippetsPath).indexOf('.') is 0
try
if object = fs.readPlist(snippetsPath)
snippets.push(object) if object
if fs.extension(snippetsPath) is '.cson' and object = fs.readObject(snippetsPath)
snippets.push(object)
else if object = fs.readPlist(snippetsPath)
snippets.push(object)
else
logWarning()
catch e

View File

@@ -5,6 +5,7 @@ Buffer = require 'buffer'
Editor = require 'editor'
_ = require 'underscore'
fs = require 'fs'
Package = require 'package'
describe "Snippets extension", ->
[buffer, editor, editSession] = []
@@ -295,6 +296,22 @@ describe "Snippets extension", ->
expect(Worker.prototype.terminate).toHaveBeenCalled()
expect(Worker.prototype.terminate.calls.length).toBe 1
it "loads CSON snippets from TextMate packages", ->
jasmine.unspy(LoadSnippetsTask.prototype, 'loadTextMateSnippets')
snippets.loaded = false
task = new LoadSnippetsTask(snippets)
task.packages = [Package.build(fixturesProject.resolve('packages/package-with-a-cson-grammar.tmbundle'))]
task.start()
waitsFor "CSON snippets to load", 5000, -> snippets.loaded
runs ->
snippet = syntax.getProperty(['.source.alot'], 'snippets.really')
expect(snippet).toBeTruthy()
expect(snippet.prefix).toBe 'really'
expect(snippet.name).toBe 'Really'
expect(snippet.body).toBe "I really like alot"
describe "snippet body parser", ->
it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", ->
bodyTree = snippets.getBodyParser().parse """