Merge branch 'master' of github.com:github/atom

This commit is contained in:
Nathan Sobo 2012-07-04 12:34:56 -06:00
commit 39ce15c3fa
34 changed files with 91 additions and 49 deletions

View File

@ -1,4 +1,4 @@
CommandInterpreter = require 'command-interpreter'
CommandInterpreter = require 'command-panel/command-interpreter'
Buffer = require 'buffer'
EditSession = require 'edit-session'
Editor = require 'editor'

View File

@ -9,7 +9,7 @@ describe "CommandPanel", ->
rootView.open(require.resolve 'fixtures/sample.js')
rootView.enableKeymap()
editor = rootView.getActiveEditor()
commandPanel = rootView.activateExtension(CommandPanel)
commandPanel = requireExtension('command-panel')
afterEach ->
rootView.remove()

View File

@ -9,7 +9,7 @@ describe "Snippets extension", ->
[buffer, editor] = []
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
rootView.activateExtension(Snippets)
requireExtension("snippets")
editor = rootView.getActiveEditor()
buffer = editor.getBuffer()
rootView.simulateDomAttachment()

View File

@ -215,16 +215,11 @@ describe "TreeView", ->
expect(treeView.find('.selected').length).toBe 1
it "selected a file's parent dir if the file's entry is not visible", ->
# treeView.attachToDom()
rootView.open(require.resolve('fixtures/dir/a-dir/oh-git'))
dirView = treeView.root.find('.directory:contains(dir)').view()
expect(dirView).toHaveClass 'selected'
# dirView.expand()
# aDirView = dirView.find('.directory:contains(a-dir)').view()
# expect(aDirView).toHaveClass 'selected'
describe "when a different editor becomes active", ->
it "selects the file in that is open in that editor", ->
sampleJs.click()
@ -493,15 +488,15 @@ describe "TreeView", ->
describe "when the path with a trailing '/' is changed and confirmed", ->
describe "when no file or directory exists at the given path", ->
it "adds a directory and closes the dialog", ->
newPath = fs.join(dirPath, "new-dir")
addDialog.miniEditor.insertText("new-dir/")
newPath = fs.join(dirPath, "new/dir")
addDialog.miniEditor.insertText("new/dir/")
addDialog.trigger 'tree-view:confirm'
expect(fs.exists(newPath)).toBeTruthy()
expect(fs.isDirectory(newPath)).toBeTruthy()
expect(addDialog.parent()).not.toExist()
expect(rootView.getActiveEditor().getBuffer().getPath()).not.toBe newPath
describe "when a or directory already exists at the given path", ->
describe "when a file or directory already exists at the given path", ->
it "shows an error message and does not close the dialog", ->
newPath = fs.join(dirPath, "new-dir")
fs.makeDirectory(newPath)
@ -592,7 +587,7 @@ describe "TreeView", ->
describe "when the directories along the new path don't exist", ->
it "creates the target directory before moving the file", ->
runs ->
newPath = fs.join(rootDirPath, 'new-directory', 'renamed-test-file.txt')
newPath = fs.join(rootDirPath, 'new/directory', 'renamed-test-file.txt')
moveDialog.miniEditor.setText(newPath)
moveDialog.trigger 'tree-view:confirm'

View File

