mirror of
https://github.com/atom/atom.git
synced 2026-02-13 08:04:56 -05:00
Load snippets from any atom package with a snippets directory
This commit is contained in:
@@ -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