mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Load snippets from any atom package with a snippets directory
This commit is contained in:
@@ -17,8 +17,14 @@
|
||||
beforeEach ->
|
||||
$1
|
||||
"""
|
||||
"After each":
|
||||
prefix: "af"
|
||||
body: """
|
||||
afterEach ->
|
||||
$1
|
||||
"""
|
||||
"Expectation":
|
||||
prefix: "be"
|
||||
prefix: "ex"
|
||||
body: "expect($1).to$2"
|
||||
"Console log":
|
||||
prefix: "log"
|
||||
|
||||
4
spec/fixtures/packages/package-with-snippets/snippets/test.cson
vendored
Normal file
4
spec/fixtures/packages/package-with-snippets/snippets/test.cson
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
".test":
|
||||
"Test Snippet":
|
||||
prefix: "test"
|
||||
body: "testing 123"
|
||||
@@ -13,7 +13,8 @@ TokenizedBuffer = require 'tokenized-buffer'
|
||||
fs = require 'fs'
|
||||
require 'window'
|
||||
requireStylesheet "jasmine.css"
|
||||
require.paths.unshift(require.resolve('fixtures/packages'))
|
||||
fixturePackagesPath = require.resolve('fixtures/packages')
|
||||
require.paths.unshift(fixturePackagesPath)
|
||||
[bindingSetsToRestore, bindingSetsByFirstKeystrokeToRestore] = []
|
||||
|
||||
# Load TextMate bundles, which specs rely on (but not other packages)
|
||||
@@ -29,6 +30,7 @@ beforeEach ->
|
||||
|
||||
# reset config before each spec; don't load or save from/to `config.json`
|
||||
window.config = new Config()
|
||||
config.packageDirPaths.unshift(fixturePackagesPath)
|
||||
spyOn(config, 'load')
|
||||
spyOn(config, 'save')
|
||||
config.set "editor.fontSize", 16
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Snippets = require 'snippets'
|
||||
Snippet = require 'snippets/src/snippet'
|
||||
RootView = require 'root-view'
|
||||
Buffer = require 'buffer'
|
||||
Editor = require 'editor'
|
||||
@@ -197,6 +198,10 @@ describe "Snippets extension", ->
|
||||
anotherEditor.trigger keydownEvent('tab', target: anotherEditor[0])
|
||||
expect(anotherEditor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]]
|
||||
|
||||
describe "snippet loading", ->
|
||||
it "loads snippets from all packages with a snippets directory", ->
|
||||
expect(syntax.getProperty(['.test'], 'snippets.test')?.constructor).toBe Snippet
|
||||
|
||||
describe "Snippets parser", ->
|
||||
it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", ->
|
||||
bodyTree = Snippets.parser.parse """
|
||||
|
||||
11
src/packages/snippets/src/package-extensions.coffee
Normal file
11
src/packages/snippets/src/package-extensions.coffee
Normal file
@@ -0,0 +1,11 @@
|
||||
AtomPackage = require 'atom-package'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
fs = require 'fs'
|
||||
|
||||
AtomPackage.prototype.loadSnippets = ->
|
||||
snippetsDirPath = fs.join(@path, 'snippets')
|
||||
if fs.exists(snippetsDirPath)
|
||||
for snippetsPath in fs.list(snippetsDirPath)
|
||||
snippets.load(snippetsPath)
|
||||
|
||||
TextMatePackage.prototype.loadSnippets = ->
|
||||
@@ -3,6 +3,7 @@ PEG = require 'pegjs'
|
||||
_ = require 'underscore'
|
||||
SnippetExpansion = require 'snippets/src/snippet-expansion'
|
||||
Snippet = require './snippet'
|
||||
require './package-extensions'
|
||||
|
||||
module.exports =
|
||||
snippetsByExtension: {}
|
||||
@@ -15,6 +16,9 @@ module.exports =
|
||||
@rootView.on 'editor:attached', (e, editor) => @enableSnippetsInEditor(editor)
|
||||
|
||||
loadAll: ->
|
||||
for pack in atom.getPackages()
|
||||
pack.loadSnippets()
|
||||
|
||||
for snippetsPath in fs.list(@userSnippetsDir)
|
||||
@load(snippetsPath)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user