@ -21,8 +21,9 @@ describe "fs", ->
describe "when called with a directory path", ->
it "return the path it was given", ->
expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures')
expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures')
expect(fs.directory("/a/b/c")).toBe "/a/b"
expect(fs.directory("/a")).toBe ""
expect(fs.directory("a")).toBe ""
describe ".exists(path)", ->
it "returns true when path exsits", ->
@ -32,7 +33,6 @@ describe "fs", ->
expect(fs.exists(require.resolve("fixtures") + "/-nope-does-not-exist")).toBe false
expect(fs.exists("")).toBe false
expect(fs.exists(null)).toBe false
#expect(fs.exists(undefined)).toBe false
describe ".join(paths...)", ->
it "concatenates the given paths with the directory seperator", ->
@ -41,6 +41,11 @@ describe "fs", ->
expect(fs.join('/a/b/', 'c', 'd')).toBe '/a/b/c/d'
expect(fs.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/'
describe ".split(path)", ->
it "returns path components", ->
expect(fs.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"]
expect(fs.split("a/b/c.txt")).toEqual ["a", "b", "c.txt"]
describe ".extension(path)", ->
it "returns the extension of a file", ->
expect(fs.extension("a/b/corey.txt")).toBe '.txt'
@ -49,6 +54,14 @@ describe "fs", ->
it "returns an empty string for paths without an extension", ->
expect(fs.extension("a/b.not-extension/a-dir")).toBe ''
describe "makeTree(path)", ->
beforeEach ->
fs.remove("/tmp/a") if fs.exists("/tmp/a")
it "creates all directories in path including any missing parent directories", ->
fs.makeTree("/tmp/a/b/c")
expect(fs.exists("/tmp/a/b/c")).toBeTruthy()
describe ".traverseTree(path, fn)", ->
fixturesDir = null

View File

@ -55,6 +55,15 @@ windowAdditions =
return if $("head style[path='#{fullPath}']").length
$('head').append "<style path='#{fullPath}'>#{content}</style>"
requireExtension: (name) ->
extensionPath = require.resolve name
extension = rootView.activateExtension require(extensionPath)
extensionKeymapPath = fs.join(fs.directory(extensionPath), "keymap.coffee")
require extensionKeymapPath if fs.exists(extensionKeymapPath)
extension
reload: ->
if rootView.getModifiedBuffers().length > 0
message = "There are unsaved buffers, reload anyway?"

View File

@ -0,0 +1 @@
module.exports = require 'autocomplete/autocomplete.coffee'

View File

@ -4,7 +4,7 @@ PEG = require 'pegjs'
module.exports =
class CommandInterpreter
constructor: ->
@parser = PEG.buildParser(fs.read(require.resolve 'command-interpreter/commands.pegjs'))
@parser = PEG.buildParser(fs.read(require.resolve 'command-panel/commands.pegjs'))
eval: (editor, string) ->
compositeCommand = @parser.parse(string)

View File

@ -1,7 +1,7 @@
{View} = require 'space-pen'
CommandInterpreter = require 'command-interpreter'
RegexAddress = require 'command-interpreter/regex-address'
CompositeCommand = require 'command-interpreter/composite-command'
CommandInterpreter = require 'command-panel/command-interpreter'
RegexAddress = require 'command-panel/commands/regex-address'
CompositeCommand = require 'command-panel/commands/composite-command'
Editor = require 'editor'
{SyntaxError} = require('pegjs').parser

View File

@ -1,12 +1,12 @@
{
var CompositeCommand = require('command-interpreter/composite-command')
var Substitution = require('command-interpreter/substitution');
var LineAddress = require('command-interpreter/line-address');
var AddressRange = require('command-interpreter/address-range');
var EofAddress = require('command-interpreter/eof-address');
var CurrentSelectionAddress = require('command-interpreter/current-selection-address')
var RegexAddress = require('command-interpreter/regex-address')
var SelectAllMatches = require('command-interpreter/select-all-matches')
var CompositeCommand = require('command-panel/commands/composite-command')
var Substitution = require('command-panel/commands/substitution');
var LineAddress = require('command-panel/commands/line-address');
var AddressRange = require('command-panel/commands/address-range');
var EofAddress = require('command-panel/commands/eof-address');
var CurrentSelectionAddress = require('command-panel/commands/current-selection-address')
var RegexAddress = require('command-panel/commands/regex-address')
var SelectAllMatches = require('command-panel/commands/select-all-matches')
}
start = expressions:(expression+) {

View File

@ -1,4 +1,4 @@
Address = require 'command-interpreter/address'
Address = require 'command-panel/commands/address'
Range = require 'range'
module.exports =

View File

@ -1,4 +1,4 @@
Command = require 'command-interpreter/command'
Command = require 'command-panel/commands/command'
module.exports =
class Address extends Command

View File

@ -1,4 +1,4 @@
Address = require 'command-interpreter/address'
Address = require 'command-panel/commands/address'
Range = require 'range'
module.exports =

View File

@ -1,4 +1,4 @@
Address = require 'command-interpreter/address'
Address = require 'command-panel/commands/address'
Range = require 'range'
module.exports =

View File

@ -1,4 +1,4 @@
Address = require 'command-interpreter/address'
Address = require 'command-panel/commands/address'
Range = require 'range'
module.exports =

View File

@ -1,4 +1,4 @@
Address = require 'command-interpreter/address'
Address = require 'command-panel/commands/address'
Range = require 'range'
module.exports =

View File

@ -1,4 +1,4 @@
Command = require 'command-interpreter/command'
Command = require 'command-panel/commands/command'
Range = require 'range'
module.exports =

View File

@ -1,4 +1,4 @@
Command = require 'command-interpreter/command'
Command = require 'command-panel/commands/command'
module.exports =
class Substitution extends Command

View File

@ -0,0 +1 @@
module.exports = require 'command-panel/command-panel'

View File

@ -0,0 +1 @@
module.exports = require 'fuzzy-finder/fuzzy-finder'

View File

@ -171,7 +171,7 @@ class TreeView extends View
newPath = @rootView.project.resolve(newPath)
directoryPath = fs.directory(newPath)
try
fs.makeDirectory(directoryPath) unless fs.exists(directoryPath)
fs.makeTree(directoryPath) unless fs.exists(directoryPath)
fs.move(oldPath, newPath)
catch e
dialog.showError("Error: " + e.message + " Try a different path:")
@ -208,15 +208,15 @@ class TreeView extends View
endsWithDirectorySeperator = /\/$/.test(relativePath)
path = @rootView.project.resolve(relativePath)
try
if endsWithDirectorySeperator
fs.makeDirectory(path)
if fs.exists(path)
pathType = if fs.isFile(path) then "file" else "directory"
dialog.showError("Error: A #{pathType} already exists at path '#{path}'. Try a different path:")
false
else if endsWithDirectorySeperator
fs.makeTree(path)
else
if fs.exists(path)
dialog.showError("Error: A file already exists at path '#{path}'. Try a different path:")
false
else
fs.write(path, "")
@rootView.open(path)
fs.write(path, "")
@rootView.open(path)
catch e
dialog.showError("Error: " + e.message + " Try a different path:")
return false

View File

@ -21,7 +21,9 @@ module.exports =
# parent directory if the file is a directory. A terminal directory
# separator is ignored.
directory: (path) ->
path.replace(new RegExp("/#{@base(path)}\/?$"), '')
parentPath = path.replace(new RegExp("/#{@base(path)}\/?$"), '')
return "" if path == parentPath
parentPath
# Returns true if the file specified by path exists
exists: (path) ->
@ -75,6 +77,15 @@ module.exports =
read: (path) ->
$native.read(path)
# Returns an array of path components. If the path is absolute, the first
# component will be an indicator of the root of the file system; for file
# systems with drives (such as Windows), this is the drive identifier with a
# colon, like "c:"; on Unix, this is an empty string "". The intent is that
# calling "join.apply" with the result of "split" as arguments will
# reconstruct the path.
split: (path) ->
path.split("/")
# Open, write, flush, and close a file, writing the given content.
write: (path, content) ->
$native.write(path, content)
@ -82,6 +93,14 @@ module.exports =
makeDirectory: (path) ->
$native.makeDirectory(path)
# Creates the directory specified by "path" including any missing parent
# directories.
makeTree: (path) ->
return unless path
if not @exists(path)
@makeTree(@directory(path))
@makeDirectory(path)
traverseTree: (rootPath, fn) ->
recurse = null
prune = -> recurse = false

View File

@ -106,12 +106,15 @@ __exists = (path) ->
__coffeeCache = (filePath) ->
{CoffeeScript} = require 'coffee-script'
cacheKey = 'coffee.' + $native.md5ForPath(filePath)
if compiled = localStorage.getItem(cacheKey)
compiled
tmpPath = "/tmp/atom-compiled-scripts"
cacheFilePath = [tmpPath, $native.md5ForPath(filePath)].join("/")
console.log cacheFilePath
if __exists(cacheFilePath)
__read(cacheFilePath)
else
compiled = CoffeeScript.compile(__read(filePath), filename: filePath)
localStorage.setItem(cacheKey, compiled)
$native.write(cacheFilePath, compiled)
compiled
__read = (path) ->