Project extended
Represents a project that's opened in Atom.
An instance of this class is always available as the atom.project
global.
Event Subscription
::onDidChangePaths(callback)
Invoke the given callback when the project paths change.
Argument | Description |
---|---|
callback(projectPaths) |
Function to be called after the project paths change. |
projectPaths |
Return values |
---|
Returns a Disposable on which |
::onDidAddBuffer(callback)
Invoke the given callback when a text buffer is added to the project.
Argument | Description |
---|---|
callback(buffer) |
Function to be called when a text buffer is added. |
buffer |
A TextBuffer item. |
Return values |
---|
Returns a Disposable on which |
::observeBuffers(callback)
Invoke the given callback with all current and future text buffers in the project.
Argument | Description |
---|---|
callback(buffer) |
Function to be called with current and future text buffers. |
buffer |
A TextBuffer item. |
Return values |
---|
Returns a Disposable on which |
::onDidChangeFiles(callback)
Invoke a callback when a filesystem change occurs within any open project path.
const disposable = atomprojectonDidChangeFilesevents =>for const event of events// "created", "modified", "deleted", or "renamed"console.log`Event action: $eventtype`// absolute path to the filesystem entry that was touchedconsole.log`Event path: $eventpath`if eventtype === 'renamed'console.log` renamed from: $eventoldPath`disposabledispose
To watch paths outside of open projects, use the watchPaths
function instead; see PathWatcher.
When writing tests against functionality that uses this method, be sure to wait for the Promise returned by {getWatcherPromise()} before manipulating the filesystem to ensure that the watcher is receiving events.
Argument | Description |
---|---|
callback(events) |
Function to be called with batches of filesystem events reported by the operating system. |
events |
An Array of objects that describe a batch of filesystem events. |
action |
String describing the filesystem action that occurred. One of |
path |
String containing the absolute path to the filesystem entry that was acted upon. |
oldPath |
For rename events, String containing the filesystem entry's former absolute path. |
Return values |
---|
Returns a Disposable to manage this event subscription. |
Accessing the git repository
::getRepositories()
Get an Array of GitRepositorys associated with the project's directories.
::repositoryForDirectory(directory)
Get the repository for a given directory asynchronously.
Argument | Description |
---|---|
directory |
Directory for which to get a |
Return values |
---|
Returns a Promise that resolves with either:
|
Managing Paths
::addPath(projectPath)
Add a path to the project's list of root paths
Argument | Description |
---|---|
projectPath |
String The path to the directory to add. |
::getWatcherPromise(projectPath)
Access a Promise that resolves when the filesystem watcher associated with a project root directory is ready to begin receiving events.
This is especially useful in test cases, where it's important to know that the watcher is ready before manipulating the filesystem to produce events.
Argument | Description |
---|---|
projectPath |
String One of the project's root directories. |
Return values |
---|
Returns a Promise that resolves with the PathWatcher associated with this project root
once it has initialized and is ready to start sending events. The Promise will reject with
an error instead if |
::removePath(projectPath)
remove a path from the project's list of root paths.
Argument | Description |
---|---|
projectPath |
String The path to remove. |
::relativizePath(fullPath)
::contains(pathToCheck)
Determines whether the given path (real or symbolic) is inside the project's directory.
This method does not actually check if the path exists, it just checks their locations relative to each other.
Basic operation
# Project's root directory is /foo/barprojectcontains'/foo/bar/baz' # => trueprojectcontains'/usr/lib/baz' # => false
Existence of the path is not required
# Project's root directory is /foo/barfsexistsSync'/foo/bar/baz' # => falseprojectcontains'/foo/bar/baz' # => true
Argument | Description |
---|---|
pathToCheck |
String path |
Return values |
---|
Returns whether the path is inside the project's root directory. |