UNPKG

3.3 kBTypeScriptView Raw
1import {
2 ConfigValues,
3 Directory,
4 Disposable,
5 FilesystemChangeEvent,
6 GitRepository,
7 PathWatcher,
8 TextBuffer,
9} from "../index";
10
11/** Represents a project that's opened in Atom. */
12export interface Project {
13 // Event Subscription
14 /** Invoke the given callback when the project paths change. */
15 onDidChangePaths(callback: (projectPaths: string[]) => void): Disposable;
16
17 /** Invoke the given callback when a text buffer is added to the project. */
18 onDidAddBuffer(callback: (buffer: TextBuffer) => void): Disposable;
19
20 /**
21 * Invoke the given callback with all current and future text buffers in
22 * the project.
23 */
24 observeBuffers(callback: (buffer: TextBuffer) => void): Disposable;
25
26 /** Invoke a callback when a filesystem change occurs within any open project path. */
27 onDidChangeFiles(callback: (events: FilesystemChangeEvent) => void): Disposable;
28
29 /** Invoke a callback whenever the project's configuration has been replaced. */
30 onDidReplace(callback: (projectSpec: ProjectSpecification | null | undefined) => void): Disposable;
31
32 // Accessing the Git Repository
33 /**
34 * Get an Array of GitRepositorys associated with the project's directories.
35 *
36 * This method will be removed in 2.0 because it does synchronous I/O.
37 */
38 getRepositories(): GitRepository[];
39
40 /** Invoke the given callback with all current and future repositories in the project. */
41 observeRepositories(callback: (repository: GitRepository) => void): Disposable;
42
43 /** Invoke the given callback when a repository is added to the project. */
44 onDidAddRepository(callback: (repository: GitRepository) => void): Disposable;
45
46 /** Get the repository for a given directory asynchronously. */
47 repositoryForDirectory(directory: Directory): Promise<GitRepository | null>;
48
49 // Managing Paths
50 /** Get an Array of strings containing the paths of the project's directories. */
51 getPaths(): string[];
52
53 /** Set the paths of the project's directories. */
54 setPaths(projectPaths: string[]): void;
55
56 /** Add a path to the project's list of root paths. */
57 addPath(projectPath: string): void;
58
59 /**
60 * Access a promise that resolves when the filesystem watcher associated with a
61 * project root directory is ready to begin receiving events.
62 */
63 getWatcherPromise(projectPath: string): Promise<PathWatcher>;
64
65 /** Remove a path from the project's list of root paths. */
66 removePath(projectPath: string): void;
67
68 /** Get an Array of Directorys associated with this project. */
69 getDirectories(): Directory[];
70
71 /** Get the relative path from the project directory to the given path. */
72 relativize(fullPath: string): string;
73
74 /**
75 * Get the path to the project directory that contains the given path, and
76 * the relative path from that project directory to the given path.
77 */
78 relativizePath(fullPath: string): [string | null, string];
79
80 /**
81 * Determines whether the given path (real or symbolic) is inside the
82 * project's directory.
83 */
84 contains(pathToCheck: string): boolean;
85}
86
87export interface ProjectSpecification {
88 paths: string[];
89 originPath: string;
90 config?: ConfigValues | undefined;
91}