mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge remote-tracking branch 'origin/dev' into fuzzy
This commit is contained in:
1
spec/fixtures/packages/package-with-snippets/snippets/.hidden-file
vendored
Normal file
1
spec/fixtures/packages/package-with-snippets/snippets/.hidden-file
vendored
Normal file
@@ -0,0 +1 @@
|
||||
This is a hidden file. Don't even try to load it as a snippet
|
||||
1
spec/fixtures/packages/package-with-snippets/snippets/junk-file
vendored
Normal file
1
spec/fixtures/packages/package-with-snippets/snippets/junk-file
vendored
Normal file
@@ -0,0 +1 @@
|
||||
This file isn't CSON, but shouldn't be a big deal
|
||||
@@ -207,12 +207,17 @@ describe "Snippets extension", ->
|
||||
expect(editor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]]
|
||||
|
||||
describe "snippet loading", ->
|
||||
it "loads snippets from all atom packages with a snippets directory", ->
|
||||
it "loads non-hidden snippet files from all atom packages with snippets directories, logging a warning if a file can't be parsed", ->
|
||||
spyOn(console, 'warn')
|
||||
jasmine.unspy(AtomPackage.prototype, 'loadSnippets')
|
||||
snippets.loadAll()
|
||||
|
||||
expect(syntax.getProperty(['.test'], 'snippets.test')?.constructor).toBe Snippet
|
||||
|
||||
# warn about junk-file, but don't even try to parse a hidden file
|
||||
expect(console.warn).toHaveBeenCalled()
|
||||
expect(console.warn.calls.length).toBe 1
|
||||
|
||||
it "loads snippets from all TextMate packages with snippets", ->
|
||||
jasmine.unspy(TextMatePackage.prototype, 'loadSnippets')
|
||||
snippets.loadAll()
|
||||
|
||||
@@ -4,9 +4,7 @@ fs = require 'fs'
|
||||
|
||||
AtomPackage.prototype.loadSnippets = ->
|
||||
snippetsDirPath = fs.join(@path, 'snippets')
|
||||
if fs.exists(snippetsDirPath)
|
||||
for snippetsPath in fs.list(snippetsDirPath)
|
||||
snippets.load(snippetsPath)
|
||||
snippets.loadDirectory(snippetsDirPath) if fs.exists(snippetsDirPath)
|
||||
|
||||
TextMatePackage.prototype.loadSnippets = ->
|
||||
snippetsDirPath = fs.join(@path, 'Snippets')
|
||||
|
||||
@@ -19,11 +19,18 @@ module.exports =
|
||||
for pack in atom.getPackages()
|
||||
pack.loadSnippets()
|
||||
|
||||
for snippetsPath in fs.list(@userSnippetsDir)
|
||||
@load(snippetsPath)
|
||||
@loadDirectory(@userSnippetsDir) if fs.exists(@userSnippetsDir)
|
||||
|
||||
loadDirectory: (snippetsDirPath) ->
|
||||
for snippetsPath in fs.list(snippetsDirPath) when fs.base(snippetsPath).indexOf('.') isnt 0
|
||||
snippets.load(snippetsPath)
|
||||
|
||||
load: (snippetsPath) ->
|
||||
@add(fs.readObject(snippetsPath))
|
||||
try
|
||||
snippets = fs.readObject(snippetsPath)
|
||||
catch e
|
||||
console.warn "Error reading snippets file '#{snippetsPath}'"
|
||||
@add(snippets)
|
||||
|
||||
add: (snippetsBySelector) ->
|
||||
for selector, snippetsByName of snippetsBySelector
|
||||
|
||||
Reference in New Issue
Block a user