From 0673c5181e5f132d81982c0e225fda767ebb2c62 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:32:25 -0500 Subject: [PATCH 01/15] feat: add atom flow types from nuclide Extention renamed to js --- nuclide/types/atom.js | 2253 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2253 insertions(+) create mode 100644 nuclide/types/atom.js diff --git a/nuclide/types/atom.js b/nuclide/types/atom.js new file mode 100644 index 00000000..39b603b0 --- /dev/null +++ b/nuclide/types/atom.js @@ -0,0 +1,2253 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the LICENSE file in + * the root directory of this source tree. + * + * @flow + */ + +/** + * Private Classes + */ + +// Octicons v4.4.0. List extracted from the atom-styleguide package. +type atom$Octicon = 'alert' | 'alignment-align' | 'alignment-aligned-to' | 'alignment-unalign' | + 'arrow-down' | 'arrow-left' | 'arrow-right' | 'arrow-small-down' | 'arrow-small-left' | + 'arrow-small-right' | 'arrow-small-up' | 'arrow-up' | 'beaker' | 'beer' | 'bell' | 'bold' | + 'book' | 'bookmark' | 'briefcase' | 'broadcast' | 'browser' | 'bug' | 'calendar' | 'check' | + 'checklist' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'chevron-up' | 'circle-slash' | + 'circuit-board' | 'clippy' | 'clock' | 'cloud-download' | 'cloud-upload' | 'code' | 'color-mode' | + 'comment' | 'comment-add' | 'comment-discussion' | 'credit-card' | 'dash' | 'dashboard' | + 'database' | 'desktop-download' | 'device-camera' | 'device-camera-video' | 'device-desktop' | + 'device-mobile' | 'diff' | 'diff-added' | 'diff-ignored' | 'diff-modified' | 'diff-removed' | + 'diff-renamed' | 'ellipses' | 'ellipsis' | 'eye' | 'eye-unwatch' | 'eye-watch' | 'file' | + 'file-add' | 'file-binary' | 'file-code' | 'file-directory' | 'file-directory-create' | + 'file-media' | 'file-pdf' | 'file-submodule' | 'file-symlink-directory' | 'file-symlink-file' | + 'file-text' | 'file-zip' | 'flame' | 'fold' | 'gear' | 'gift' | 'gist' | 'gist-fork' | + 'gist-new' | 'gist-private' | 'gist-secret' | 'git-branch' | 'git-branch-create' | + 'git-branch-delete' | 'git-commit' | 'git-compare' | 'git-fork-private' | 'git-merge' | + 'git-pull-request' | 'git-pull-request-abandoned' | 'globe' | 'grabber' | 'graph' | 'heart' | + 'history' | 'home' | 'horizontal-rule' | 'hourglass' | 'hubot' | 'inbox' | 'info' | + 'issue-closed' | 'issue-opened' | 'issue-reopened' | 'italic' | 'jersey' | 'jump-down' | + 'jump-left' | 'jump-right' | 'jump-up' | 'key' | 'keyboard' | 'law' | 'light-bulb' | 'link' | + 'link-external' | 'list-ordered' | 'list-unordered' | 'location' | 'lock' | 'log-in' | 'log-out' | + 'logo-gist' | 'logo-github' | 'mail' | 'mail-read' | 'mail-reply' | 'mark-github' | 'markdown' | + 'megaphone' | 'mention' | 'microscope' | 'milestone' | 'mirror' | 'mirror-private' | + 'mirror-public' | 'mortar-board' | 'move-down' | 'move-left' | 'move-right' | 'move-up' | 'mute' | + 'no-newline' | 'octoface' | 'organization' | 'package' | 'paintcan' | 'pencil' | 'person' | + 'person-add' | 'person-follow' | 'pin' | 'playback-fast-forward' | 'playback-pause' | + 'playback-play' | 'playback-rewind' | 'plug' | 'plus-small' | 'plus' | 'podium' | + 'primitive-dot' | 'primitive-square' | 'pulse' | 'puzzle' | 'question' | 'quote' | 'radio-tower' | + 'remove-close' | 'reply' | 'repo' | 'repo-clone' | 'repo-create' | 'repo-delete' | + 'repo-force-push' | 'repo-forked' | 'repo-pull' | 'repo-push' | 'repo-sync' | 'rocket' | 'rss' | + 'ruby' | 'screen-full' | 'screen-normal' | 'search' | 'search-save' | 'server' | 'settings' | + 'shield' | 'sign-in' | 'sign-out' | 'smiley' | 'split' | 'squirrel' | 'star' | 'star-add' | + 'star-delete' | 'steps' | 'stop' | 'sync' | 'tag' | 'tag-add' | 'tag-remove' | 'tasklist' | + 'telescope' | 'terminal' | 'text-size' | 'three-bars' | 'thumbsdown' | 'thumbsup' | 'tools' | + 'trashcan' | 'triangle-down' | 'triangle-left' | 'triangle-right' | 'triangle-up' | 'type-array'| + 'type-boolean'| 'type-class'| 'type-constant'| 'type-constructor'| 'type-enum'| 'type-field'| + 'type-file'| 'type-function'| 'type-interface'| 'type-method'| 'type-module'| 'type-namespace'| + 'type-number'| 'type-package'| 'type-property'| 'type-string'| 'type-variable' | 'unfold' | + 'unmute' | 'unverified' | 'verified' | 'versions' | 'watch' | 'x' | 'zap'; + +type atom$PaneLocation = 'left' | 'right' | 'bottom' | 'center'; + +declare type atom$Color = { + // Returns a String in the form '#abcdef'. + toHexString(): string; + // Returns a String in the form 'rgba(25, 50, 75, .9)'. + toRGBAString(): string; +} + +declare class atom$Model { + destroy(): void, + isDestroyed(): boolean, +} + +declare class atom$Package { + path: string, + activateTime: number, + mainModule: any, + mainModulePath: string, + metadata: Object, + name: string, + loadTime: number, + getType(): 'atom' | 'textmate' | 'theme', + hasActivationCommands(): boolean, + hasActivationHooks(): boolean, + initializeTime: number, + getActivationHooks(): Array, + onDidDeactivate(cb: () => mixed): IDisposable, + activateNow(): void, + // Undocumented + bundledPackage: boolean, + getCanDeferMainModuleRequireStorageKey(): string, + initializeIfNeeded(): void, +} + +/** + * Essential Classes + */ + +declare type atom$CustomEvent = CustomEvent & { + originalEvent?: Event; +} + +type atom$CommandCallback = (event: atom$CustomEvent) => mixed; + +type atom$CommandDescriptor = { + name: string, + displayName: string, + description?: string, + hiddenInCommandPalette?: boolean, + tags?: Array, +}; + +type atom$CommandListener = atom$CommandCallback | { + displayName?: string, + description?: string, + didDispatch: atom$CommandCallback, +}; + +declare class atom$CommandRegistry { + // Methods + add( + target: string | HTMLElement, + commandNameOrCommands: string | {[commandName: string]: atom$CommandListener}, + listener?: atom$CommandListener, + throwOnInvalidSelector?: boolean, + ): IDisposable, + dispatch(target: HTMLElement, commandName: string, detail?: Object): void, + onDidDispatch(callback: (event: atom$CustomEvent) => mixed): IDisposable, + onWillDispatch(callback: (event: atom$CustomEvent) => mixed): IDisposable, + findCommands(opts: {target: Node}): Array, +} + +declare class atom$CompositeDisposable { + constructor(...disposables: Array): void, + dispose(): void, + + add(...disposables: Array): void, + remove(disposable: IDisposable): void, + clear(): void, +} + +type atom$ConfigParams = { + saveCallback?: Object => void, + mainSource?: string, + projectHomeSchema?: atom$ConfigSchema, +}; + +type atom$ConfigType = + 'boolean' | 'string' | 'integer' | 'number' | + 'array' | 'object' | 'color' | 'any'; + +type atom$ConfigSchema = { + default?: mixed, + description?: string, + enum?: Array, + maximum?: number, + minimum?: number, + properties?: Object, + title?: string, + type: Array | atom$ConfigType, +}; + +declare class atom$Config { + defaultSettings: Object, + settings: Object, + + // Config Subscription + observe( + keyPath: string, + optionsOrCallback?: + | {scope?: atom$ScopeDescriptorLike} + | (value: mixed) => void, + callback?: (value: mixed) => mixed, + ): IDisposable, + + onDidChange( + keyPathOrCallback: + | string + | (event: {oldValue: mixed, newValue: mixed}) => mixed, + optionsOrCallback?: + | {scope?: atom$ScopeDescriptorLike} + | (event: {oldValue: mixed, newValue: mixed}) => mixed, + callback?: (event: {oldValue: mixed, newValue: mixed}) => mixed + ): IDisposable, + + // Managing Settings + get( + keyPath?: string, + options?: { + excludeSources?: Array, + sources?: Array, + scope?: atom$ScopeDescriptorLike, + } + ): mixed, + + set( + keyPath: string, + value: ?mixed, + options?: { + scopeSelector?: string, + source?: string, + }, + ): boolean, + + unset( + keyPath: string, + options?: { + scopeSelector?: string, + source?: string, + } + ): void, + + getUserConfigPath(): string, + + // Undocumented Methods + constructor(params?: atom$ConfigParams): atom$Config, + getRawValue(keyPath: ?string, options: {excludeSources?: string, sources?: string}): mixed, + getSchema(keyPath: string): atom$ConfigSchema, + save(): void, + setRawValue(keyPath: string, value: mixed): void, + setSchema( + keyPath: string, + schema: atom$ConfigSchema, + ): void, + removeAtKeyPath(keyPath: ?string, value: ?mixed): mixed, + + // Used by nuclide-config to set the initial settings from disk + resetUserSettings(newSettings: Object, options?: {source?: string}): void, +} + +declare class atom$Cursor { + // Cursor Marker + marker: atom$Marker; + editor: atom$TextEditor; + + // Event Subscription + onDidChangePosition( + callback: (event: { + oldBufferPosition: atom$Point, + oldScreenPosition: atom$Point, + newBufferPosition: atom$Point, + newScreenPosition: atom$Point, + textChanged: boolean, + Cursor: atom$Cursor, + }) => mixed, + ): IDisposable, + + // Managing Cursor Position + getBufferRow(): number, + getBufferColumn(): number, + getBufferPosition(): atom$Point, + + // Cursor Position Details + // Moving the Cursor + moveUp(rowCount: number, {moveToEndOfSelection?: boolean}): void, + moveDown(rowCount: number, {moveToEndOfSelection?: boolean}): void, + + // Local Positions and Ranges + getCurrentWordBufferRange(options?: {wordRegex: RegExp}): atom$Range, + getCurrentWordPrefix(): string, + + // Visibility + // Comparing to another cursor + // Utilities + wordRegExp(options?: {includeNonWordCharacters: boolean}): RegExp, +} + +declare class atom$Decoration { + destroy(): void, + onDidChangeProperties( + callback: (event: {oldProperties: Object, newProperties: Object}) => mixed + ): IDisposable, + onDidDestroy(callback: () => mixed): IDisposable, + getMarker(): atom$Marker, + getProperties(): Object, + setProperties(properties: mixed): void, +} + +declare class atom$DisplayMarkerLayer { + destroy(): void, + clear(): void, + isDestroyed(): boolean, + markBufferPosition(position: atom$PointLike, options?: MarkerOptions): atom$Marker, + markBufferRange(range: atom$Range | atom$RangeLike, options?: MarkerOptions): atom$Marker, + findMarkers(options: MarkerOptions): Array, + getMarkers(): Array, + onDidUpdate(callback: () => mixed): IDisposable +} + +declare class atom$LayerDecoration { + destroy(): void, + isDestroyed(): boolean, + getProperties(): Object, + setProperties(properties: mixed): void, + setPropertiesForMarker(marker: atom$Marker, properties: mixed): void, +} + +declare class atom$Disposable { + constructor(disposalAction?: (...args: Array) => any): void, + disposed: boolean, + dispose(): void, +} + +declare class atom$Emitter { + static onEventHandlerException(error: any): IDisposable, + dispose(): void, + on(name: string, callback: (v: any) => mixed): IDisposable, + once(name: string, callback: (v: any) => mixed): IDisposable, + preempt(name: string, callback: (v: any) => void): IDisposable, + // This is a flow hack to prevent emitting more than one value. + // `EventEmitter` allows emitting any number of values - making this a land + // mine, since we tend to think of `emit` as interchangeable. + // This hack only works if the extra value is not `undefined`, so this isn't + // full-proof, but it works for most cases. + emit(name: string, value: any, ...no_extra_args_allowed: Array): void, +} + +declare class atom$Gutter { + name: string, + destroy(): void, + decorateMarker( + marker: atom$Marker, + options?: {type?: string, 'class'?: string, item?: Object | HTMLElement}, + ): atom$Decoration, + show(): void, + hide(): void, + onDidDestroy(callback: () => void): IDisposable, +} + +declare type atom$MarkerChangeEvent = { + oldHeadScreenPosition: atom$Point, + newHeadScreenPosition: atom$Point, + oldTailScreenPosition: atom$Point, + newTailScreenPosition: atom$Point, + + oldHeadBufferPosition: atom$Point, + newHeadBufferPosition: atom$Point, + oldTailBufferPosition: atom$Point, + newTailBufferPosition: atom$Point, + + isValid: boolean, + textChanged: boolean, +} + +declare class atom$Marker { + destroy(): void, + getBufferRange(): atom$Range, + getStartBufferPosition(): atom$Point, + onDidChange(callback: (event: atom$MarkerChangeEvent) => mixed): IDisposable, + isValid(): boolean, + isDestroyed(): boolean, + onDidDestroy(callback: () => mixed): IDisposable, + getScreenRange(): atom$Range, + setBufferRange( + range: atom$RangeLike, + properties?: {reversed: boolean}, + ): void, + id: number, +} + +declare class atom$ServiceHub { + provide(keyPath: string, version: string, service: T): IDisposable, + consume( + keyPath: string, + versionRange: string, + callback: (provider: T) => mixed + ): IDisposable, +} + +type atom$PackageMetadata = { + name: string, + version: string, +}; + +declare class atom$PackageManager { + +initialPackagesActivated: boolean, + + // Event Subscription + onDidLoadInitialPackages(callback: () => void): IDisposable, + onDidActivateInitialPackages(callback: () => void): IDisposable, + onDidActivatePackage(callback: (pkg: atom$Package) => mixed): IDisposable, + onDidDeactivatePackage(callback: (pkg: atom$Package) => mixed): IDisposable, + onDidLoadPackage(callback: (pkg: atom$Package) => mixed): IDisposable, + onDidUnloadPackage(callback: (pkg: atom$Package) => mixed): IDisposable, + onDidTriggerActivationHook(activationHook: string, callback: () => mixed): IDisposable, + + // Package system data + getApmPath(): string, + getPackageDirPaths(): Array, + + // General package data + resolvePackagePath(name: string): ?string, + isBundledPackage(name: string): boolean, + + // Enabling and disabling packages + enablePackage(name: string): ?atom$Package, + disablePackage(name: string): ?atom$Package, + isPackageDisabled(name: string): boolean, + + // Accessing active packages + getActivePackage(name: string): ?atom$Package, + getActivePackages(): Array, + isPackageActive(name: string): boolean, + hasActivatedInitialPackages(): boolean, + + // Activating and deactivating packages + activatePackage(name: string): Promise, + + // Accessing loaded packages + getLoadedPackage(name: string): ?atom$Package, + getLoadedPackages(): Array, + isPackageLoaded(name: string): boolean, + hasLoadedInitialPackages(): boolean, + + // Accessing available packages + getAvailablePackageNames(): Array, + getAvailablePackageMetadata(): Array, + + // (Undocumented.) + activate(): Promise, + deactivatePackages(): Promise, + deactivatePackage(name: string, suppressSerialization?: boolean): Promise, + emitter: atom$Emitter, + loadedPackages: {[packageName: string]: atom$Package}, + loadPackage(name: string): void, + loadPackages(): void, + serializePackage(pkg: atom$Package): void, + serviceHub: atom$ServiceHub, + packageDirPaths: Array, + triggerActivationHook(hook: string): void, + triggerDeferredActivationHooks(): void, + unloadPackage(name: string): void, + unloadPackages(): void, +} + +declare class atom$StyleManager { + // Event Subscription + + // Reading Style Elements + getStyleElements(): Array, + + // Paths + getUserStyleSheetPath(): string, + + // (Undocumented.) + addStyleSheet( + source: string, + params: { + sourcePath?: string, + context?: boolean, + priority?: number, + skipDeprecatedSelectorsTransformation?: boolean + } + ): IDisposable, +} + +type atom$PaneSplitParams = { + copyActiveItem?: boolean, + items?: Array, +}; + +type atom$PaneSplitOrientation = 'horizontal' | 'vertical'; +type atom$PaneSplitSide = 'before' | 'after'; + +// Undocumented class +declare class atom$applicationDelegate { + focusWindow(): Promise, + open(params: { + pathsToOpen: Array, + newWindow?: boolean, + devMode?: boolean, + safeMode?: boolean, + }): void, + + // Used by nuclide-config to replicate atom.config saveCallback + setUserSettings(config: atom$Config, configFilePath: string): Promise; +} + +type atom$PaneParams = { + activeItem?: Object, + applicationDelegate: atom$applicationDelegate, + focused?: boolean, + container: Object, + config: atom$Config, + notificationManager: atom$NotificationManager, + deserializerManager: atom$DeserializerManager, + items?: Array, + itemStackIndices?: Array, + flexScale?: number, +}; + +declare class atom$Pane { + // Items + addItem(item: Object, options?: {index?: number, pending?: boolean}): Object, + getItems(): Array, + getActiveItem(): ?Object, + itemAtIndex(index: number): ?Object, + getActiveItemIndex(): number, + activateItem(item: Object): ?Object, + activateItemAtIndex(index: number): void, + moveItemToPane(item: Object, pane: atom$Pane, index: number): void, + destroyItem(item: Object, force?: boolean): Promise, + itemForURI(uri: string): Object, + + // Event subscriptions. + onDidAddItem(cb: (event: {item: Object, index: number}) => void): IDisposable, + onDidRemoveItem(cb: (event: {item: Object, index: number}) => void): IDisposable, + onWillRemoveItem(cb: (event: {item: Object, index: number}) => void): IDisposable, + onDidDestroy(cb: () => mixed): IDisposable, + onDidChangeFlexScale(cb: (newFlexScale: number) => void): IDisposable, + onWillDestroy(cb: () => void): IDisposable, + observeActiveItem(cb: (item: ?Object) => void): IDisposable, + + // Lifecycle + isActive(): boolean, + activate(): void, + destroy(): void, + isDestroyed(): void, + + // Splitting + splitLeft(params?: atom$PaneSplitParams): atom$Pane, + splitRight(params?: atom$PaneSplitParams): atom$Pane, + splitUp(params?: atom$PaneSplitParams): atom$Pane, + splitDown(params?: atom$PaneSplitParams): atom$Pane, + split( + orientation: atom$PaneSplitOrientation, + side: atom$PaneSplitSide, + params?: atom$PaneSplitParams, + ): atom$Pane, + + // Undocumented Methods + constructor(params: atom$PaneParams): atom$Pane, + getPendingItem(): atom$PaneItem, + setPendingItem(item: atom$PaneItem): void, + clearPendingItem(): void, + getFlexScale(): number, + getElement(): HTMLElement, + getParent(): Object, + removeItem(item: Object, moved: ?boolean): void, + setActiveItem(item: Object): Object, + setFlexScale(flexScale: number): number, + getContainer(): atom$PaneContainer, + getActiveEditor(): ?atom$TextEditor, + + element: HTMLElement, +} + +declare interface atom$PaneItem { + // These are all covariant, meaning that these props are read-only. Therefore we can assign an + // object with more strict requirements to an variable of this type. + +getTitle: () => string, + +getLongTitle?: () => string, + +getIconName?: () => string, + +getURI?: () => ?string, + +onDidChangeIcon?: (cb: (icon: string) => void) => IDisposable, + +onDidChangeTitle?: (cb: (title: string) => void) => IDisposable, + +onDidTerminatePendingState?: (() => mixed) => IDisposable; + +serialize?: () => Object, + +terminatePendingState?: () => void, +} + +// Undocumented class +declare class atom$PaneAxis { + getFlexScale(): number, + setFlexScale(flexScale: number): number, + getItems(): Array, +} + +// Undocumented class +// Note that this is not the same object returned by `atom.workspace.getPaneContainers()`. (Those +// are typed here as AbstractPaneContainers and, in the current implementation, wrap these.) +declare class atom$PaneContainer { + constructor({ + config: atom$Config, + applicationDelegate: atom$applicationDelegate, + notificationManager: atom$NotificationManager, + deserializerManager: atom$DeserializerManager, + }): atom$PaneContainer, + destroy(): void, + getActivePane(): atom$Pane, + getActivePaneItem(): ?Object, + getLocation(): atom$PaneLocation, + getPanes(): Array, + getPaneItems(): Array, + observePanes(cb: (pane: atom$Pane) => void): IDisposable, + onDidAddPane(cb: (event: {pane: atom$Pane}) => void): IDisposable, + onDidDestroyPane(cb: (event: {pane: atom$Pane}) => void): IDisposable, + onWillDestroyPane(cb: (event: {pane: atom$Pane}) => void): IDisposable, + onDidAddPaneItem(cb: (item: atom$PaneItem) => void): IDisposable, + onDidDestroyPaneItem(cb: (item: atom$Pane) => void): IDisposable, + paneForItem(item: Object): ?atom$Pane, + serialize(): Object, +} + +declare class atom$Panel { + // Construction and Destruction + destroy(): void, + + // Event Subscription + onDidChangeVisible(callback: (visible: boolean) => any): IDisposable, + onDidDestroy(callback: (panel: atom$Panel) => any): IDisposable, + + // Panel Details + getElement(): HTMLElement, + getItem(): any, + getPriority(): number, + isVisible(): boolean, + hide(): void, + show(): void, +} + +type atom$PointObject = {row: number, column: number}; + +type atom$PointLike = atom$Point +| [number, number] +| atom$PointObject; + +declare class atom$Point { + static fromObject(object: atom$PointLike, copy: ? boolean): atom$Point, + constructor(row: number, column: number): void, + row: number, + column: number, + copy(): atom$Point, + negate(): atom$Point, + + // Comparison + min(point1: atom$PointLike, point2: atom$PointLike): atom$Point, + compare(other: atom$PointLike): -1 | 0 | 1, + isEqual(otherRange: atom$PointLike): boolean, + isLessThan(other: atom$PointLike): boolean, + isLessThanOrEqual(other: atom$PointLike): boolean, + isGreaterThan(other: atom$PointLike): boolean, + isGreaterThanOrEqual(other: atom$PointLike): boolean, + + // Operations + translate(other: atom$PointLike): atom$Point, + + // Conversion + serialize(): [number, number], + toArray(): [number, number], +} + +type atom$RangeObject = { + start: atom$PointObject, + end: atom$PointObject, +}; + +type atom$RangeLike = atom$Range + | atom$RangeObject // TODO: Flow doesn't really handle the real signature below... + | [atom$PointLike, atom$PointLike] + | { + start: atom$PointLike, + end: atom$PointLike, + }; + +declare class atom$Range { + static fromObject( + object: atom$RangeLike, + copy?: boolean, + ): atom$Range, + static fromPointWithDelta( + startPoint: atom$PointLike, + rowDelta: number, + columnDelta: number + ): atom$Range, + + constructor(pointA: atom$PointLike, pointB: atom$PointLike): void, + compare(other: atom$Range): number, + start: atom$Point, + end: atom$Point, + isEmpty(): boolean, + isEqual(otherRange: atom$RangeLike): boolean, + isSingleLine(): boolean, + intersectsWith(otherRange: atom$RangeLike, exclusive?: boolean): boolean, + containsPoint(point: atom$PointLike, exclusive?: boolean): boolean, + containsRange(other: atom$Range, exclusive?: boolean): boolean, + union(other: atom$Range): atom$Range, + serialize(): Array>, + translate(startDelta: atom$PointLike, endDelta?: atom$PointLike): atom$Range, + getRowCount(): number, + getRows(): Array, +} + +type RawStatusBarTile = { + item: HTMLElement, + priority: number, +}; + +type atom$StatusBarTile = { + getPriority(): number, + getItem(): HTMLElement, + destroy(): void, +}; + +declare class atom$ScopeDescriptor { + constructor(object: {scopes: Array}): void, + getScopesArray(): Array, +} + +type atom$ScopeDescriptorLike = atom$ScopeDescriptor | Array; + +/** + * This API is defined at https://github.com/atom/status-bar. + */ +declare class atom$StatusBar { + addLeftTile(tile: RawStatusBarTile): atom$StatusBarTile, + addRightTile(tile: RawStatusBarTile): atom$StatusBarTile, + getLeftTiles(): Array, + getRightTiles(): Array, +} + +// https://github.com/atom/atom/blob/v1.9.0/src/text-editor-registry.coffee +declare class atom$TextEditorRegistry { + add(editor: atom$TextEditor): IDisposable, + remove(editor: atom$TextEditor): boolean, + observe(callback: (editor: atom$TextEditor) => void): IDisposable, + build: (params: atom$TextEditorParams) => atom$TextEditor, + + // Private + editors: Set, +} + +declare class atom$ThemeManager { + // Event Subscription + /** + * As recent as Atom 1.0.10, the implementation of this method was: + * + * ``` + * onDidChangeActiveThemes: (callback) -> + * @emitter.on 'did-change-active-themes', callback + * @emitter.on 'did-reload-all', callback # TODO: Remove once deprecated pre-1.0 APIs are gone + * ``` + * + * Due to the nature of CoffeeScript, onDidChangeActiveThemes returns a Disposable even though it + * is not documented as doing so. However, the Disposable that it does return removes the + * subscription on the 'did-reload-all' event (which is supposed to be deprecated) rather than the + * 'did-change-active-themes' one. + */ + onDidChangeActiveThemes(callback: () => mixed): IDisposable, + + // Accessing Loaded Themes + getLoadedThemeNames(): Array, + getLoadedThemes(): Array, // TODO: Define undocumented ThemePackage class. + + // Accessing Active Themes + getActiveThemeNames(): Array, + getActiveThemes(): Array, // TODO: Define undocumented ThemePackage class. + + // Managing Enabled Themes + getEnabledThemeNames(): Array, + + // Private + activateThemes(): Promise, + requireStylesheet(stylesheetPath: string): IDisposable, +} + +type atom$TooltipsPlacementOption = 'top' | 'bottom' | 'left' | 'right' | 'auto'; + +type atom$TooltipsAddOptions = { + title?: string, + item?: HTMLElement, + keyBindingCommand?: string, + keyBindingTarget?: HTMLElement, + animation?: boolean, + container?: string | false, + delay?: number | {show: number, hide: number}, + placement?: atom$TooltipsPlacementOption | () => atom$TooltipsPlacementOption, + trigger?: string, +}; + +type atom$Tooltip = { + show(): void; + hide(): void; + getTooltipElement(): HTMLElement, +}; + +declare class atom$TooltipManager { + tooltips: Map>; + add( + target: HTMLElement, + options: atom$TooltipsAddOptions, + ): IDisposable, + findTooltips(HTMLElement): Array, +} + +type InsertTextOptions = { + select: boolean, + autoIndent: boolean, + autoIndentNewline: boolean, + autoDecreaseIndent: boolean, + normalizeLineEndings: ?boolean, + undo: string, +}; + +type DecorateMarkerParams = { + type: 'line', + class: string, + onlyHead?: boolean, + onlyEmpty?: boolean, + onlyNonEmpty?: boolean, +} | { + type: 'gutter', + item?: HTMLElement, + class?: string, + onlyHead?: boolean, + onlyEmpty?: boolean, + onlyNonEmpty?: boolean, + gutterName?: string, +} | { + type: 'highlight', + class?: string, + gutterName?: string, +} | { + type: 'overlay', + item: Object, + position?: 'head' | 'tail', // Defaults to 'head' when unspecified. +} | { + type: 'block', + item: HTMLElement, + position?: 'before' | 'after', // Defaults to 'before' when unspecified. +} | { + type: 'line-number', + class?: string, +}; + +type ChangeCursorPositionEvent = { + oldBufferPosition: atom$Point, + oldScreenPosition: atom$Point, + newBufferPosition: atom$Point, + newScreenPosition: atom$Point, + textChanged: boolean, + cursor: atom$Cursor, +}; + +type MarkerOptions = { + reversed?: boolean, + tailed?: boolean, + invalidate?: 'never' | 'surround' | 'overlap' | 'inside' | 'touch', + exclusive?: boolean, +}; + +type atom$ChangeSelectionRangeEvent = {| + oldBufferRange: atom$Range, + oldScreenRange: atom$Range, + newBufferRange: atom$Range, + newScreenRange: atom$Range, + selection: atom$Selection, +|}; + +declare class atom$TextEditor extends atom$Model { + id: number, + verticalScrollMargin: number, + + // Event Subscription + onDidChange(callback: () => void): IDisposable, + onDidChangePath(callback: (newPath: string) => mixed): IDisposable, + onDidStopChanging(callback: () => mixed): IDisposable, + onDidChangeCursorPosition(callback: (event: ChangeCursorPositionEvent) => mixed): + IDisposable, + onDidAddCursor(callback: (cursor: atom$Cursor) => mixed): IDisposable; + onDidRemoveCursor(callback: (cursor: atom$Cursor) => mixed): IDisposable; + onDidDestroy(callback: () => mixed): IDisposable, + onDidSave(callback: (event: {path: string}) => mixed): IDisposable, + getBuffer(): atom$TextBuffer, + observeGrammar(callback: (grammar: atom$Grammar) => mixed): IDisposable, + onWillInsertText(callback: (event: {cancel: () => void, text: string}) => void): + IDisposable, + // Note that the range property of the event is undocumented. + onDidInsertText(callback: (event: {text: string, range: atom$Range}) => mixed): IDisposable, + onDidChangeSoftWrapped(callback: (softWrapped: boolean) => mixed): IDisposable, + onDidChangeSelectionRange(callback: (event: atom$ChangeSelectionRangeEvent) => mixed): IDisposable, + observeSelections(callback: (selection: atom$Selection) => mixed): IDisposable, + onDidAddSelection(callback: (selection: atom$Selection) => mixed): IDisposable, + + // File Details + getTitle: () => string, + getLongTitle(): string, + /** + * If you open Atom via Spotlight such that it opens with a tab named + * "untitled" that does not correspond to a file on disk, this will return + * null. + */ + getPath(): ?string, + getURI: () => ?string, + insertNewline(): void, + isModified: () => boolean, + isEmpty(): boolean, + getEncoding(): buffer$Encoding, + setEncoding(encoding: string): void, + getTabLength() : number, + getSoftTabs(): boolean, + getIconName(): string, + onDidChangeIcon(cb: (icon: string) => void): IDisposable, + onDidChangeTitle(cb: (title: string) => void): IDisposable, + + // File Operations + save(): Promise, + // DO NOT USE: Doesn't work with remote text buffers! + // saveAs(filePath: string): void, + + // Reading Text + getText(): string, + getTextInBufferRange(range: atom$RangeLike): string, + getLineCount(): number, + getScreenLineCount(): number, + getLastScreenRow(): number, + + // Mutating Text + setText(text: string, options?: InsertTextOptions): void, + setTextInBufferRange( + range: atom$RangeLike, + text: string, + options?: { + normalizeLineEndings?: boolean, + undo?: string, + }, + ): atom$Range, + insertText(text: string): Array | false, + mutateSelectedText(fn: (selection: atom$Selection, index: number) => void): void, + delete: () => void, + backspace: () => void, + duplicateLines: () => void, + + // History + createCheckpoint(): atom$TextBufferCheckpoint, + revertToCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean, + terminatePendingState(): void, + transact(fn: () => mixed, _: void): void, + transact(groupingInterval: number, fn: () => mixed): void, + onDidTerminatePendingState(() => mixed): IDisposable; + + // TextEditor Coordinates + screenPositionForBufferPosition( + bufferPosition: atom$PointLike, + options?: { + wrapBeyondNewlines?: boolean, + wrapAtSoftNewlines?: boolean, + screenLine?: boolean, + }, + ): atom$Point, + bufferPositionForScreenPosition( + screenPosition: atom$PointLike, + options?: { + wrapBeyondNewlines?: boolean, + wrapAtSoftNewlines?: boolean, + screenLine?: boolean, + }, + ): atom$Point, + getEofBufferPosition(): atom$Point, + getVisibleRowRange(): [number, number], + bufferRowForScreenRow(screenRow: number): number, + screenRangeForBufferRange(bufferRange: atom$RangeLike): atom$Range, + bufferRangeForBufferRow(bufferRow: number): atom$Range, + + // Decorations + decorateMarker(marker: atom$Marker, decorationParams: DecorateMarkerParams): atom$Decoration, + decorateMarkerLayer( + markerLayer: atom$DisplayMarkerLayer, + decorationParams: DecorateMarkerParams, + ): atom$LayerDecoration, + decorationsForScreenRowRange( + startScreenRow: number, + endScreenRow: number, + ): {[markerId: string]: Array}, + getDecorations(options?: {class?: string, type?: string}): Array, + + // Markers + addMarkerLayer(): atom$DisplayMarkerLayer, + getDefaultMarkerLayer(): atom$DisplayMarkerLayer, + markBufferPosition(position: atom$PointLike, options?: MarkerOptions): atom$Marker, + markBufferRange(range: atom$RangeLike, options?: MarkerOptions): atom$Marker, + markScreenRange(range: atom$RangeLike, options?: MarkerOptions): atom$Marker, + markScreenPosition(position: atom$PointLike, options?: MarkerOptions): atom$Marker, + findMarkers(options: MarkerOptions): Array, + getMarkerCount(): number, + + // Cursors + getCursors(): Array, + setCursorBufferPosition( + position: atom$PointLike, + options?: { + autoscroll?: boolean, + wrapBeyondNewlines?: boolean, + wrapAtSoftNewlines?: boolean, + screenLine?: boolean, + }): void, + getCursorBufferPosition(): atom$Point, + getCursorBufferPositions(): Array, + getCursorScreenPosition(): atom$Point, + getCursorScreenPositions(): Array, + getLastCursor(): atom$Cursor, + addCursorAtBufferPosition(point: atom$PointLike): atom$Cursor, + moveToBeginningOfLine(): void, + moveToEndOfLine(): void, + moveToBottom(): void, + + // Folds + foldCurrentRow(): void, + unfoldCurrentRow(): void, + foldBufferRow(bufferRow: number): void, + unfoldBufferRow(bufferRow: number): void, + + // Selections + getLastSelection(): atom$Selection, + getSelectedText(): string, + selectAll(): void, + getSelectedBufferRange(): atom$Range, + getSelectedBufferRanges(): Array, + getSelections(): Array, + selectToBufferPosition(point: atom$Point): void, + setSelectedBufferRange( + bufferRange: atom$RangeLike, + options?: { + reversed?: boolean, + preserveFolds?: boolean, + }, + ): void, + setSelectedBufferRanges( + bufferRanges: Array, + options?: { + reversed?: boolean, + preserveFolds?: boolean, + }, + ): void, + selectWordsContainingCursors(): void, + + // Folds + unfoldAll(): void, + + // Searching and Replacing + scanInBufferRange( + regex: RegExp, + range: atom$Range, + iterator: (foundMatch: { + match: mixed, + matchText: string, + range: atom$Range, + stop: () => mixed, + replace: (replaceWith: string) => mixed, + }) => mixed + ): void, + + scan( + regex: RegExp, + iterator: (foundMatch: { + match: RegExp$matchResult, + matchText: string, + range: atom$Range, + stop: () => mixed, + replace: (replaceWith: string) => mixed, + }) => mixed + ): void, + + // Tab Behavior + // Soft Wrap Behavior + // Indentation + indentationForBufferRow(bufferRow: number): number, + setTabLength(tabLength: number): void, + setSoftTabs(softTabs: boolean): void, + + lineTextForBufferRow(bufferRow: number): string, + lineTextForScreenRow(screenRow: number): string, + + // Grammars + getGrammar(): atom$Grammar, + setGrammar(grammar: ?atom$Grammar): void, + + // Clipboard Operations + pasteText: (options?: Object) => void, + copySelectedText: () => void, + + // Managing Syntax Scopes + getRootScopeDescriptor(): atom$ScopeDescriptor, + scopeDescriptorForBufferPosition( + bufferPosition: atom$PointLike, + ): atom$ScopeDescriptor, + + // Gutter + addGutter(options: { + name: string, + priority?: number, + visible?: boolean, + }): atom$Gutter, + observeGutters(callback: (gutter: atom$Gutter) => void): IDisposable, + getGutters(): Array, + gutterWithName(name: string): ?atom$Gutter, + + // Scrolling the TextEditor + scrollToBufferPosition( + position: atom$Point | [?number, ?number], + options?: {center?: boolean} + ): void, + scrollToScreenPosition( + position: atom$Point | [?number, ?number], + options?: {center?: boolean} + ): void, + scrollToScreenRange(screenRange: atom$Range, options?: {clip?: boolean}): void, + scrollToCursorPosition( + options?: {center?: boolean} + ): void, + scrollToBottom(): void, + scrollToTop(): void, + + // TextEditor Rendering + getPlaceholderText(): string, + setPlaceholderText(placeholderText: string): void, + + // This is undocumented, but Nuclide uses it in the AtomTextEditor wrapper. + setLineNumberGutterVisible(lineNumberGutterVisible: boolean): void, + + // Editor Options + setSoftWrapped(softWrapped: boolean): void, + + isFoldedAtBufferRow(row: number): boolean, + getLastBufferRow(): number, + + // Undocumented Methods + getElement(): atom$TextEditorElement, + getDefaultCharWidth(): number, + getLineHeightInPixels(): number, + moveToTop(): void, + tokenForBufferPosition(position: atom$Point | [?number, ?number]): atom$Token, + onDidConflict(callback: () => void): IDisposable, + serialize(): Object, + foldBufferRowRange(startRow: number, endRow: number): void, + getNonWordCharacters(position?: atom$PointLike): string, + scheduleComponentUpdate(): void, +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need to reach into this object + * via `atom$TextEditorElement` to do some things that we have no other way to do. + */ +declare class atom$TextEditorComponent { + domNode: HTMLElement, + scrollViewNode: HTMLElement, + presenter: atom$TextEditorPresenter, + refs: atom$TextEditorComponentRefs, + linesComponent: atom$LinesComponent, + // NOTE: This is typed as a property to allow overwriting. + startCursorBlinking: () => void, + stopCursorBlinking(): void, + pixelPositionForScreenPosition( + screenPosition: atom$Point, + clip?: boolean, + ): {top: number, left: number}, + screenPositionForMouseEvent(event: MouseEvent): atom$Point, + pixelPositionForMouseEvent( + event: MouseEvent, + linesClientRect?: {top: number, left: number, bottom: number, right: number}, + ): {top: number, left: number, bottom: number, right: number}, + invalidateBlockDecorationDimensions(decoration: atom$Decoration): void, + element: atom$TextEditorElement, + didFocus(): void, + setScrollTop(scrollTop: number): void, + getScrollTop(): number, + + setScrollLeft(scrollLeft: number): void, + getScrollLeft(): number, + updateSync(useScheduler?: boolean): void, +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need to reach into this object + * via `atom$TextEditorComponent` to do some things that we have no other way to do. + */ +declare class atom$TextEditorPresenter { + startBlinkingCursors: () => void, + stopBlinkingCursors(visible: boolean): void, + updateLineNumberGutterState(): void, +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need it to access + * the deepest dom element receiving DOM events. + */ +declare class atom$LinesComponent { + domNode: HTMLElement, + getDomNode(): HTMLElement, +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need it to access + * the deepest dom element receiving DOM events. + */ +declare class atom$TextEditorComponentRefs { + lineTiles: HTMLElement, +} + +/** + * This is not part of the official Atom 1.0 API, but it really should be. This is the element that + * is returned when you run `atom.views.getView()`. + */ +declare class atom$TextEditorElement extends HTMLElement { + component: ?atom$TextEditorComponent, + getModel(): atom$TextEditor, + setModel(model: atom$TextEditor): void, + pixelPositionForBufferPosition( + bufferPosition: atom$PointLike, + ): {top: number, left: number}, + pixelPositionForScreenPosition(screenPosition: atom$Point): { + left: number, + top: number, + }, + + setScrollTop(scrollTop: number): void, + getScrollTop(): number, + + setScrollLeft(scrollLeft: number): void, + getScrollLeft(): number, + + getScrollHeight(): number, + getHeight(): number, + + onDidChangeScrollTop(callback: (scrollTop: number) => mixed): IDisposable, + onDidChangeScrollLeft(callback: (scrollLeft: number) => mixed): IDisposable, + + // Called when the editor is attached to the DOM. + onDidAttach(callback: () => mixed): IDisposable, + // Called when the editor is detached from the DOM. + onDidDetach(callback: () => mixed): IDisposable, + + measureDimensions(): void, + + // Undocumented Methods + + // Returns a promise that resolves after the next update. + getNextUpdatePromise(): Promise, + + // `undefined` means no explicit width. `null` sets a zero width (which is almost certainly a + // mistake) so we don't allow it. + setWidth(width: number | void): void, +} + +declare class atom$ViewProvider { + modelConstructor: Function, +} + +declare class atom$ViewRegistry { + // Methods + addViewProvider( + modelConstructor: any, + createView?: (...args: Array) => ?HTMLElement + ): IDisposable, + getView(textEditor: atom$TextEditor): atom$TextEditorElement, + getView(notification: atom$Notification): HTMLElement, + getView(gutter: atom$Gutter): HTMLElement, + getView(panel: atom$Panel): HTMLElement, + getView(workspace: atom$Workspace): HTMLElement, + getView(object: Object): HTMLElement, + providers: Array, +} + +type atom$WorkspaceAddPanelOptions = { + item: Object, + visible?: boolean, + priority?: number, + className?: string, +}; + +type atom$TextEditorParams = { + buffer?: atom$TextBuffer, + lineNumberGutterVisible?: boolean, +}; + +type DestroyPaneItemEvent = { + item: atom$PaneItem, + pane: atom$Pane, + index: number, +}; + +type AddPaneItemEvent = { + item: atom$PaneItem, + pane: atom$Pane, + index: number, +}; + +type OnDidOpenEvent = { + uri: string, + item: mixed, + pane: atom$Pane, + index: number, +}; + +type AddTextEditorEvent = { + textEditor: atom$TextEditor, + pane: atom$Pane, + index: number, +}; + +type atom$WorkspaceOpenOptions = { + activatePane?: ?boolean, + activateItem?: ?boolean, + initialLine?: ?number, + initialColumn?: ?number, + pending?: ?boolean, + split?: ?string, + searchAllPanes?: ?boolean, + location?: atom$PaneLocation, +} + +declare class atom$Workspace { + // Event Subscription + observePanes(cb: (pane: atom$Pane) => void): IDisposable, + observeTextEditors(callback: (editor: atom$TextEditor) => mixed): IDisposable, + observeActiveTextEditor(callback: (editor: ?atom$TextEditor) => mixed): IDisposable, + onDidAddTextEditor(callback: (event: AddTextEditorEvent) => mixed): IDisposable, + onDidChangeActivePaneItem(callback: (item: mixed) => mixed): IDisposable, + onDidDestroyPaneItem(callback: (event: DestroyPaneItemEvent) => mixed): IDisposable, + onDidAddPaneItem(callback: (event: AddPaneItemEvent) => mixed): IDisposable, + observeActivePaneItem(callback: (item: ?mixed) => mixed): IDisposable, + onDidStopChangingActivePaneItem(callback: (item: ?mixed) => mixed): IDisposable, + observePaneItems(callback: (item: mixed) => mixed): IDisposable, + onWillDestroyPaneItem( + callback: (event: {item: mixed, pane: mixed, index: number}) => mixed + ): IDisposable, + onDidOpen(callback: (event: OnDidOpenEvent) => mixed): IDisposable, + + getElement(): HTMLElement, + + // Opening + open( + uri?: string, + options?: atom$WorkspaceOpenOptions, + ): Promise, + openURIInPane( + uri?: string, + pane: atom$Pane, + options?: { + initialLine?: number, + initialColumn?: number, + activePane?: boolean, + searchAllPanes?: boolean, + } + ): Promise, + isTextEditor(item: ?mixed): boolean, + /* Optional method because this was added post-1.0. */ + buildTextEditor: ((params: ?atom$TextEditorParams) => atom$TextEditor), + /* Optional method because this was added in 1.9.0 */ + handleGrammarUsed?: (grammar: atom$Grammar) => void, + reopenItem(): Promise, + addOpener(callback: (uri: string) => any): IDisposable, + hide(uriOrItem: string | Object): void, + toggle(uriOrItem: string | Object): void, + + // Pane Containers + getPaneContainers(): Array, + paneContainerForItem(item: ?mixed): ?atom$AbstractPaneContainer, + + // Pane Items + getPaneItems(): Array, + getActivePaneItem(): ?Object, + getActivePaneContainer(): atom$PaneContainer, + getTextEditors(): Array, + getActiveTextEditor(): ?atom$TextEditor, + createItemForURI(uri: string, options: atom$WorkspaceOpenOptions): atom$PaneItem, + + // Panes + getPanes(): Array, + getActivePane(): atom$Pane, + activateNextPane(): boolean, + activatePreviousPane(): boolean, + paneForURI(uri: string): atom$Pane, + paneForItem(item: mixed): ?atom$Pane, + paneContainers: {[location: atom$PaneLocation]: atom$AbstractPaneContainer}, + + // Panels + panelContainers: {[location: string]: atom$PanelContainer}, + getBottomPanels(): Array, + addBottomPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, + getLeftPanels(): Array, + addLeftPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, + getRightPanels(): Array, + addRightPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, + getTopPanels(): Array, + addTopPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, + getModalPanels(): Array, + addModalPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, + getHeaderPanels(): Array, + addHeaderPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, + + getLeftDock(): atom$Dock, + getRightDock(): atom$Dock, + getBottomDock(): atom$Dock, + getCenter(): atom$WorkspaceCenter, + + // Searching and Replacing + scan( + regex: RegExp, + options: { + paths?: Array, + onPathsSearched?: (numSearched: number) => mixed, + leadingContextLineCount?: number, + trailingContextLineCount?: number, + }, + iterator: ( + ?{ + filePath: string, + matches: Array<{ + leadingContextLines: Array, + lineText: string, + lineTextOffset: number, + range: atom$RangeLike, + matchText: string, + trailingContextLines: Array, + }>, + }, + Error, + ) => mixed, + ): Promise, + + destroyActivePaneItemOrEmptyPane(): void, + destroyActivePaneItem(): void, +} + +declare class atom$AbstractPaneContainer { + activate(): void, + getLocation(): atom$PaneLocation, + getElement(): HTMLElement, + isVisible(): boolean, + show(): void, + hide(): void, + getActivePane(): atom$Pane, + getPanes(): Array, + onDidAddPaneItem((item: {item: Object}) => void): IDisposable, + observePanes(cb: (pane: atom$Pane) => void): IDisposable, + state: { + size: number, + } +} + +declare class atom$Dock extends atom$AbstractPaneContainer { + // This is a woefully incomplete list, items can be added as needed from + // https://github.com/atom/atom/blob/master/src/dock.js + toggle(): void, +} + +declare class atom$WorkspaceCenter extends atom$AbstractPaneContainer { + activate(): void; + + // Pane Items + getPaneItems(): Array, + getActivePaneItem(): ?atom$PaneItem, + getTextEditors(): Array, + getActiveTextEditor(): ?atom$TextEditor, + + observeActivePaneItem(callback: atom$PaneItem => mixed): IDisposable; + onDidChangeActivePaneItem(callback: (item: mixed) => mixed): IDisposable; + onDidAddTextEditor( + callback: (item: { + textEditor: atom$TextEditor, + pane: atom$Pane, + index: number, + }) => mixed, + ): IDisposable; + // This should be removed soon anyway, it's currently deprecated. + paneContainer: Object; +} + +/** + * Extended Classes + */ + +declare class atom$BufferedNodeProcess { } + +declare class atom$BufferedProcess { + // Event Subscription + onWillThrowError( + callback: (errorObject: {error: Object, handle: mixed}) => mixed + ): IDisposable, + // Helper Methods + kill(): void, +} + +declare class atom$Clipboard { + // Methods + write(text: string, metadata?: mixed): void, + read(): string, + readWithMetadata(): { + metadata: ?mixed, + text: string, + }, +} + +declare class atom$ContextMenuManager { + add(itemsBySelector: {[cssSelector: string]: Array}): IDisposable, + itemSets: Array, + + // Undocumented methods + showForEvent(event: Event): void, + templateForEvent(event: Event): Array, +} + +declare class atom$ContextMenuItemSet { + items: Array, + selector: string, +} + +type atom$ContextMenuItem = { + command?: string, + created?: (event: MouseEvent) => void, + enabled?: boolean, + label?: string, + shouldDisplay?: (event: MouseEvent) => boolean, + submenu?: Array, + type?: string, + visible?: boolean, +}; + +type atom$Deserializer = { + name: string, + deserialize: (state: Object) => mixed, +}; + +declare class atom$DeserializerManager { + add(...deserializers: Array): IDisposable, + deserialize(state: Object, params?: Object): mixed, +} + +// Apparently it can sometimes include a `code` property. +declare class atom$GetEntriesError extends Error { + code?: string, +} + +declare class atom$Directory { + constructor(dirname?: string): atom$Directory, + + symlink: boolean, + + // Construction + create(mode?: number): Promise, + + // Event Subscription + onDidChange(callback: () => mixed): IDisposable, + + // Directory Metadata + isFile(): boolean, + isDirectory(): boolean, + exists():Promise, + + // Managing Paths + getPath(): string, + getBaseName(): string, + relativize(fullPath: string): string, + + // Event Subscription + onDidRename(callback: () => void): IDisposable, + onDidDelete(callback: () => void): IDisposable, + + // Traversing + getParent(): atom$Directory, + getFile(filename: string): atom$File, + getSubdirectory(dirname: string): atom$Directory, + getEntries( + callback: ( + error: ?atom$GetEntriesError, + entries: ?Array, + ) => mixed): void, + contains(path: string): boolean, +} + +// These are the methods called on a file by atom-text-buffer +interface atom$Fileish { + existsSync(): boolean, + setEncoding(encoding: string): void, + getEncoding(): ?string, + + onDidRename(callback: () => void): IDisposable, + onDidDelete(callback: () => void): IDisposable, + onDidChange(callback: () => void): IDisposable, + onWillThrowWatchError(callback: () => mixed): IDisposable, + + getPath(): string, + getBaseName(): string, + + createReadStream(): stream$Readable, + createWriteStream(): stream$Writable, +} + +declare class atom$File /* implements atom$Fileish */ { + constructor(filePath?: string, symlink?: boolean): atom$File, + + symlink: boolean, + + // Construction + create(): Promise, + + // File Metadata + isFile(): boolean, + isDirectory(): boolean, + exists(): Promise, + existsSync(): boolean, + setEncoding(encoding: string): void, + getEncoding(): string, + + // Event Subscription + onDidRename(callback: () => void): IDisposable, + onDidDelete(callback: () => void): IDisposable, + onDidChange(callback: () => void): IDisposable, + onWillThrowWatchError(callback: () => mixed): IDisposable, + + // Managing Paths + getPath(): string, + getBaseName(): string, + + // Traversing + getParent(): atom$Directory, + + // Reading and Writing + read(flushCache?: boolean): Promise, + write(text: string): Promise, + writeSync(text: string): void, + createReadStream(): stream$Readable, + createWriteStream(): stream$Writable, +} + +declare class atom$GitRepository extends atom$Repository { + // Unofficial API. + statuses: {[filePath: string]: number}, + // Return the `git-utils` async repo. + getRepo(): atom$GitRepositoryInternal, +} + +declare class atom$Grammar { + name: string, + scopeName: string, + tokenizeLines(text: string): Array>, + tokenizeLine(line: string, ruleStack: mixed, firstLine: boolean): { + line: string, + tags: Array, + // Dynamic property: invoking it will incur additional overhead + tokens: Array, + ruleStack: mixed + }, +} + +type atom$GrammarToken = { + value: string, + scopes: Array, +}; + +declare class atom$GrammarRegistry { + // Event Subscription + onDidAddGrammar(callback: (grammar: atom$Grammar) => void): IDisposable, + + // Managing Grammars + grammarForScopeName(scopeName: string): ?atom$Grammar, + removeGrammarForScopeName(scopeName: string): ?atom$Grammar, + loadGrammarSync(grammarPath: string): atom$Grammar, + selectGrammar(filePath: string, fileContents: string): atom$Grammar, + autoAssignLanguageMode(buffer: atom$TextBuffer): void, + assignLanguageMode(buffer: atom$TextBuffer, languageId: string): void, + + // Extended + getGrammarScore(grammar: atom$Grammar, filePath: string, contents?: string): number, + forEachGrammar(callback: (grammar: atom$Grammar) => mixed): void, + + // Private API + clear(): IDisposable, +} + +declare class atom$HistoryManager { + removeProject(paths: Array): void, + getProjects(): Array, +} + +declare class atom$HistoryProject { + get paths(): Array; + get lastOpened(): Date; +} + +// https://github.com/atom/atom-keymap/blob/18f00ac307de5770bb8f98958bd9a13ecffa9e68/src/key-binding.coffee +declare class atom$KeyBinding { + cachedKeyups: ?Array, + command: string, + index: number, + keystrokeArray : Array, + keystrokeCount: number, + keystrokes: string, + priority: number, + selector: string, + source: string, + specificity: number, + + matches(keystroke: string): boolean, + compare(keybinding: atom$KeyBinding): number, + getKeyups(): ?Array, + matchesKeystrokes(userKeystrokes: Array): boolean | 'exact' | 'partial' | 'pendingKeyup', +} + +declare class atom$KeymapManager { + // Event Subscription + onDidMatchBinding(callback: (event: { + keystrokes: string, + binding: atom$KeyBinding, + keyboardEventTarget: HTMLElement, + }) => mixed): IDisposable, + + onDidPartiallyMatchBinding(callback: (event: { + keystrokes: string, + partiallyMatchedBindings: atom$KeyBinding, + keyboardEventTarget: HTMLElement, + }) => mixed): IDisposable, + + onDidFailToMatchBinding(callback: (event: { + keystrokes: string, + partiallyMatchedBindings: atom$KeyBinding, + keyboardEventTarget: HTMLElement, + }) => mixed): IDisposable, + + onDidFailToReadFile(callback: (error: { + message: string, + stack: string, + }) => mixed): IDisposable, + + // Adding and Removing Bindings + add(source: string, bindings: Object): IDisposable, + removeBindingsFromSource(source: string): void, + + // Accessing Bindings + getKeyBindings(): Array, + findKeyBindings(params: { + keystrokes?: string, + command?: string, + target?: HTMLElement, + }): Array, + + // Managing Keymap Files + loadKeymap(path: string, options?: {watch: boolean}): void, + watchKeymap(path: string): void, + + // Managing Keyboard Events + handleKeyboardEvent(event: Event): void, + keystrokeForKeyboardEvent(event: Event): string, + getPartialMatchTimeout(): number, + + static buildKeydownEvent( + key: string, + options: { + target: HTMLElement, + alt?: boolean, + cmd?: boolean, + ctrl?: boolean, + shift?: boolean, + }, + ): Event, +} + +declare class atom$MenuManager { + add(items: Array): IDisposable, + update(): void, + + // Private API + template: Array, +} + +type atom$ProjectSpecification = { + originPath: string, + paths?: Array, + config?: {[string]: mixed} +}; + +declare class atom$Project { + // Event Subscription + onDidChangePaths(callback: (projectPaths: Array) => mixed): IDisposable, + onDidAddBuffer(callback: (buffer: atom$TextBuffer) => mixed): IDisposable, + onDidReplace((settings: atom$ProjectSpecification) => mixed): IDisposable, + observeBuffers(callback: (buffer: atom$TextBuffer) => mixed): IDisposable, + observeRepositories(callback: (repository: atom$Repository)=> mixed): IDisposable, + replace?: (newSettings: atom$ProjectSpecification) => void, + // Accessing the git repository + getRepositories(): Array, + repositoryForDirectory(directory: atom$Directory): Promise, + + // Managing Paths + getPaths(): Array, + addPath(projectPath: string, options?: { + emitEvent?: boolean, + exact?: boolean, + mustExist?: boolean, + }): void, + setPaths(paths: Array): void, + removePath(projectPath: string): void, + getDirectories(): Array, + relativizePath(relativizePath?: string): Array, // [projectPath: ?string, relativePath: string] + relativize(filePath: string): string, + contains(path: string): boolean, + + // Private API + findBufferForPath(path: string): ?atom$TextBuffer, + addBuffer(buffer: atom$TextBuffer): void, + removeBuffer(buffer: atom$TextBuffer): void, + getBuffers(): Array, +} + +type TextBufferScanIterator = (arg: { + match: Array, + matchText: string, + range: atom$Range, + stop(): void, + replace(replacement: string): void, +}) => void; + +// This happens to be a number but it would be better if the type could be entirely opaque. All you +// need to know is that if something needs a checkpoint you should only pass it values received from +// TextBuffer::createCheckpoint +type atom$TextBufferCheckpoint = number; + +// TextBuffer did-change/will-change +type atom$TextEditEvent = { + oldRange: atom$Range, + newRange: atom$Range, + oldText: string, + newText: string, +}; + +type atom$AggregatedTextEditEvent = { + changes: Array, +}; + +declare class atom$LanguageMode { + getLanguageId(): string, +} + +declare class atom$TextBuffer { + constructor(text?: string): atom$TextBuffer, + constructor(params?: { + filePath?: string, + text?: string, + }): atom$TextBuffer, + + file: ?atom$File, + + // Mixin + static deserialize: (state: Object, params: Object) => mixed, + static load: (file: string | atom$Fileish, params: Object) => Promise, + + setFile(file: atom$Fileish): void, + + // Events + onWillChange(callback: () => mixed): IDisposable, + onDidChangeText(callback: (event: atom$AggregatedTextEditEvent) => mixed): IDisposable, + onDidStopChanging(callback: () => mixed): IDisposable, + onDidConflict(callback: () => mixed): IDisposable, + onDidChangeModified(callback: () => mixed): IDisposable, + onDidUpdateMarkers(callback: () => mixed): IDisposable, + onDidCreateMarker(callback: () => mixed): IDisposable, + onDidChangePath(callback: () => mixed): IDisposable, + onDidChangeEncoding(callback: () => mixed): IDisposable, + onWillSave(callback: () => mixed): IDisposable, + onDidSave(callback: (event: {path: string}) => mixed): IDisposable, + onDidDelete(callback: () => mixed): IDisposable, + onWillReload(callback: () => mixed): IDisposable, + onDidReload(callback: () => mixed): IDisposable, + onDidDestroy(callback: () => mixed): IDisposable, + onWillThrowWatchError(callback: () => mixed): IDisposable, + + // File Details + // DO NOT USE (T21363106): Doesn't work with remote text buffers! + // setPath(filePath: string): void, + getPath(): ?string, + setEncoding(encoding: string): void, + getEncoding(): string, + getUri(): string, + getId(): string, + getLanguageMode(): atom$LanguageMode, + + // Reading Text + isEmpty(): boolean, + getText(): string, + getTextInRange(range: atom$RangeLike): string, + getLineCount(): number, + getLines(): Array, + getLastLine(): string, + lineForRow(row: number): string, + lineEndingForRow(row: number): string, + lineLengthForRow(row: number): number, + isRowBlank(row: number): boolean, + previousNonBlankRow(startRow: number): ?number, + nextNonBlankRow(startRow: number): ?number, + + // Mutating Text + setText: (text: string) => atom$Range, + setTextInRange(range: atom$RangeLike, text: string, options?: Object): atom$Range, + setTextViaDiff(text: string): void, + insert( + position: atom$Point, + text: string, + options?: { + normalizeLineEndings?: boolean, + undo?: string, + }, + ): atom$Range, + append(text: string, options: ?{ + normalizeLineEndings?: boolean, + undo?: string, + }): atom$Range, + delete(range: atom$Range): atom$Range, + deleteRows(startRow: number, endRow: number): atom$Range, + + // History + undo(): void, + redo(): void, + transact(fn: () => mixed, _: void): void, + transact(groupingInterval: number, fn: () => mixed): void, + clearUndoStack(): void, + createCheckpoint(): atom$TextBufferCheckpoint, + revertToCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean, + groupChangesSinceCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean, + // TODO describe the return type more precisely. + getChangesSinceCheckpoint(checkpoint: atom$TextBufferCheckpoint): Array, + + // Search And Replace + scan(regex: RegExp, iterator: TextBufferScanIterator): void, + scanInRange(regex: RegExp, range: atom$Range, iterator: TextBufferScanIterator): void, + backwardsScanInRange(regex: RegExp, range: atom$Range, iterator: TextBufferScanIterator): void, + + // Buffer Range Details + getLastRow(): number, + getRange(): atom$Range, + rangeForRow(row: number, includeNewLine?: boolean): atom$Range, + getLength(): number, + + // Position/Index mapping + characterIndexForPosition(position: atom$PointLike): number, + positionForCharacterIndex(index: number): atom$Point, + + // Buffer Operations + reload(): void, + load(): Promise, + save(): Promise, + + isInConflict(): boolean, + isModified(): boolean, + + // Private APIs + cachedDiskContents: ?string, + emitter: atom$Emitter, + refcount: number, + loaded: boolean, + wasModifiedBeforeRemove: boolean, + finishLoading(): atom$TextBuffer, + updateCachedDiskContents(flushCache?: boolean, callback?: () => mixed): Promise, + emitModifiedStatusChanged(changed: boolean): void, + destroy(): void, + isDestroyed(): boolean, + applyChange: () => void, + shouldDestroyOnFileDelete?: () => boolean, +} + +declare class atom$Notification { + // Event Subscription + onDidDismiss(callback: () => mixed): IDisposable, + onDidDisplay(callback: () => mixed): IDisposable, + + // Methods + getType(): string, + getMessage(): string, + getOptions(): Object, + dismiss(): void, + isDismissed(): boolean, +} + +type atom$NotificationButton = { + text: string, + className?: string, + onDidClick?: () => mixed, +}; + +type atom$NotificationOptions = { + detail?: string, + dismissable?: boolean, + description?: string, + icon?: string, + stack?: string, + buttons?: Array, +}; + +declare class atom$NotificationManager { + // Events + onDidAddNotification(callback: (notification: atom$Notification) => void): IDisposable, + + // Adding Notifications + add(type: string, message: string, options?: atom$NotificationOptions): atom$Notification, + addSuccess(message: string, options?: atom$NotificationOptions): atom$Notification, + addInfo(message: string, options?: atom$NotificationOptions): atom$Notification, + addWarning(message: string, options?: atom$NotificationOptions): atom$Notification, + addError(message: string, options?: atom$NotificationOptions): atom$Notification, + addFatalError(message: string, options?: atom$NotificationOptions): atom$Notification, + addNotification(notification: atom$Notification): atom$Notification, + + // Getting Notifications + getNotifications(): Array, +} + +// The items in this declaration are available off of `require('atom')`. +// This list is not complete. +declare module 'atom' { + declare var BufferedNodeProcess: typeof atom$BufferedNodeProcess; + declare var BufferedProcess: typeof atom$BufferedProcess; + declare var CompositeDisposable: typeof atom$CompositeDisposable; + declare var Directory: typeof atom$Directory; + declare var Disposable: typeof atom$Disposable; + declare var Emitter: typeof atom$Emitter; + declare var File: typeof atom$File; + declare var GitRepository: typeof atom$GitRepository; + declare var Notification: typeof atom$Notification; + declare var Point: typeof atom$Point; + declare var Range: typeof atom$Range; + declare var TextBuffer: typeof atom$TextBuffer; + declare var TextEditor: typeof atom$TextEditor; +} + +// Make sure that common types can be referenced without the `atom$` prefix +// in type declarations. +declare var Cursor: typeof atom$Cursor; +declare var Panel: typeof atom$Panel; +declare var TextEditor: typeof atom$TextEditor; + +type atom$UnhandledErrorEvent = { + originalError: Object, + message: string, + url: string, + line: number, + column: number, +}; + +// The properties of this type match the properties of the `atom` global. +// This list is not complete. +type AtomGlobal = { + // Properties + appVersion: string, + atomScriptMode: ?boolean, // Added by nuclide-atom-script. + clipboard: atom$Clipboard, + commands: atom$CommandRegistry, + config: atom$Config, + contextMenu: atom$ContextMenuManager, + applicationDelegate: atom$applicationDelegate, + deserializers: atom$DeserializerManager, + grammars: atom$GrammarRegistry, + history: atom$HistoryManager, + keymaps: atom$KeymapManager, + menu: atom$MenuManager, + notifications: atom$NotificationManager, + packages: atom$PackageManager, + styles: atom$StyleManager, + themes: atom$ThemeManager, + textEditors: atom$TextEditorRegistry, + tooltips: atom$TooltipManager, + views: atom$ViewRegistry, + workspace: atom$Workspace, + project: atom$Project, + devMode: boolean, + + // Event Subscription + onWillThrowError(callback: (event: atom$UnhandledErrorEvent) => mixed): IDisposable, + onDidThrowError(callback: (event: atom$UnhandledErrorEvent) => mixed): IDisposable, + whenShellEnvironmentLoaded(callback: () => mixed): IDisposable, + + // Atom Details + inDevMode(): boolean, + inSafeMode(): boolean, + inSpecMode(): boolean, + getVersion(): string, + isReleasedVersion(): boolean, + getWindowLoadTime(): number, + + // This is an undocumented way to reach the Electron BrowserWindow. + // Use `electron.remote.getCurrentWindow` instead. + getCurrentWindow: void, + + // Messaging the User + +confirm: + & (( + { + message: string, + detail?: string, + buttons?: Array, + }, + (number) => void, + ) => void) + // The synchronous form. You really shouldn't use this. + & (({ + message: string, + detailedMessage?: string, + buttons?: Array | {[buttonName: string]: () => mixed}, + }) => ?number), + + open(params: { + pathsToOpen?: Array, + newWindow?: boolean, + devMode?: boolean, + safeMode?: boolean, + }): void, + reload(): void, + + // Undocumented Methods + getConfigDirPath(): string, + showSaveDialogSync(options: Object): string, + loadState(): Promise, + getLoadSettings(): Object, +}; + +declare var atom: AtomGlobal; + +type RepositoryDidChangeStatusCallback = (event: {path: string, pathStatus: number}) => mixed; +type RepositoryLineDiff = { + oldStart: number, + newStart: number, + oldLines: number, + newLines: number, +}; + +// Taken from the interface of [`GitRepository`][1], which is also implemented by +// `HgRepositoryClient`. +// +// [1]: https://github.com/atom/atom/blob/v1.7.3/src/git-repository.coffee +declare class atom$Repository { + constructor(path: string, options?: {refreshOnWindowFocus?: boolean}): void, + + // Event Subscription + onDidChangeStatus: (callback: RepositoryDidChangeStatusCallback) => IDisposable, + onDidChangeStatuses: (callback: () => mixed) => IDisposable, + + // Repository Details + getType: () => string, + getPath: () => string, + getWorkingDirectory: () => string, + isProjectAtRoot: () => boolean, + relativize: (aPath: string) => string, + getOriginURL: (aPath: ?string) => ?string, + + // Reading Status + isPathModified: (aPath: string) => boolean, + isPathNew: (aPath: string) => boolean, + isPathIgnored: (aPath: string) => boolean, + getDirectoryStatus: (aPath: string) => number, + getPathStatus: (aPath: string) => number, + getCachedPathStatus: (aPath: string) => ?number, + isStatusModified: (status: number) => boolean, + isStatusNew: (status: number) => boolean, + refreshStatus: () => Promise, + + // Retrieving Diffs + getDiffStats: (filePath: string) => {added: number, deleted: number}, + getLineDiffs: (aPath: string, text: string) => Array, + + // Checking Out + checkoutHead: (aPath: string) => boolean, + checkoutReference: (reference: string, create: boolean) => Promise, + + // Event Subscription + onDidDestroy(callback: () => mixed): IDisposable, + isDestroyed(): boolean, +} + +declare class atom$GitRepositoryInternal { + // Reading Status + isStatusModified: (status: number) => boolean, + isStatusNew: (status: number) => boolean, + isStatusIgnored: (status: number) => boolean, + isStatusStaged: (status: number) => boolean, + isStatusDeleted: (status: number) => boolean, +} + +// One of text or snippet is required. +// TODO(hansonw): use a union + intersection type +type atom$AutocompleteSuggestion = { + text?: string, + snippet?: string, + displayText?: string, + replacementPrefix?: string, + type?: ?string, + leftLabel?: ?string, + leftLabelHTML?: ?string, + rightLabel?: ?string, + rightLabelHTML?: ?string, + className?: ?string, + iconHTML?: ?string, + description?: ?string, + descriptionMarkdown?: ?string, + descriptionMoreURL?: ?string, +}; + +type atom$AutocompleteRequest = { + editor: TextEditor, + bufferPosition: atom$Point, + scopeDescriptor: atom$ScopeDescriptor, + prefix: string, + activatedManually?: boolean, +}; + +type atom$AutocompleteProvider = { + +selector: string, + +getSuggestions: ( + request: atom$AutocompleteRequest, + ) => Promise> | ?Array, + +getSuggestionDetailsOnSelect?: ( + suggestion: atom$AutocompleteSuggestion + ) => Promise, + +disableForSelector?: string, + +inclusionPriority?: number, + +excludeLowerPriority?: boolean, + +suggestionPriority?: number, + +filterSuggestions?: boolean, + +disposable?: () => void, + +onDidInsertSuggestion?: ( + insertedSuggestion: atom$SuggestionInsertedRequest, + ) => void, +}; + +type atom$SuggestionInsertedRequest = { + +editor: atom$TextEditor, + +triggerPosition: atom$Point, + +suggestion: atom$AutocompleteSuggestion, +}; + +// https://github.com/atom/autocomplete-plus/blob/master/README.md#the-watcheditor-api +type atom$AutocompleteWatchEditor = ( + editor: atom$TextEditor, + labels?: Array, +) => IDisposable; + +// Undocumented API. +declare class atom$Token { + value: string, + matchesScopeSelector(selector: string): boolean, +} + +declare class atom$Selection { + clear(): void, + getText(): string, + getBufferRange(): atom$Range, + insertText( + text: string, + options?: { + select?: boolean, + autoIndent?: boolean, + autoIndentNewLine?: boolean, + autoDecreaseIdent?: boolean, + normalizeLineEndings?: boolean, + undo?: boolean, + }, + ): string, + isEmpty(): boolean, +} + +declare class atom$PanelContainer { + dock: atom$Dock, + element: HTMLElement, + emitter: atom$Emitter, + location: atom$PaneLocation, + panels: Array, + subscriptions: atom$CompositeDisposable, + viewRegistry: atom$ViewRegistry, + + getPanels(): Array, +}; From 2441920f6a6afa1b9d2408fc59a25873925b8eee Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:38:42 -0500 Subject: [PATCH 02/15] fix: convert to typescript using flow-to-ts --- nuclide/types/atom.js | 2253 ------------------------------------- nuclide/types/atom.ts | 2466 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2466 insertions(+), 2253 deletions(-) delete mode 100644 nuclide/types/atom.js create mode 100644 nuclide/types/atom.ts diff --git a/nuclide/types/atom.js b/nuclide/types/atom.js deleted file mode 100644 index 39b603b0..00000000 --- a/nuclide/types/atom.js +++ /dev/null @@ -1,2253 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the license found in the LICENSE file in - * the root directory of this source tree. - * - * @flow - */ - -/** - * Private Classes - */ - -// Octicons v4.4.0. List extracted from the atom-styleguide package. -type atom$Octicon = 'alert' | 'alignment-align' | 'alignment-aligned-to' | 'alignment-unalign' | - 'arrow-down' | 'arrow-left' | 'arrow-right' | 'arrow-small-down' | 'arrow-small-left' | - 'arrow-small-right' | 'arrow-small-up' | 'arrow-up' | 'beaker' | 'beer' | 'bell' | 'bold' | - 'book' | 'bookmark' | 'briefcase' | 'broadcast' | 'browser' | 'bug' | 'calendar' | 'check' | - 'checklist' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'chevron-up' | 'circle-slash' | - 'circuit-board' | 'clippy' | 'clock' | 'cloud-download' | 'cloud-upload' | 'code' | 'color-mode' | - 'comment' | 'comment-add' | 'comment-discussion' | 'credit-card' | 'dash' | 'dashboard' | - 'database' | 'desktop-download' | 'device-camera' | 'device-camera-video' | 'device-desktop' | - 'device-mobile' | 'diff' | 'diff-added' | 'diff-ignored' | 'diff-modified' | 'diff-removed' | - 'diff-renamed' | 'ellipses' | 'ellipsis' | 'eye' | 'eye-unwatch' | 'eye-watch' | 'file' | - 'file-add' | 'file-binary' | 'file-code' | 'file-directory' | 'file-directory-create' | - 'file-media' | 'file-pdf' | 'file-submodule' | 'file-symlink-directory' | 'file-symlink-file' | - 'file-text' | 'file-zip' | 'flame' | 'fold' | 'gear' | 'gift' | 'gist' | 'gist-fork' | - 'gist-new' | 'gist-private' | 'gist-secret' | 'git-branch' | 'git-branch-create' | - 'git-branch-delete' | 'git-commit' | 'git-compare' | 'git-fork-private' | 'git-merge' | - 'git-pull-request' | 'git-pull-request-abandoned' | 'globe' | 'grabber' | 'graph' | 'heart' | - 'history' | 'home' | 'horizontal-rule' | 'hourglass' | 'hubot' | 'inbox' | 'info' | - 'issue-closed' | 'issue-opened' | 'issue-reopened' | 'italic' | 'jersey' | 'jump-down' | - 'jump-left' | 'jump-right' | 'jump-up' | 'key' | 'keyboard' | 'law' | 'light-bulb' | 'link' | - 'link-external' | 'list-ordered' | 'list-unordered' | 'location' | 'lock' | 'log-in' | 'log-out' | - 'logo-gist' | 'logo-github' | 'mail' | 'mail-read' | 'mail-reply' | 'mark-github' | 'markdown' | - 'megaphone' | 'mention' | 'microscope' | 'milestone' | 'mirror' | 'mirror-private' | - 'mirror-public' | 'mortar-board' | 'move-down' | 'move-left' | 'move-right' | 'move-up' | 'mute' | - 'no-newline' | 'octoface' | 'organization' | 'package' | 'paintcan' | 'pencil' | 'person' | - 'person-add' | 'person-follow' | 'pin' | 'playback-fast-forward' | 'playback-pause' | - 'playback-play' | 'playback-rewind' | 'plug' | 'plus-small' | 'plus' | 'podium' | - 'primitive-dot' | 'primitive-square' | 'pulse' | 'puzzle' | 'question' | 'quote' | 'radio-tower' | - 'remove-close' | 'reply' | 'repo' | 'repo-clone' | 'repo-create' | 'repo-delete' | - 'repo-force-push' | 'repo-forked' | 'repo-pull' | 'repo-push' | 'repo-sync' | 'rocket' | 'rss' | - 'ruby' | 'screen-full' | 'screen-normal' | 'search' | 'search-save' | 'server' | 'settings' | - 'shield' | 'sign-in' | 'sign-out' | 'smiley' | 'split' | 'squirrel' | 'star' | 'star-add' | - 'star-delete' | 'steps' | 'stop' | 'sync' | 'tag' | 'tag-add' | 'tag-remove' | 'tasklist' | - 'telescope' | 'terminal' | 'text-size' | 'three-bars' | 'thumbsdown' | 'thumbsup' | 'tools' | - 'trashcan' | 'triangle-down' | 'triangle-left' | 'triangle-right' | 'triangle-up' | 'type-array'| - 'type-boolean'| 'type-class'| 'type-constant'| 'type-constructor'| 'type-enum'| 'type-field'| - 'type-file'| 'type-function'| 'type-interface'| 'type-method'| 'type-module'| 'type-namespace'| - 'type-number'| 'type-package'| 'type-property'| 'type-string'| 'type-variable' | 'unfold' | - 'unmute' | 'unverified' | 'verified' | 'versions' | 'watch' | 'x' | 'zap'; - -type atom$PaneLocation = 'left' | 'right' | 'bottom' | 'center'; - -declare type atom$Color = { - // Returns a String in the form '#abcdef'. - toHexString(): string; - // Returns a String in the form 'rgba(25, 50, 75, .9)'. - toRGBAString(): string; -} - -declare class atom$Model { - destroy(): void, - isDestroyed(): boolean, -} - -declare class atom$Package { - path: string, - activateTime: number, - mainModule: any, - mainModulePath: string, - metadata: Object, - name: string, - loadTime: number, - getType(): 'atom' | 'textmate' | 'theme', - hasActivationCommands(): boolean, - hasActivationHooks(): boolean, - initializeTime: number, - getActivationHooks(): Array, - onDidDeactivate(cb: () => mixed): IDisposable, - activateNow(): void, - // Undocumented - bundledPackage: boolean, - getCanDeferMainModuleRequireStorageKey(): string, - initializeIfNeeded(): void, -} - -/** - * Essential Classes - */ - -declare type atom$CustomEvent = CustomEvent & { - originalEvent?: Event; -} - -type atom$CommandCallback = (event: atom$CustomEvent) => mixed; - -type atom$CommandDescriptor = { - name: string, - displayName: string, - description?: string, - hiddenInCommandPalette?: boolean, - tags?: Array, -}; - -type atom$CommandListener = atom$CommandCallback | { - displayName?: string, - description?: string, - didDispatch: atom$CommandCallback, -}; - -declare class atom$CommandRegistry { - // Methods - add( - target: string | HTMLElement, - commandNameOrCommands: string | {[commandName: string]: atom$CommandListener}, - listener?: atom$CommandListener, - throwOnInvalidSelector?: boolean, - ): IDisposable, - dispatch(target: HTMLElement, commandName: string, detail?: Object): void, - onDidDispatch(callback: (event: atom$CustomEvent) => mixed): IDisposable, - onWillDispatch(callback: (event: atom$CustomEvent) => mixed): IDisposable, - findCommands(opts: {target: Node}): Array, -} - -declare class atom$CompositeDisposable { - constructor(...disposables: Array): void, - dispose(): void, - - add(...disposables: Array): void, - remove(disposable: IDisposable): void, - clear(): void, -} - -type atom$ConfigParams = { - saveCallback?: Object => void, - mainSource?: string, - projectHomeSchema?: atom$ConfigSchema, -}; - -type atom$ConfigType = - 'boolean' | 'string' | 'integer' | 'number' | - 'array' | 'object' | 'color' | 'any'; - -type atom$ConfigSchema = { - default?: mixed, - description?: string, - enum?: Array, - maximum?: number, - minimum?: number, - properties?: Object, - title?: string, - type: Array | atom$ConfigType, -}; - -declare class atom$Config { - defaultSettings: Object, - settings: Object, - - // Config Subscription - observe( - keyPath: string, - optionsOrCallback?: - | {scope?: atom$ScopeDescriptorLike} - | (value: mixed) => void, - callback?: (value: mixed) => mixed, - ): IDisposable, - - onDidChange( - keyPathOrCallback: - | string - | (event: {oldValue: mixed, newValue: mixed}) => mixed, - optionsOrCallback?: - | {scope?: atom$ScopeDescriptorLike} - | (event: {oldValue: mixed, newValue: mixed}) => mixed, - callback?: (event: {oldValue: mixed, newValue: mixed}) => mixed - ): IDisposable, - - // Managing Settings - get( - keyPath?: string, - options?: { - excludeSources?: Array, - sources?: Array, - scope?: atom$ScopeDescriptorLike, - } - ): mixed, - - set( - keyPath: string, - value: ?mixed, - options?: { - scopeSelector?: string, - source?: string, - }, - ): boolean, - - unset( - keyPath: string, - options?: { - scopeSelector?: string, - source?: string, - } - ): void, - - getUserConfigPath(): string, - - // Undocumented Methods - constructor(params?: atom$ConfigParams): atom$Config, - getRawValue(keyPath: ?string, options: {excludeSources?: string, sources?: string}): mixed, - getSchema(keyPath: string): atom$ConfigSchema, - save(): void, - setRawValue(keyPath: string, value: mixed): void, - setSchema( - keyPath: string, - schema: atom$ConfigSchema, - ): void, - removeAtKeyPath(keyPath: ?string, value: ?mixed): mixed, - - // Used by nuclide-config to set the initial settings from disk - resetUserSettings(newSettings: Object, options?: {source?: string}): void, -} - -declare class atom$Cursor { - // Cursor Marker - marker: atom$Marker; - editor: atom$TextEditor; - - // Event Subscription - onDidChangePosition( - callback: (event: { - oldBufferPosition: atom$Point, - oldScreenPosition: atom$Point, - newBufferPosition: atom$Point, - newScreenPosition: atom$Point, - textChanged: boolean, - Cursor: atom$Cursor, - }) => mixed, - ): IDisposable, - - // Managing Cursor Position - getBufferRow(): number, - getBufferColumn(): number, - getBufferPosition(): atom$Point, - - // Cursor Position Details - // Moving the Cursor - moveUp(rowCount: number, {moveToEndOfSelection?: boolean}): void, - moveDown(rowCount: number, {moveToEndOfSelection?: boolean}): void, - - // Local Positions and Ranges - getCurrentWordBufferRange(options?: {wordRegex: RegExp}): atom$Range, - getCurrentWordPrefix(): string, - - // Visibility - // Comparing to another cursor - // Utilities - wordRegExp(options?: {includeNonWordCharacters: boolean}): RegExp, -} - -declare class atom$Decoration { - destroy(): void, - onDidChangeProperties( - callback: (event: {oldProperties: Object, newProperties: Object}) => mixed - ): IDisposable, - onDidDestroy(callback: () => mixed): IDisposable, - getMarker(): atom$Marker, - getProperties(): Object, - setProperties(properties: mixed): void, -} - -declare class atom$DisplayMarkerLayer { - destroy(): void, - clear(): void, - isDestroyed(): boolean, - markBufferPosition(position: atom$PointLike, options?: MarkerOptions): atom$Marker, - markBufferRange(range: atom$Range | atom$RangeLike, options?: MarkerOptions): atom$Marker, - findMarkers(options: MarkerOptions): Array, - getMarkers(): Array, - onDidUpdate(callback: () => mixed): IDisposable -} - -declare class atom$LayerDecoration { - destroy(): void, - isDestroyed(): boolean, - getProperties(): Object, - setProperties(properties: mixed): void, - setPropertiesForMarker(marker: atom$Marker, properties: mixed): void, -} - -declare class atom$Disposable { - constructor(disposalAction?: (...args: Array) => any): void, - disposed: boolean, - dispose(): void, -} - -declare class atom$Emitter { - static onEventHandlerException(error: any): IDisposable, - dispose(): void, - on(name: string, callback: (v: any) => mixed): IDisposable, - once(name: string, callback: (v: any) => mixed): IDisposable, - preempt(name: string, callback: (v: any) => void): IDisposable, - // This is a flow hack to prevent emitting more than one value. - // `EventEmitter` allows emitting any number of values - making this a land - // mine, since we tend to think of `emit` as interchangeable. - // This hack only works if the extra value is not `undefined`, so this isn't - // full-proof, but it works for most cases. - emit(name: string, value: any, ...no_extra_args_allowed: Array): void, -} - -declare class atom$Gutter { - name: string, - destroy(): void, - decorateMarker( - marker: atom$Marker, - options?: {type?: string, 'class'?: string, item?: Object | HTMLElement}, - ): atom$Decoration, - show(): void, - hide(): void, - onDidDestroy(callback: () => void): IDisposable, -} - -declare type atom$MarkerChangeEvent = { - oldHeadScreenPosition: atom$Point, - newHeadScreenPosition: atom$Point, - oldTailScreenPosition: atom$Point, - newTailScreenPosition: atom$Point, - - oldHeadBufferPosition: atom$Point, - newHeadBufferPosition: atom$Point, - oldTailBufferPosition: atom$Point, - newTailBufferPosition: atom$Point, - - isValid: boolean, - textChanged: boolean, -} - -declare class atom$Marker { - destroy(): void, - getBufferRange(): atom$Range, - getStartBufferPosition(): atom$Point, - onDidChange(callback: (event: atom$MarkerChangeEvent) => mixed): IDisposable, - isValid(): boolean, - isDestroyed(): boolean, - onDidDestroy(callback: () => mixed): IDisposable, - getScreenRange(): atom$Range, - setBufferRange( - range: atom$RangeLike, - properties?: {reversed: boolean}, - ): void, - id: number, -} - -declare class atom$ServiceHub { - provide(keyPath: string, version: string, service: T): IDisposable, - consume( - keyPath: string, - versionRange: string, - callback: (provider: T) => mixed - ): IDisposable, -} - -type atom$PackageMetadata = { - name: string, - version: string, -}; - -declare class atom$PackageManager { - +initialPackagesActivated: boolean, - - // Event Subscription - onDidLoadInitialPackages(callback: () => void): IDisposable, - onDidActivateInitialPackages(callback: () => void): IDisposable, - onDidActivatePackage(callback: (pkg: atom$Package) => mixed): IDisposable, - onDidDeactivatePackage(callback: (pkg: atom$Package) => mixed): IDisposable, - onDidLoadPackage(callback: (pkg: atom$Package) => mixed): IDisposable, - onDidUnloadPackage(callback: (pkg: atom$Package) => mixed): IDisposable, - onDidTriggerActivationHook(activationHook: string, callback: () => mixed): IDisposable, - - // Package system data - getApmPath(): string, - getPackageDirPaths(): Array, - - // General package data - resolvePackagePath(name: string): ?string, - isBundledPackage(name: string): boolean, - - // Enabling and disabling packages - enablePackage(name: string): ?atom$Package, - disablePackage(name: string): ?atom$Package, - isPackageDisabled(name: string): boolean, - - // Accessing active packages - getActivePackage(name: string): ?atom$Package, - getActivePackages(): Array, - isPackageActive(name: string): boolean, - hasActivatedInitialPackages(): boolean, - - // Activating and deactivating packages - activatePackage(name: string): Promise, - - // Accessing loaded packages - getLoadedPackage(name: string): ?atom$Package, - getLoadedPackages(): Array, - isPackageLoaded(name: string): boolean, - hasLoadedInitialPackages(): boolean, - - // Accessing available packages - getAvailablePackageNames(): Array, - getAvailablePackageMetadata(): Array, - - // (Undocumented.) - activate(): Promise, - deactivatePackages(): Promise, - deactivatePackage(name: string, suppressSerialization?: boolean): Promise, - emitter: atom$Emitter, - loadedPackages: {[packageName: string]: atom$Package}, - loadPackage(name: string): void, - loadPackages(): void, - serializePackage(pkg: atom$Package): void, - serviceHub: atom$ServiceHub, - packageDirPaths: Array, - triggerActivationHook(hook: string): void, - triggerDeferredActivationHooks(): void, - unloadPackage(name: string): void, - unloadPackages(): void, -} - -declare class atom$StyleManager { - // Event Subscription - - // Reading Style Elements - getStyleElements(): Array, - - // Paths - getUserStyleSheetPath(): string, - - // (Undocumented.) - addStyleSheet( - source: string, - params: { - sourcePath?: string, - context?: boolean, - priority?: number, - skipDeprecatedSelectorsTransformation?: boolean - } - ): IDisposable, -} - -type atom$PaneSplitParams = { - copyActiveItem?: boolean, - items?: Array, -}; - -type atom$PaneSplitOrientation = 'horizontal' | 'vertical'; -type atom$PaneSplitSide = 'before' | 'after'; - -// Undocumented class -declare class atom$applicationDelegate { - focusWindow(): Promise, - open(params: { - pathsToOpen: Array, - newWindow?: boolean, - devMode?: boolean, - safeMode?: boolean, - }): void, - - // Used by nuclide-config to replicate atom.config saveCallback - setUserSettings(config: atom$Config, configFilePath: string): Promise; -} - -type atom$PaneParams = { - activeItem?: Object, - applicationDelegate: atom$applicationDelegate, - focused?: boolean, - container: Object, - config: atom$Config, - notificationManager: atom$NotificationManager, - deserializerManager: atom$DeserializerManager, - items?: Array, - itemStackIndices?: Array, - flexScale?: number, -}; - -declare class atom$Pane { - // Items - addItem(item: Object, options?: {index?: number, pending?: boolean}): Object, - getItems(): Array, - getActiveItem(): ?Object, - itemAtIndex(index: number): ?Object, - getActiveItemIndex(): number, - activateItem(item: Object): ?Object, - activateItemAtIndex(index: number): void, - moveItemToPane(item: Object, pane: atom$Pane, index: number): void, - destroyItem(item: Object, force?: boolean): Promise, - itemForURI(uri: string): Object, - - // Event subscriptions. - onDidAddItem(cb: (event: {item: Object, index: number}) => void): IDisposable, - onDidRemoveItem(cb: (event: {item: Object, index: number}) => void): IDisposable, - onWillRemoveItem(cb: (event: {item: Object, index: number}) => void): IDisposable, - onDidDestroy(cb: () => mixed): IDisposable, - onDidChangeFlexScale(cb: (newFlexScale: number) => void): IDisposable, - onWillDestroy(cb: () => void): IDisposable, - observeActiveItem(cb: (item: ?Object) => void): IDisposable, - - // Lifecycle - isActive(): boolean, - activate(): void, - destroy(): void, - isDestroyed(): void, - - // Splitting - splitLeft(params?: atom$PaneSplitParams): atom$Pane, - splitRight(params?: atom$PaneSplitParams): atom$Pane, - splitUp(params?: atom$PaneSplitParams): atom$Pane, - splitDown(params?: atom$PaneSplitParams): atom$Pane, - split( - orientation: atom$PaneSplitOrientation, - side: atom$PaneSplitSide, - params?: atom$PaneSplitParams, - ): atom$Pane, - - // Undocumented Methods - constructor(params: atom$PaneParams): atom$Pane, - getPendingItem(): atom$PaneItem, - setPendingItem(item: atom$PaneItem): void, - clearPendingItem(): void, - getFlexScale(): number, - getElement(): HTMLElement, - getParent(): Object, - removeItem(item: Object, moved: ?boolean): void, - setActiveItem(item: Object): Object, - setFlexScale(flexScale: number): number, - getContainer(): atom$PaneContainer, - getActiveEditor(): ?atom$TextEditor, - - element: HTMLElement, -} - -declare interface atom$PaneItem { - // These are all covariant, meaning that these props are read-only. Therefore we can assign an - // object with more strict requirements to an variable of this type. - +getTitle: () => string, - +getLongTitle?: () => string, - +getIconName?: () => string, - +getURI?: () => ?string, - +onDidChangeIcon?: (cb: (icon: string) => void) => IDisposable, - +onDidChangeTitle?: (cb: (title: string) => void) => IDisposable, - +onDidTerminatePendingState?: (() => mixed) => IDisposable; - +serialize?: () => Object, - +terminatePendingState?: () => void, -} - -// Undocumented class -declare class atom$PaneAxis { - getFlexScale(): number, - setFlexScale(flexScale: number): number, - getItems(): Array, -} - -// Undocumented class -// Note that this is not the same object returned by `atom.workspace.getPaneContainers()`. (Those -// are typed here as AbstractPaneContainers and, in the current implementation, wrap these.) -declare class atom$PaneContainer { - constructor({ - config: atom$Config, - applicationDelegate: atom$applicationDelegate, - notificationManager: atom$NotificationManager, - deserializerManager: atom$DeserializerManager, - }): atom$PaneContainer, - destroy(): void, - getActivePane(): atom$Pane, - getActivePaneItem(): ?Object, - getLocation(): atom$PaneLocation, - getPanes(): Array, - getPaneItems(): Array, - observePanes(cb: (pane: atom$Pane) => void): IDisposable, - onDidAddPane(cb: (event: {pane: atom$Pane}) => void): IDisposable, - onDidDestroyPane(cb: (event: {pane: atom$Pane}) => void): IDisposable, - onWillDestroyPane(cb: (event: {pane: atom$Pane}) => void): IDisposable, - onDidAddPaneItem(cb: (item: atom$PaneItem) => void): IDisposable, - onDidDestroyPaneItem(cb: (item: atom$Pane) => void): IDisposable, - paneForItem(item: Object): ?atom$Pane, - serialize(): Object, -} - -declare class atom$Panel { - // Construction and Destruction - destroy(): void, - - // Event Subscription - onDidChangeVisible(callback: (visible: boolean) => any): IDisposable, - onDidDestroy(callback: (panel: atom$Panel) => any): IDisposable, - - // Panel Details - getElement(): HTMLElement, - getItem(): any, - getPriority(): number, - isVisible(): boolean, - hide(): void, - show(): void, -} - -type atom$PointObject = {row: number, column: number}; - -type atom$PointLike = atom$Point -| [number, number] -| atom$PointObject; - -declare class atom$Point { - static fromObject(object: atom$PointLike, copy: ? boolean): atom$Point, - constructor(row: number, column: number): void, - row: number, - column: number, - copy(): atom$Point, - negate(): atom$Point, - - // Comparison - min(point1: atom$PointLike, point2: atom$PointLike): atom$Point, - compare(other: atom$PointLike): -1 | 0 | 1, - isEqual(otherRange: atom$PointLike): boolean, - isLessThan(other: atom$PointLike): boolean, - isLessThanOrEqual(other: atom$PointLike): boolean, - isGreaterThan(other: atom$PointLike): boolean, - isGreaterThanOrEqual(other: atom$PointLike): boolean, - - // Operations - translate(other: atom$PointLike): atom$Point, - - // Conversion - serialize(): [number, number], - toArray(): [number, number], -} - -type atom$RangeObject = { - start: atom$PointObject, - end: atom$PointObject, -}; - -type atom$RangeLike = atom$Range - | atom$RangeObject // TODO: Flow doesn't really handle the real signature below... - | [atom$PointLike, atom$PointLike] - | { - start: atom$PointLike, - end: atom$PointLike, - }; - -declare class atom$Range { - static fromObject( - object: atom$RangeLike, - copy?: boolean, - ): atom$Range, - static fromPointWithDelta( - startPoint: atom$PointLike, - rowDelta: number, - columnDelta: number - ): atom$Range, - - constructor(pointA: atom$PointLike, pointB: atom$PointLike): void, - compare(other: atom$Range): number, - start: atom$Point, - end: atom$Point, - isEmpty(): boolean, - isEqual(otherRange: atom$RangeLike): boolean, - isSingleLine(): boolean, - intersectsWith(otherRange: atom$RangeLike, exclusive?: boolean): boolean, - containsPoint(point: atom$PointLike, exclusive?: boolean): boolean, - containsRange(other: atom$Range, exclusive?: boolean): boolean, - union(other: atom$Range): atom$Range, - serialize(): Array>, - translate(startDelta: atom$PointLike, endDelta?: atom$PointLike): atom$Range, - getRowCount(): number, - getRows(): Array, -} - -type RawStatusBarTile = { - item: HTMLElement, - priority: number, -}; - -type atom$StatusBarTile = { - getPriority(): number, - getItem(): HTMLElement, - destroy(): void, -}; - -declare class atom$ScopeDescriptor { - constructor(object: {scopes: Array}): void, - getScopesArray(): Array, -} - -type atom$ScopeDescriptorLike = atom$ScopeDescriptor | Array; - -/** - * This API is defined at https://github.com/atom/status-bar. - */ -declare class atom$StatusBar { - addLeftTile(tile: RawStatusBarTile): atom$StatusBarTile, - addRightTile(tile: RawStatusBarTile): atom$StatusBarTile, - getLeftTiles(): Array, - getRightTiles(): Array, -} - -// https://github.com/atom/atom/blob/v1.9.0/src/text-editor-registry.coffee -declare class atom$TextEditorRegistry { - add(editor: atom$TextEditor): IDisposable, - remove(editor: atom$TextEditor): boolean, - observe(callback: (editor: atom$TextEditor) => void): IDisposable, - build: (params: atom$TextEditorParams) => atom$TextEditor, - - // Private - editors: Set, -} - -declare class atom$ThemeManager { - // Event Subscription - /** - * As recent as Atom 1.0.10, the implementation of this method was: - * - * ``` - * onDidChangeActiveThemes: (callback) -> - * @emitter.on 'did-change-active-themes', callback - * @emitter.on 'did-reload-all', callback # TODO: Remove once deprecated pre-1.0 APIs are gone - * ``` - * - * Due to the nature of CoffeeScript, onDidChangeActiveThemes returns a Disposable even though it - * is not documented as doing so. However, the Disposable that it does return removes the - * subscription on the 'did-reload-all' event (which is supposed to be deprecated) rather than the - * 'did-change-active-themes' one. - */ - onDidChangeActiveThemes(callback: () => mixed): IDisposable, - - // Accessing Loaded Themes - getLoadedThemeNames(): Array, - getLoadedThemes(): Array, // TODO: Define undocumented ThemePackage class. - - // Accessing Active Themes - getActiveThemeNames(): Array, - getActiveThemes(): Array, // TODO: Define undocumented ThemePackage class. - - // Managing Enabled Themes - getEnabledThemeNames(): Array, - - // Private - activateThemes(): Promise, - requireStylesheet(stylesheetPath: string): IDisposable, -} - -type atom$TooltipsPlacementOption = 'top' | 'bottom' | 'left' | 'right' | 'auto'; - -type atom$TooltipsAddOptions = { - title?: string, - item?: HTMLElement, - keyBindingCommand?: string, - keyBindingTarget?: HTMLElement, - animation?: boolean, - container?: string | false, - delay?: number | {show: number, hide: number}, - placement?: atom$TooltipsPlacementOption | () => atom$TooltipsPlacementOption, - trigger?: string, -}; - -type atom$Tooltip = { - show(): void; - hide(): void; - getTooltipElement(): HTMLElement, -}; - -declare class atom$TooltipManager { - tooltips: Map>; - add( - target: HTMLElement, - options: atom$TooltipsAddOptions, - ): IDisposable, - findTooltips(HTMLElement): Array, -} - -type InsertTextOptions = { - select: boolean, - autoIndent: boolean, - autoIndentNewline: boolean, - autoDecreaseIndent: boolean, - normalizeLineEndings: ?boolean, - undo: string, -}; - -type DecorateMarkerParams = { - type: 'line', - class: string, - onlyHead?: boolean, - onlyEmpty?: boolean, - onlyNonEmpty?: boolean, -} | { - type: 'gutter', - item?: HTMLElement, - class?: string, - onlyHead?: boolean, - onlyEmpty?: boolean, - onlyNonEmpty?: boolean, - gutterName?: string, -} | { - type: 'highlight', - class?: string, - gutterName?: string, -} | { - type: 'overlay', - item: Object, - position?: 'head' | 'tail', // Defaults to 'head' when unspecified. -} | { - type: 'block', - item: HTMLElement, - position?: 'before' | 'after', // Defaults to 'before' when unspecified. -} | { - type: 'line-number', - class?: string, -}; - -type ChangeCursorPositionEvent = { - oldBufferPosition: atom$Point, - oldScreenPosition: atom$Point, - newBufferPosition: atom$Point, - newScreenPosition: atom$Point, - textChanged: boolean, - cursor: atom$Cursor, -}; - -type MarkerOptions = { - reversed?: boolean, - tailed?: boolean, - invalidate?: 'never' | 'surround' | 'overlap' | 'inside' | 'touch', - exclusive?: boolean, -}; - -type atom$ChangeSelectionRangeEvent = {| - oldBufferRange: atom$Range, - oldScreenRange: atom$Range, - newBufferRange: atom$Range, - newScreenRange: atom$Range, - selection: atom$Selection, -|}; - -declare class atom$TextEditor extends atom$Model { - id: number, - verticalScrollMargin: number, - - // Event Subscription - onDidChange(callback: () => void): IDisposable, - onDidChangePath(callback: (newPath: string) => mixed): IDisposable, - onDidStopChanging(callback: () => mixed): IDisposable, - onDidChangeCursorPosition(callback: (event: ChangeCursorPositionEvent) => mixed): - IDisposable, - onDidAddCursor(callback: (cursor: atom$Cursor) => mixed): IDisposable; - onDidRemoveCursor(callback: (cursor: atom$Cursor) => mixed): IDisposable; - onDidDestroy(callback: () => mixed): IDisposable, - onDidSave(callback: (event: {path: string}) => mixed): IDisposable, - getBuffer(): atom$TextBuffer, - observeGrammar(callback: (grammar: atom$Grammar) => mixed): IDisposable, - onWillInsertText(callback: (event: {cancel: () => void, text: string}) => void): - IDisposable, - // Note that the range property of the event is undocumented. - onDidInsertText(callback: (event: {text: string, range: atom$Range}) => mixed): IDisposable, - onDidChangeSoftWrapped(callback: (softWrapped: boolean) => mixed): IDisposable, - onDidChangeSelectionRange(callback: (event: atom$ChangeSelectionRangeEvent) => mixed): IDisposable, - observeSelections(callback: (selection: atom$Selection) => mixed): IDisposable, - onDidAddSelection(callback: (selection: atom$Selection) => mixed): IDisposable, - - // File Details - getTitle: () => string, - getLongTitle(): string, - /** - * If you open Atom via Spotlight such that it opens with a tab named - * "untitled" that does not correspond to a file on disk, this will return - * null. - */ - getPath(): ?string, - getURI: () => ?string, - insertNewline(): void, - isModified: () => boolean, - isEmpty(): boolean, - getEncoding(): buffer$Encoding, - setEncoding(encoding: string): void, - getTabLength() : number, - getSoftTabs(): boolean, - getIconName(): string, - onDidChangeIcon(cb: (icon: string) => void): IDisposable, - onDidChangeTitle(cb: (title: string) => void): IDisposable, - - // File Operations - save(): Promise, - // DO NOT USE: Doesn't work with remote text buffers! - // saveAs(filePath: string): void, - - // Reading Text - getText(): string, - getTextInBufferRange(range: atom$RangeLike): string, - getLineCount(): number, - getScreenLineCount(): number, - getLastScreenRow(): number, - - // Mutating Text - setText(text: string, options?: InsertTextOptions): void, - setTextInBufferRange( - range: atom$RangeLike, - text: string, - options?: { - normalizeLineEndings?: boolean, - undo?: string, - }, - ): atom$Range, - insertText(text: string): Array | false, - mutateSelectedText(fn: (selection: atom$Selection, index: number) => void): void, - delete: () => void, - backspace: () => void, - duplicateLines: () => void, - - // History - createCheckpoint(): atom$TextBufferCheckpoint, - revertToCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean, - terminatePendingState(): void, - transact(fn: () => mixed, _: void): void, - transact(groupingInterval: number, fn: () => mixed): void, - onDidTerminatePendingState(() => mixed): IDisposable; - - // TextEditor Coordinates - screenPositionForBufferPosition( - bufferPosition: atom$PointLike, - options?: { - wrapBeyondNewlines?: boolean, - wrapAtSoftNewlines?: boolean, - screenLine?: boolean, - }, - ): atom$Point, - bufferPositionForScreenPosition( - screenPosition: atom$PointLike, - options?: { - wrapBeyondNewlines?: boolean, - wrapAtSoftNewlines?: boolean, - screenLine?: boolean, - }, - ): atom$Point, - getEofBufferPosition(): atom$Point, - getVisibleRowRange(): [number, number], - bufferRowForScreenRow(screenRow: number): number, - screenRangeForBufferRange(bufferRange: atom$RangeLike): atom$Range, - bufferRangeForBufferRow(bufferRow: number): atom$Range, - - // Decorations - decorateMarker(marker: atom$Marker, decorationParams: DecorateMarkerParams): atom$Decoration, - decorateMarkerLayer( - markerLayer: atom$DisplayMarkerLayer, - decorationParams: DecorateMarkerParams, - ): atom$LayerDecoration, - decorationsForScreenRowRange( - startScreenRow: number, - endScreenRow: number, - ): {[markerId: string]: Array}, - getDecorations(options?: {class?: string, type?: string}): Array, - - // Markers - addMarkerLayer(): atom$DisplayMarkerLayer, - getDefaultMarkerLayer(): atom$DisplayMarkerLayer, - markBufferPosition(position: atom$PointLike, options?: MarkerOptions): atom$Marker, - markBufferRange(range: atom$RangeLike, options?: MarkerOptions): atom$Marker, - markScreenRange(range: atom$RangeLike, options?: MarkerOptions): atom$Marker, - markScreenPosition(position: atom$PointLike, options?: MarkerOptions): atom$Marker, - findMarkers(options: MarkerOptions): Array, - getMarkerCount(): number, - - // Cursors - getCursors(): Array, - setCursorBufferPosition( - position: atom$PointLike, - options?: { - autoscroll?: boolean, - wrapBeyondNewlines?: boolean, - wrapAtSoftNewlines?: boolean, - screenLine?: boolean, - }): void, - getCursorBufferPosition(): atom$Point, - getCursorBufferPositions(): Array, - getCursorScreenPosition(): atom$Point, - getCursorScreenPositions(): Array, - getLastCursor(): atom$Cursor, - addCursorAtBufferPosition(point: atom$PointLike): atom$Cursor, - moveToBeginningOfLine(): void, - moveToEndOfLine(): void, - moveToBottom(): void, - - // Folds - foldCurrentRow(): void, - unfoldCurrentRow(): void, - foldBufferRow(bufferRow: number): void, - unfoldBufferRow(bufferRow: number): void, - - // Selections - getLastSelection(): atom$Selection, - getSelectedText(): string, - selectAll(): void, - getSelectedBufferRange(): atom$Range, - getSelectedBufferRanges(): Array, - getSelections(): Array, - selectToBufferPosition(point: atom$Point): void, - setSelectedBufferRange( - bufferRange: atom$RangeLike, - options?: { - reversed?: boolean, - preserveFolds?: boolean, - }, - ): void, - setSelectedBufferRanges( - bufferRanges: Array, - options?: { - reversed?: boolean, - preserveFolds?: boolean, - }, - ): void, - selectWordsContainingCursors(): void, - - // Folds - unfoldAll(): void, - - // Searching and Replacing - scanInBufferRange( - regex: RegExp, - range: atom$Range, - iterator: (foundMatch: { - match: mixed, - matchText: string, - range: atom$Range, - stop: () => mixed, - replace: (replaceWith: string) => mixed, - }) => mixed - ): void, - - scan( - regex: RegExp, - iterator: (foundMatch: { - match: RegExp$matchResult, - matchText: string, - range: atom$Range, - stop: () => mixed, - replace: (replaceWith: string) => mixed, - }) => mixed - ): void, - - // Tab Behavior - // Soft Wrap Behavior - // Indentation - indentationForBufferRow(bufferRow: number): number, - setTabLength(tabLength: number): void, - setSoftTabs(softTabs: boolean): void, - - lineTextForBufferRow(bufferRow: number): string, - lineTextForScreenRow(screenRow: number): string, - - // Grammars - getGrammar(): atom$Grammar, - setGrammar(grammar: ?atom$Grammar): void, - - // Clipboard Operations - pasteText: (options?: Object) => void, - copySelectedText: () => void, - - // Managing Syntax Scopes - getRootScopeDescriptor(): atom$ScopeDescriptor, - scopeDescriptorForBufferPosition( - bufferPosition: atom$PointLike, - ): atom$ScopeDescriptor, - - // Gutter - addGutter(options: { - name: string, - priority?: number, - visible?: boolean, - }): atom$Gutter, - observeGutters(callback: (gutter: atom$Gutter) => void): IDisposable, - getGutters(): Array, - gutterWithName(name: string): ?atom$Gutter, - - // Scrolling the TextEditor - scrollToBufferPosition( - position: atom$Point | [?number, ?number], - options?: {center?: boolean} - ): void, - scrollToScreenPosition( - position: atom$Point | [?number, ?number], - options?: {center?: boolean} - ): void, - scrollToScreenRange(screenRange: atom$Range, options?: {clip?: boolean}): void, - scrollToCursorPosition( - options?: {center?: boolean} - ): void, - scrollToBottom(): void, - scrollToTop(): void, - - // TextEditor Rendering - getPlaceholderText(): string, - setPlaceholderText(placeholderText: string): void, - - // This is undocumented, but Nuclide uses it in the AtomTextEditor wrapper. - setLineNumberGutterVisible(lineNumberGutterVisible: boolean): void, - - // Editor Options - setSoftWrapped(softWrapped: boolean): void, - - isFoldedAtBufferRow(row: number): boolean, - getLastBufferRow(): number, - - // Undocumented Methods - getElement(): atom$TextEditorElement, - getDefaultCharWidth(): number, - getLineHeightInPixels(): number, - moveToTop(): void, - tokenForBufferPosition(position: atom$Point | [?number, ?number]): atom$Token, - onDidConflict(callback: () => void): IDisposable, - serialize(): Object, - foldBufferRowRange(startRow: number, endRow: number): void, - getNonWordCharacters(position?: atom$PointLike): string, - scheduleComponentUpdate(): void, -} - -/** - * This is not part of the official Atom 1.0 API. Nevertheless, we need to reach into this object - * via `atom$TextEditorElement` to do some things that we have no other way to do. - */ -declare class atom$TextEditorComponent { - domNode: HTMLElement, - scrollViewNode: HTMLElement, - presenter: atom$TextEditorPresenter, - refs: atom$TextEditorComponentRefs, - linesComponent: atom$LinesComponent, - // NOTE: This is typed as a property to allow overwriting. - startCursorBlinking: () => void, - stopCursorBlinking(): void, - pixelPositionForScreenPosition( - screenPosition: atom$Point, - clip?: boolean, - ): {top: number, left: number}, - screenPositionForMouseEvent(event: MouseEvent): atom$Point, - pixelPositionForMouseEvent( - event: MouseEvent, - linesClientRect?: {top: number, left: number, bottom: number, right: number}, - ): {top: number, left: number, bottom: number, right: number}, - invalidateBlockDecorationDimensions(decoration: atom$Decoration): void, - element: atom$TextEditorElement, - didFocus(): void, - setScrollTop(scrollTop: number): void, - getScrollTop(): number, - - setScrollLeft(scrollLeft: number): void, - getScrollLeft(): number, - updateSync(useScheduler?: boolean): void, -} - -/** - * This is not part of the official Atom 1.0 API. Nevertheless, we need to reach into this object - * via `atom$TextEditorComponent` to do some things that we have no other way to do. - */ -declare class atom$TextEditorPresenter { - startBlinkingCursors: () => void, - stopBlinkingCursors(visible: boolean): void, - updateLineNumberGutterState(): void, -} - -/** - * This is not part of the official Atom 1.0 API. Nevertheless, we need it to access - * the deepest dom element receiving DOM events. - */ -declare class atom$LinesComponent { - domNode: HTMLElement, - getDomNode(): HTMLElement, -} - -/** - * This is not part of the official Atom 1.0 API. Nevertheless, we need it to access - * the deepest dom element receiving DOM events. - */ -declare class atom$TextEditorComponentRefs { - lineTiles: HTMLElement, -} - -/** - * This is not part of the official Atom 1.0 API, but it really should be. This is the element that - * is returned when you run `atom.views.getView()`. - */ -declare class atom$TextEditorElement extends HTMLElement { - component: ?atom$TextEditorComponent, - getModel(): atom$TextEditor, - setModel(model: atom$TextEditor): void, - pixelPositionForBufferPosition( - bufferPosition: atom$PointLike, - ): {top: number, left: number}, - pixelPositionForScreenPosition(screenPosition: atom$Point): { - left: number, - top: number, - }, - - setScrollTop(scrollTop: number): void, - getScrollTop(): number, - - setScrollLeft(scrollLeft: number): void, - getScrollLeft(): number, - - getScrollHeight(): number, - getHeight(): number, - - onDidChangeScrollTop(callback: (scrollTop: number) => mixed): IDisposable, - onDidChangeScrollLeft(callback: (scrollLeft: number) => mixed): IDisposable, - - // Called when the editor is attached to the DOM. - onDidAttach(callback: () => mixed): IDisposable, - // Called when the editor is detached from the DOM. - onDidDetach(callback: () => mixed): IDisposable, - - measureDimensions(): void, - - // Undocumented Methods - - // Returns a promise that resolves after the next update. - getNextUpdatePromise(): Promise, - - // `undefined` means no explicit width. `null` sets a zero width (which is almost certainly a - // mistake) so we don't allow it. - setWidth(width: number | void): void, -} - -declare class atom$ViewProvider { - modelConstructor: Function, -} - -declare class atom$ViewRegistry { - // Methods - addViewProvider( - modelConstructor: any, - createView?: (...args: Array) => ?HTMLElement - ): IDisposable, - getView(textEditor: atom$TextEditor): atom$TextEditorElement, - getView(notification: atom$Notification): HTMLElement, - getView(gutter: atom$Gutter): HTMLElement, - getView(panel: atom$Panel): HTMLElement, - getView(workspace: atom$Workspace): HTMLElement, - getView(object: Object): HTMLElement, - providers: Array, -} - -type atom$WorkspaceAddPanelOptions = { - item: Object, - visible?: boolean, - priority?: number, - className?: string, -}; - -type atom$TextEditorParams = { - buffer?: atom$TextBuffer, - lineNumberGutterVisible?: boolean, -}; - -type DestroyPaneItemEvent = { - item: atom$PaneItem, - pane: atom$Pane, - index: number, -}; - -type AddPaneItemEvent = { - item: atom$PaneItem, - pane: atom$Pane, - index: number, -}; - -type OnDidOpenEvent = { - uri: string, - item: mixed, - pane: atom$Pane, - index: number, -}; - -type AddTextEditorEvent = { - textEditor: atom$TextEditor, - pane: atom$Pane, - index: number, -}; - -type atom$WorkspaceOpenOptions = { - activatePane?: ?boolean, - activateItem?: ?boolean, - initialLine?: ?number, - initialColumn?: ?number, - pending?: ?boolean, - split?: ?string, - searchAllPanes?: ?boolean, - location?: atom$PaneLocation, -} - -declare class atom$Workspace { - // Event Subscription - observePanes(cb: (pane: atom$Pane) => void): IDisposable, - observeTextEditors(callback: (editor: atom$TextEditor) => mixed): IDisposable, - observeActiveTextEditor(callback: (editor: ?atom$TextEditor) => mixed): IDisposable, - onDidAddTextEditor(callback: (event: AddTextEditorEvent) => mixed): IDisposable, - onDidChangeActivePaneItem(callback: (item: mixed) => mixed): IDisposable, - onDidDestroyPaneItem(callback: (event: DestroyPaneItemEvent) => mixed): IDisposable, - onDidAddPaneItem(callback: (event: AddPaneItemEvent) => mixed): IDisposable, - observeActivePaneItem(callback: (item: ?mixed) => mixed): IDisposable, - onDidStopChangingActivePaneItem(callback: (item: ?mixed) => mixed): IDisposable, - observePaneItems(callback: (item: mixed) => mixed): IDisposable, - onWillDestroyPaneItem( - callback: (event: {item: mixed, pane: mixed, index: number}) => mixed - ): IDisposable, - onDidOpen(callback: (event: OnDidOpenEvent) => mixed): IDisposable, - - getElement(): HTMLElement, - - // Opening - open( - uri?: string, - options?: atom$WorkspaceOpenOptions, - ): Promise, - openURIInPane( - uri?: string, - pane: atom$Pane, - options?: { - initialLine?: number, - initialColumn?: number, - activePane?: boolean, - searchAllPanes?: boolean, - } - ): Promise, - isTextEditor(item: ?mixed): boolean, - /* Optional method because this was added post-1.0. */ - buildTextEditor: ((params: ?atom$TextEditorParams) => atom$TextEditor), - /* Optional method because this was added in 1.9.0 */ - handleGrammarUsed?: (grammar: atom$Grammar) => void, - reopenItem(): Promise, - addOpener(callback: (uri: string) => any): IDisposable, - hide(uriOrItem: string | Object): void, - toggle(uriOrItem: string | Object): void, - - // Pane Containers - getPaneContainers(): Array, - paneContainerForItem(item: ?mixed): ?atom$AbstractPaneContainer, - - // Pane Items - getPaneItems(): Array, - getActivePaneItem(): ?Object, - getActivePaneContainer(): atom$PaneContainer, - getTextEditors(): Array, - getActiveTextEditor(): ?atom$TextEditor, - createItemForURI(uri: string, options: atom$WorkspaceOpenOptions): atom$PaneItem, - - // Panes - getPanes(): Array, - getActivePane(): atom$Pane, - activateNextPane(): boolean, - activatePreviousPane(): boolean, - paneForURI(uri: string): atom$Pane, - paneForItem(item: mixed): ?atom$Pane, - paneContainers: {[location: atom$PaneLocation]: atom$AbstractPaneContainer}, - - // Panels - panelContainers: {[location: string]: atom$PanelContainer}, - getBottomPanels(): Array, - addBottomPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, - getLeftPanels(): Array, - addLeftPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, - getRightPanels(): Array, - addRightPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, - getTopPanels(): Array, - addTopPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, - getModalPanels(): Array, - addModalPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, - getHeaderPanels(): Array, - addHeaderPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel, - - getLeftDock(): atom$Dock, - getRightDock(): atom$Dock, - getBottomDock(): atom$Dock, - getCenter(): atom$WorkspaceCenter, - - // Searching and Replacing - scan( - regex: RegExp, - options: { - paths?: Array, - onPathsSearched?: (numSearched: number) => mixed, - leadingContextLineCount?: number, - trailingContextLineCount?: number, - }, - iterator: ( - ?{ - filePath: string, - matches: Array<{ - leadingContextLines: Array, - lineText: string, - lineTextOffset: number, - range: atom$RangeLike, - matchText: string, - trailingContextLines: Array, - }>, - }, - Error, - ) => mixed, - ): Promise, - - destroyActivePaneItemOrEmptyPane(): void, - destroyActivePaneItem(): void, -} - -declare class atom$AbstractPaneContainer { - activate(): void, - getLocation(): atom$PaneLocation, - getElement(): HTMLElement, - isVisible(): boolean, - show(): void, - hide(): void, - getActivePane(): atom$Pane, - getPanes(): Array, - onDidAddPaneItem((item: {item: Object}) => void): IDisposable, - observePanes(cb: (pane: atom$Pane) => void): IDisposable, - state: { - size: number, - } -} - -declare class atom$Dock extends atom$AbstractPaneContainer { - // This is a woefully incomplete list, items can be added as needed from - // https://github.com/atom/atom/blob/master/src/dock.js - toggle(): void, -} - -declare class atom$WorkspaceCenter extends atom$AbstractPaneContainer { - activate(): void; - - // Pane Items - getPaneItems(): Array, - getActivePaneItem(): ?atom$PaneItem, - getTextEditors(): Array, - getActiveTextEditor(): ?atom$TextEditor, - - observeActivePaneItem(callback: atom$PaneItem => mixed): IDisposable; - onDidChangeActivePaneItem(callback: (item: mixed) => mixed): IDisposable; - onDidAddTextEditor( - callback: (item: { - textEditor: atom$TextEditor, - pane: atom$Pane, - index: number, - }) => mixed, - ): IDisposable; - // This should be removed soon anyway, it's currently deprecated. - paneContainer: Object; -} - -/** - * Extended Classes - */ - -declare class atom$BufferedNodeProcess { } - -declare class atom$BufferedProcess { - // Event Subscription - onWillThrowError( - callback: (errorObject: {error: Object, handle: mixed}) => mixed - ): IDisposable, - // Helper Methods - kill(): void, -} - -declare class atom$Clipboard { - // Methods - write(text: string, metadata?: mixed): void, - read(): string, - readWithMetadata(): { - metadata: ?mixed, - text: string, - }, -} - -declare class atom$ContextMenuManager { - add(itemsBySelector: {[cssSelector: string]: Array}): IDisposable, - itemSets: Array, - - // Undocumented methods - showForEvent(event: Event): void, - templateForEvent(event: Event): Array, -} - -declare class atom$ContextMenuItemSet { - items: Array, - selector: string, -} - -type atom$ContextMenuItem = { - command?: string, - created?: (event: MouseEvent) => void, - enabled?: boolean, - label?: string, - shouldDisplay?: (event: MouseEvent) => boolean, - submenu?: Array, - type?: string, - visible?: boolean, -}; - -type atom$Deserializer = { - name: string, - deserialize: (state: Object) => mixed, -}; - -declare class atom$DeserializerManager { - add(...deserializers: Array): IDisposable, - deserialize(state: Object, params?: Object): mixed, -} - -// Apparently it can sometimes include a `code` property. -declare class atom$GetEntriesError extends Error { - code?: string, -} - -declare class atom$Directory { - constructor(dirname?: string): atom$Directory, - - symlink: boolean, - - // Construction - create(mode?: number): Promise, - - // Event Subscription - onDidChange(callback: () => mixed): IDisposable, - - // Directory Metadata - isFile(): boolean, - isDirectory(): boolean, - exists():Promise, - - // Managing Paths - getPath(): string, - getBaseName(): string, - relativize(fullPath: string): string, - - // Event Subscription - onDidRename(callback: () => void): IDisposable, - onDidDelete(callback: () => void): IDisposable, - - // Traversing - getParent(): atom$Directory, - getFile(filename: string): atom$File, - getSubdirectory(dirname: string): atom$Directory, - getEntries( - callback: ( - error: ?atom$GetEntriesError, - entries: ?Array, - ) => mixed): void, - contains(path: string): boolean, -} - -// These are the methods called on a file by atom-text-buffer -interface atom$Fileish { - existsSync(): boolean, - setEncoding(encoding: string): void, - getEncoding(): ?string, - - onDidRename(callback: () => void): IDisposable, - onDidDelete(callback: () => void): IDisposable, - onDidChange(callback: () => void): IDisposable, - onWillThrowWatchError(callback: () => mixed): IDisposable, - - getPath(): string, - getBaseName(): string, - - createReadStream(): stream$Readable, - createWriteStream(): stream$Writable, -} - -declare class atom$File /* implements atom$Fileish */ { - constructor(filePath?: string, symlink?: boolean): atom$File, - - symlink: boolean, - - // Construction - create(): Promise, - - // File Metadata - isFile(): boolean, - isDirectory(): boolean, - exists(): Promise, - existsSync(): boolean, - setEncoding(encoding: string): void, - getEncoding(): string, - - // Event Subscription - onDidRename(callback: () => void): IDisposable, - onDidDelete(callback: () => void): IDisposable, - onDidChange(callback: () => void): IDisposable, - onWillThrowWatchError(callback: () => mixed): IDisposable, - - // Managing Paths - getPath(): string, - getBaseName(): string, - - // Traversing - getParent(): atom$Directory, - - // Reading and Writing - read(flushCache?: boolean): Promise, - write(text: string): Promise, - writeSync(text: string): void, - createReadStream(): stream$Readable, - createWriteStream(): stream$Writable, -} - -declare class atom$GitRepository extends atom$Repository { - // Unofficial API. - statuses: {[filePath: string]: number}, - // Return the `git-utils` async repo. - getRepo(): atom$GitRepositoryInternal, -} - -declare class atom$Grammar { - name: string, - scopeName: string, - tokenizeLines(text: string): Array>, - tokenizeLine(line: string, ruleStack: mixed, firstLine: boolean): { - line: string, - tags: Array, - // Dynamic property: invoking it will incur additional overhead - tokens: Array, - ruleStack: mixed - }, -} - -type atom$GrammarToken = { - value: string, - scopes: Array, -}; - -declare class atom$GrammarRegistry { - // Event Subscription - onDidAddGrammar(callback: (grammar: atom$Grammar) => void): IDisposable, - - // Managing Grammars - grammarForScopeName(scopeName: string): ?atom$Grammar, - removeGrammarForScopeName(scopeName: string): ?atom$Grammar, - loadGrammarSync(grammarPath: string): atom$Grammar, - selectGrammar(filePath: string, fileContents: string): atom$Grammar, - autoAssignLanguageMode(buffer: atom$TextBuffer): void, - assignLanguageMode(buffer: atom$TextBuffer, languageId: string): void, - - // Extended - getGrammarScore(grammar: atom$Grammar, filePath: string, contents?: string): number, - forEachGrammar(callback: (grammar: atom$Grammar) => mixed): void, - - // Private API - clear(): IDisposable, -} - -declare class atom$HistoryManager { - removeProject(paths: Array): void, - getProjects(): Array, -} - -declare class atom$HistoryProject { - get paths(): Array; - get lastOpened(): Date; -} - -// https://github.com/atom/atom-keymap/blob/18f00ac307de5770bb8f98958bd9a13ecffa9e68/src/key-binding.coffee -declare class atom$KeyBinding { - cachedKeyups: ?Array, - command: string, - index: number, - keystrokeArray : Array, - keystrokeCount: number, - keystrokes: string, - priority: number, - selector: string, - source: string, - specificity: number, - - matches(keystroke: string): boolean, - compare(keybinding: atom$KeyBinding): number, - getKeyups(): ?Array, - matchesKeystrokes(userKeystrokes: Array): boolean | 'exact' | 'partial' | 'pendingKeyup', -} - -declare class atom$KeymapManager { - // Event Subscription - onDidMatchBinding(callback: (event: { - keystrokes: string, - binding: atom$KeyBinding, - keyboardEventTarget: HTMLElement, - }) => mixed): IDisposable, - - onDidPartiallyMatchBinding(callback: (event: { - keystrokes: string, - partiallyMatchedBindings: atom$KeyBinding, - keyboardEventTarget: HTMLElement, - }) => mixed): IDisposable, - - onDidFailToMatchBinding(callback: (event: { - keystrokes: string, - partiallyMatchedBindings: atom$KeyBinding, - keyboardEventTarget: HTMLElement, - }) => mixed): IDisposable, - - onDidFailToReadFile(callback: (error: { - message: string, - stack: string, - }) => mixed): IDisposable, - - // Adding and Removing Bindings - add(source: string, bindings: Object): IDisposable, - removeBindingsFromSource(source: string): void, - - // Accessing Bindings - getKeyBindings(): Array, - findKeyBindings(params: { - keystrokes?: string, - command?: string, - target?: HTMLElement, - }): Array, - - // Managing Keymap Files - loadKeymap(path: string, options?: {watch: boolean}): void, - watchKeymap(path: string): void, - - // Managing Keyboard Events - handleKeyboardEvent(event: Event): void, - keystrokeForKeyboardEvent(event: Event): string, - getPartialMatchTimeout(): number, - - static buildKeydownEvent( - key: string, - options: { - target: HTMLElement, - alt?: boolean, - cmd?: boolean, - ctrl?: boolean, - shift?: boolean, - }, - ): Event, -} - -declare class atom$MenuManager { - add(items: Array): IDisposable, - update(): void, - - // Private API - template: Array, -} - -type atom$ProjectSpecification = { - originPath: string, - paths?: Array, - config?: {[string]: mixed} -}; - -declare class atom$Project { - // Event Subscription - onDidChangePaths(callback: (projectPaths: Array) => mixed): IDisposable, - onDidAddBuffer(callback: (buffer: atom$TextBuffer) => mixed): IDisposable, - onDidReplace((settings: atom$ProjectSpecification) => mixed): IDisposable, - observeBuffers(callback: (buffer: atom$TextBuffer) => mixed): IDisposable, - observeRepositories(callback: (repository: atom$Repository)=> mixed): IDisposable, - replace?: (newSettings: atom$ProjectSpecification) => void, - // Accessing the git repository - getRepositories(): Array, - repositoryForDirectory(directory: atom$Directory): Promise, - - // Managing Paths - getPaths(): Array, - addPath(projectPath: string, options?: { - emitEvent?: boolean, - exact?: boolean, - mustExist?: boolean, - }): void, - setPaths(paths: Array): void, - removePath(projectPath: string): void, - getDirectories(): Array, - relativizePath(relativizePath?: string): Array, // [projectPath: ?string, relativePath: string] - relativize(filePath: string): string, - contains(path: string): boolean, - - // Private API - findBufferForPath(path: string): ?atom$TextBuffer, - addBuffer(buffer: atom$TextBuffer): void, - removeBuffer(buffer: atom$TextBuffer): void, - getBuffers(): Array, -} - -type TextBufferScanIterator = (arg: { - match: Array, - matchText: string, - range: atom$Range, - stop(): void, - replace(replacement: string): void, -}) => void; - -// This happens to be a number but it would be better if the type could be entirely opaque. All you -// need to know is that if something needs a checkpoint you should only pass it values received from -// TextBuffer::createCheckpoint -type atom$TextBufferCheckpoint = number; - -// TextBuffer did-change/will-change -type atom$TextEditEvent = { - oldRange: atom$Range, - newRange: atom$Range, - oldText: string, - newText: string, -}; - -type atom$AggregatedTextEditEvent = { - changes: Array, -}; - -declare class atom$LanguageMode { - getLanguageId(): string, -} - -declare class atom$TextBuffer { - constructor(text?: string): atom$TextBuffer, - constructor(params?: { - filePath?: string, - text?: string, - }): atom$TextBuffer, - - file: ?atom$File, - - // Mixin - static deserialize: (state: Object, params: Object) => mixed, - static load: (file: string | atom$Fileish, params: Object) => Promise, - - setFile(file: atom$Fileish): void, - - // Events - onWillChange(callback: () => mixed): IDisposable, - onDidChangeText(callback: (event: atom$AggregatedTextEditEvent) => mixed): IDisposable, - onDidStopChanging(callback: () => mixed): IDisposable, - onDidConflict(callback: () => mixed): IDisposable, - onDidChangeModified(callback: () => mixed): IDisposable, - onDidUpdateMarkers(callback: () => mixed): IDisposable, - onDidCreateMarker(callback: () => mixed): IDisposable, - onDidChangePath(callback: () => mixed): IDisposable, - onDidChangeEncoding(callback: () => mixed): IDisposable, - onWillSave(callback: () => mixed): IDisposable, - onDidSave(callback: (event: {path: string}) => mixed): IDisposable, - onDidDelete(callback: () => mixed): IDisposable, - onWillReload(callback: () => mixed): IDisposable, - onDidReload(callback: () => mixed): IDisposable, - onDidDestroy(callback: () => mixed): IDisposable, - onWillThrowWatchError(callback: () => mixed): IDisposable, - - // File Details - // DO NOT USE (T21363106): Doesn't work with remote text buffers! - // setPath(filePath: string): void, - getPath(): ?string, - setEncoding(encoding: string): void, - getEncoding(): string, - getUri(): string, - getId(): string, - getLanguageMode(): atom$LanguageMode, - - // Reading Text - isEmpty(): boolean, - getText(): string, - getTextInRange(range: atom$RangeLike): string, - getLineCount(): number, - getLines(): Array, - getLastLine(): string, - lineForRow(row: number): string, - lineEndingForRow(row: number): string, - lineLengthForRow(row: number): number, - isRowBlank(row: number): boolean, - previousNonBlankRow(startRow: number): ?number, - nextNonBlankRow(startRow: number): ?number, - - // Mutating Text - setText: (text: string) => atom$Range, - setTextInRange(range: atom$RangeLike, text: string, options?: Object): atom$Range, - setTextViaDiff(text: string): void, - insert( - position: atom$Point, - text: string, - options?: { - normalizeLineEndings?: boolean, - undo?: string, - }, - ): atom$Range, - append(text: string, options: ?{ - normalizeLineEndings?: boolean, - undo?: string, - }): atom$Range, - delete(range: atom$Range): atom$Range, - deleteRows(startRow: number, endRow: number): atom$Range, - - // History - undo(): void, - redo(): void, - transact(fn: () => mixed, _: void): void, - transact(groupingInterval: number, fn: () => mixed): void, - clearUndoStack(): void, - createCheckpoint(): atom$TextBufferCheckpoint, - revertToCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean, - groupChangesSinceCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean, - // TODO describe the return type more precisely. - getChangesSinceCheckpoint(checkpoint: atom$TextBufferCheckpoint): Array, - - // Search And Replace - scan(regex: RegExp, iterator: TextBufferScanIterator): void, - scanInRange(regex: RegExp, range: atom$Range, iterator: TextBufferScanIterator): void, - backwardsScanInRange(regex: RegExp, range: atom$Range, iterator: TextBufferScanIterator): void, - - // Buffer Range Details - getLastRow(): number, - getRange(): atom$Range, - rangeForRow(row: number, includeNewLine?: boolean): atom$Range, - getLength(): number, - - // Position/Index mapping - characterIndexForPosition(position: atom$PointLike): number, - positionForCharacterIndex(index: number): atom$Point, - - // Buffer Operations - reload(): void, - load(): Promise, - save(): Promise, - - isInConflict(): boolean, - isModified(): boolean, - - // Private APIs - cachedDiskContents: ?string, - emitter: atom$Emitter, - refcount: number, - loaded: boolean, - wasModifiedBeforeRemove: boolean, - finishLoading(): atom$TextBuffer, - updateCachedDiskContents(flushCache?: boolean, callback?: () => mixed): Promise, - emitModifiedStatusChanged(changed: boolean): void, - destroy(): void, - isDestroyed(): boolean, - applyChange: () => void, - shouldDestroyOnFileDelete?: () => boolean, -} - -declare class atom$Notification { - // Event Subscription - onDidDismiss(callback: () => mixed): IDisposable, - onDidDisplay(callback: () => mixed): IDisposable, - - // Methods - getType(): string, - getMessage(): string, - getOptions(): Object, - dismiss(): void, - isDismissed(): boolean, -} - -type atom$NotificationButton = { - text: string, - className?: string, - onDidClick?: () => mixed, -}; - -type atom$NotificationOptions = { - detail?: string, - dismissable?: boolean, - description?: string, - icon?: string, - stack?: string, - buttons?: Array, -}; - -declare class atom$NotificationManager { - // Events - onDidAddNotification(callback: (notification: atom$Notification) => void): IDisposable, - - // Adding Notifications - add(type: string, message: string, options?: atom$NotificationOptions): atom$Notification, - addSuccess(message: string, options?: atom$NotificationOptions): atom$Notification, - addInfo(message: string, options?: atom$NotificationOptions): atom$Notification, - addWarning(message: string, options?: atom$NotificationOptions): atom$Notification, - addError(message: string, options?: atom$NotificationOptions): atom$Notification, - addFatalError(message: string, options?: atom$NotificationOptions): atom$Notification, - addNotification(notification: atom$Notification): atom$Notification, - - // Getting Notifications - getNotifications(): Array, -} - -// The items in this declaration are available off of `require('atom')`. -// This list is not complete. -declare module 'atom' { - declare var BufferedNodeProcess: typeof atom$BufferedNodeProcess; - declare var BufferedProcess: typeof atom$BufferedProcess; - declare var CompositeDisposable: typeof atom$CompositeDisposable; - declare var Directory: typeof atom$Directory; - declare var Disposable: typeof atom$Disposable; - declare var Emitter: typeof atom$Emitter; - declare var File: typeof atom$File; - declare var GitRepository: typeof atom$GitRepository; - declare var Notification: typeof atom$Notification; - declare var Point: typeof atom$Point; - declare var Range: typeof atom$Range; - declare var TextBuffer: typeof atom$TextBuffer; - declare var TextEditor: typeof atom$TextEditor; -} - -// Make sure that common types can be referenced without the `atom$` prefix -// in type declarations. -declare var Cursor: typeof atom$Cursor; -declare var Panel: typeof atom$Panel; -declare var TextEditor: typeof atom$TextEditor; - -type atom$UnhandledErrorEvent = { - originalError: Object, - message: string, - url: string, - line: number, - column: number, -}; - -// The properties of this type match the properties of the `atom` global. -// This list is not complete. -type AtomGlobal = { - // Properties - appVersion: string, - atomScriptMode: ?boolean, // Added by nuclide-atom-script. - clipboard: atom$Clipboard, - commands: atom$CommandRegistry, - config: atom$Config, - contextMenu: atom$ContextMenuManager, - applicationDelegate: atom$applicationDelegate, - deserializers: atom$DeserializerManager, - grammars: atom$GrammarRegistry, - history: atom$HistoryManager, - keymaps: atom$KeymapManager, - menu: atom$MenuManager, - notifications: atom$NotificationManager, - packages: atom$PackageManager, - styles: atom$StyleManager, - themes: atom$ThemeManager, - textEditors: atom$TextEditorRegistry, - tooltips: atom$TooltipManager, - views: atom$ViewRegistry, - workspace: atom$Workspace, - project: atom$Project, - devMode: boolean, - - // Event Subscription - onWillThrowError(callback: (event: atom$UnhandledErrorEvent) => mixed): IDisposable, - onDidThrowError(callback: (event: atom$UnhandledErrorEvent) => mixed): IDisposable, - whenShellEnvironmentLoaded(callback: () => mixed): IDisposable, - - // Atom Details - inDevMode(): boolean, - inSafeMode(): boolean, - inSpecMode(): boolean, - getVersion(): string, - isReleasedVersion(): boolean, - getWindowLoadTime(): number, - - // This is an undocumented way to reach the Electron BrowserWindow. - // Use `electron.remote.getCurrentWindow` instead. - getCurrentWindow: void, - - // Messaging the User - +confirm: - & (( - { - message: string, - detail?: string, - buttons?: Array, - }, - (number) => void, - ) => void) - // The synchronous form. You really shouldn't use this. - & (({ - message: string, - detailedMessage?: string, - buttons?: Array | {[buttonName: string]: () => mixed}, - }) => ?number), - - open(params: { - pathsToOpen?: Array, - newWindow?: boolean, - devMode?: boolean, - safeMode?: boolean, - }): void, - reload(): void, - - // Undocumented Methods - getConfigDirPath(): string, - showSaveDialogSync(options: Object): string, - loadState(): Promise, - getLoadSettings(): Object, -}; - -declare var atom: AtomGlobal; - -type RepositoryDidChangeStatusCallback = (event: {path: string, pathStatus: number}) => mixed; -type RepositoryLineDiff = { - oldStart: number, - newStart: number, - oldLines: number, - newLines: number, -}; - -// Taken from the interface of [`GitRepository`][1], which is also implemented by -// `HgRepositoryClient`. -// -// [1]: https://github.com/atom/atom/blob/v1.7.3/src/git-repository.coffee -declare class atom$Repository { - constructor(path: string, options?: {refreshOnWindowFocus?: boolean}): void, - - // Event Subscription - onDidChangeStatus: (callback: RepositoryDidChangeStatusCallback) => IDisposable, - onDidChangeStatuses: (callback: () => mixed) => IDisposable, - - // Repository Details - getType: () => string, - getPath: () => string, - getWorkingDirectory: () => string, - isProjectAtRoot: () => boolean, - relativize: (aPath: string) => string, - getOriginURL: (aPath: ?string) => ?string, - - // Reading Status - isPathModified: (aPath: string) => boolean, - isPathNew: (aPath: string) => boolean, - isPathIgnored: (aPath: string) => boolean, - getDirectoryStatus: (aPath: string) => number, - getPathStatus: (aPath: string) => number, - getCachedPathStatus: (aPath: string) => ?number, - isStatusModified: (status: number) => boolean, - isStatusNew: (status: number) => boolean, - refreshStatus: () => Promise, - - // Retrieving Diffs - getDiffStats: (filePath: string) => {added: number, deleted: number}, - getLineDiffs: (aPath: string, text: string) => Array, - - // Checking Out - checkoutHead: (aPath: string) => boolean, - checkoutReference: (reference: string, create: boolean) => Promise, - - // Event Subscription - onDidDestroy(callback: () => mixed): IDisposable, - isDestroyed(): boolean, -} - -declare class atom$GitRepositoryInternal { - // Reading Status - isStatusModified: (status: number) => boolean, - isStatusNew: (status: number) => boolean, - isStatusIgnored: (status: number) => boolean, - isStatusStaged: (status: number) => boolean, - isStatusDeleted: (status: number) => boolean, -} - -// One of text or snippet is required. -// TODO(hansonw): use a union + intersection type -type atom$AutocompleteSuggestion = { - text?: string, - snippet?: string, - displayText?: string, - replacementPrefix?: string, - type?: ?string, - leftLabel?: ?string, - leftLabelHTML?: ?string, - rightLabel?: ?string, - rightLabelHTML?: ?string, - className?: ?string, - iconHTML?: ?string, - description?: ?string, - descriptionMarkdown?: ?string, - descriptionMoreURL?: ?string, -}; - -type atom$AutocompleteRequest = { - editor: TextEditor, - bufferPosition: atom$Point, - scopeDescriptor: atom$ScopeDescriptor, - prefix: string, - activatedManually?: boolean, -}; - -type atom$AutocompleteProvider = { - +selector: string, - +getSuggestions: ( - request: atom$AutocompleteRequest, - ) => Promise> | ?Array, - +getSuggestionDetailsOnSelect?: ( - suggestion: atom$AutocompleteSuggestion - ) => Promise, - +disableForSelector?: string, - +inclusionPriority?: number, - +excludeLowerPriority?: boolean, - +suggestionPriority?: number, - +filterSuggestions?: boolean, - +disposable?: () => void, - +onDidInsertSuggestion?: ( - insertedSuggestion: atom$SuggestionInsertedRequest, - ) => void, -}; - -type atom$SuggestionInsertedRequest = { - +editor: atom$TextEditor, - +triggerPosition: atom$Point, - +suggestion: atom$AutocompleteSuggestion, -}; - -// https://github.com/atom/autocomplete-plus/blob/master/README.md#the-watcheditor-api -type atom$AutocompleteWatchEditor = ( - editor: atom$TextEditor, - labels?: Array, -) => IDisposable; - -// Undocumented API. -declare class atom$Token { - value: string, - matchesScopeSelector(selector: string): boolean, -} - -declare class atom$Selection { - clear(): void, - getText(): string, - getBufferRange(): atom$Range, - insertText( - text: string, - options?: { - select?: boolean, - autoIndent?: boolean, - autoIndentNewLine?: boolean, - autoDecreaseIdent?: boolean, - normalizeLineEndings?: boolean, - undo?: boolean, - }, - ): string, - isEmpty(): boolean, -} - -declare class atom$PanelContainer { - dock: atom$Dock, - element: HTMLElement, - emitter: atom$Emitter, - location: atom$PaneLocation, - panels: Array, - subscriptions: atom$CompositeDisposable, - viewRegistry: atom$ViewRegistry, - - getPanels(): Array, -}; diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts new file mode 100644 index 00000000..241251b6 --- /dev/null +++ b/nuclide/types/atom.ts @@ -0,0 +1,2466 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the LICENSE file in + * the root directory of this source tree. + * + * @flow + */ + +/** + * Private Classes + */ + +// Octicons v4.4.0. List extracted from the atom-styleguide package. +type atom$Octicon = 'alert' | 'alignment-align' | 'alignment-aligned-to' | 'alignment-unalign' | + 'arrow-down' | 'arrow-left' | 'arrow-right' | 'arrow-small-down' | 'arrow-small-left' | + 'arrow-small-right' | 'arrow-small-up' | 'arrow-up' | 'beaker' | 'beer' | 'bell' | 'bold' | + 'book' | 'bookmark' | 'briefcase' | 'broadcast' | 'browser' | 'bug' | 'calendar' | 'check' | + 'checklist' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'chevron-up' | 'circle-slash' | + 'circuit-board' | 'clippy' | 'clock' | 'cloud-download' | 'cloud-upload' | 'code' | 'color-mode' | + 'comment' | 'comment-add' | 'comment-discussion' | 'credit-card' | 'dash' | 'dashboard' | + 'database' | 'desktop-download' | 'device-camera' | 'device-camera-video' | 'device-desktop' | + 'device-mobile' | 'diff' | 'diff-added' | 'diff-ignored' | 'diff-modified' | 'diff-removed' | + 'diff-renamed' | 'ellipses' | 'ellipsis' | 'eye' | 'eye-unwatch' | 'eye-watch' | 'file' | + 'file-add' | 'file-binary' | 'file-code' | 'file-directory' | 'file-directory-create' | + 'file-media' | 'file-pdf' | 'file-submodule' | 'file-symlink-directory' | 'file-symlink-file' | + 'file-text' | 'file-zip' | 'flame' | 'fold' | 'gear' | 'gift' | 'gist' | 'gist-fork' | + 'gist-new' | 'gist-private' | 'gist-secret' | 'git-branch' | 'git-branch-create' | + 'git-branch-delete' | 'git-commit' | 'git-compare' | 'git-fork-private' | 'git-merge' | + 'git-pull-request' | 'git-pull-request-abandoned' | 'globe' | 'grabber' | 'graph' | 'heart' | + 'history' | 'home' | 'horizontal-rule' | 'hourglass' | 'hubot' | 'inbox' | 'info' | + 'issue-closed' | 'issue-opened' | 'issue-reopened' | 'italic' | 'jersey' | 'jump-down' | + 'jump-left' | 'jump-right' | 'jump-up' | 'key' | 'keyboard' | 'law' | 'light-bulb' | 'link' | + 'link-external' | 'list-ordered' | 'list-unordered' | 'location' | 'lock' | 'log-in' | 'log-out' | + 'logo-gist' | 'logo-github' | 'mail' | 'mail-read' | 'mail-reply' | 'mark-github' | 'markdown' | + 'megaphone' | 'mention' | 'microscope' | 'milestone' | 'mirror' | 'mirror-private' | + 'mirror-public' | 'mortar-board' | 'move-down' | 'move-left' | 'move-right' | 'move-up' | 'mute' | + 'no-newline' | 'octoface' | 'organization' | 'package' | 'paintcan' | 'pencil' | 'person' | + 'person-add' | 'person-follow' | 'pin' | 'playback-fast-forward' | 'playback-pause' | + 'playback-play' | 'playback-rewind' | 'plug' | 'plus-small' | 'plus' | 'podium' | + 'primitive-dot' | 'primitive-square' | 'pulse' | 'puzzle' | 'question' | 'quote' | 'radio-tower' | + 'remove-close' | 'reply' | 'repo' | 'repo-clone' | 'repo-create' | 'repo-delete' | + 'repo-force-push' | 'repo-forked' | 'repo-pull' | 'repo-push' | 'repo-sync' | 'rocket' | 'rss' | + 'ruby' | 'screen-full' | 'screen-normal' | 'search' | 'search-save' | 'server' | 'settings' | + 'shield' | 'sign-in' | 'sign-out' | 'smiley' | 'split' | 'squirrel' | 'star' | 'star-add' | + 'star-delete' | 'steps' | 'stop' | 'sync' | 'tag' | 'tag-add' | 'tag-remove' | 'tasklist' | + 'telescope' | 'terminal' | 'text-size' | 'three-bars' | 'thumbsdown' | 'thumbsup' | 'tools' | + 'trashcan' | 'triangle-down' | 'triangle-left' | 'triangle-right' | 'triangle-up' | 'type-array'| + 'type-boolean'| 'type-class'| 'type-constant'| 'type-constructor'| 'type-enum'| 'type-field'| + 'type-file'| 'type-function'| 'type-interface'| 'type-method'| 'type-module'| 'type-namespace'| + 'type-number'| 'type-package'| 'type-property'| 'type-string'| 'type-variable' | 'unfold' | + 'unmute' | 'unverified' | 'verified' | 'versions' | 'watch' | 'x' | 'zap'; + +type atom$PaneLocation = 'left' | 'right' | 'bottom' | 'center'; + +declare type atom$Color = { + // Returns a String in the form '#abcdef'. + toHexString(): string; + // Returns a String in the form 'rgba(25, 50, 75, .9)'. + toRGBAString(): string; +}; + +declare class atom$Model { + destroy(): void; + isDestroyed(): boolean; +} + +declare class atom$Package { + path: string; + activateTime: number; + mainModule: any; + mainModulePath: string; + metadata: Object; + name: string; + loadTime: number; + getType(): 'atom' | 'textmate' | 'theme'; + hasActivationCommands(): boolean; + hasActivationHooks(): boolean; + initializeTime: number; + getActivationHooks(): Array; + onDidDeactivate(cb: () => unknown): IDisposable; + activateNow(): void; + // Undocumented + bundledPackage: boolean; + getCanDeferMainModuleRequireStorageKey(): string; + initializeIfNeeded(): void; +} + +/** + * Essential Classes + */ +declare type atom$CustomEvent = CustomEvent & { + originalEvent?: Event; +}; + +type atom$CommandCallback = (event: atom$CustomEvent) => unknown; + +type atom$CommandDescriptor = { + name: string; + displayName: string; + description?: string; + hiddenInCommandPalette?: boolean; + tags?: Array; +}; + +type atom$CommandListener = + | atom$CommandCallback + | { + displayName?: string; + description?: string; + didDispatch: atom$CommandCallback; + }; + +declare class atom$CommandRegistry { + // Methods + add( + target: string | HTMLElement, + commandNameOrCommands: + | string + | { + [commandName: string]: atom$CommandListener; + }, + listener?: atom$CommandListener, + throwOnInvalidSelector?: boolean, + ): IDisposable; + dispatch(target: HTMLElement, commandName: string, detail?: Object): void; + onDidDispatch(callback: (event: atom$CustomEvent) => unknown): IDisposable; + onWillDispatch(callback: (event: atom$CustomEvent) => unknown): IDisposable; + findCommands(opts: {target: Node}): Array; +} + +declare class atom$CompositeDisposable { + constructor(...disposables: Array); + dispose(): void; + + add(...disposables: Array): void; + remove(disposable: IDisposable): void; + clear(): void; +} + +type atom$ConfigParams = { + saveCallback?: (arg0: Object) => void; + mainSource?: string; + projectHomeSchema?: atom$ConfigSchema; +}; + +type atom$ConfigType = + | 'boolean' + | 'string' + | 'integer' + | 'number' + | 'array' + | 'object' + | 'color' + | 'any'; + +type atom$ConfigSchema = { + default?: unknown; + description?: string; + enum?: Array; + maximum?: number; + minimum?: number; + properties?: Object; + title?: string; + type: Array | atom$ConfigType; +}; + +declare class atom$Config { + defaultSettings: Object; + settings: Object; + + // Config Subscription + observe( + keyPath: string, + optionsOrCallback?: + | {scope?: atom$ScopeDescriptorLike} + | ((value: unknown) => void), + callback?: (value: unknown) => unknown, + ): IDisposable; + + onDidChange( + keyPathOrCallback: + | string + | ((event: {oldValue: unknown; newValue: unknown}) => unknown), + optionsOrCallback?: + | {scope?: atom$ScopeDescriptorLike} + | ((event: {oldValue: unknown; newValue: unknown}) => unknown), + callback?: (event: {oldValue: unknown; newValue: unknown}) => unknown, + ): IDisposable; + + // Managing Settings + get( + keyPath?: string, + options?: { + excludeSources?: Array; + sources?: Array; + scope?: atom$ScopeDescriptorLike; + }, + ): unknown; + + set( + keyPath: string, + value: unknown | null | undefined, + options?: { + scopeSelector?: string; + source?: string; + }, + ): boolean; + + unset( + keyPath: string, + options?: { + scopeSelector?: string; + source?: string; + }, + ): void; + + getUserConfigPath(): string; + + // Undocumented Methods + constructor(params?: atom$ConfigParams); + getRawValue( + keyPath: string | null | undefined, + options: {excludeSources?: string; sources?: string}, + ): unknown; + getSchema(keyPath: string): atom$ConfigSchema; + save(): void; + setRawValue(keyPath: string, value: unknown): void; + setSchema(keyPath: string, schema: atom$ConfigSchema): void; + removeAtKeyPath( + keyPath: string | null | undefined, + value: unknown | null | undefined, + ): unknown; + + // Used by nuclide-config to set the initial settings from disk + resetUserSettings(newSettings: Object, options?: {source?: string}): void; +} + +declare class atom$Cursor { + // Cursor Marker + marker: atom$Marker; + editor: atom$TextEditor; + + // Event Subscription + onDidChangePosition( + callback: (event: { + oldBufferPosition: atom$Point; + oldScreenPosition: atom$Point; + newBufferPosition: atom$Point; + newScreenPosition: atom$Point; + textChanged: boolean; + Cursor: atom$Cursor; + }) => unknown, + ): IDisposable; + + // Managing Cursor Position + getBufferRow(): number; + getBufferColumn(): number; + getBufferPosition(): atom$Point; + + // Cursor Position Details + // Moving the Cursor + moveUp(rowCount: number, arg1: {moveToEndOfSelection?: boolean}): void; + moveDown(rowCount: number, arg1: {moveToEndOfSelection?: boolean}): void; + + // Local Positions and Ranges + getCurrentWordBufferRange(options?: {wordRegex: RegExp}): atom$Range; + getCurrentWordPrefix(): string; + + // Visibility + // Comparing to another cursor + // Utilities + wordRegExp(options?: {includeNonWordCharacters: boolean}): RegExp; +} + +declare class atom$Decoration { + destroy(): void; + onDidChangeProperties( + callback: (event: { + oldProperties: Object; + newProperties: Object; + }) => unknown, + ): IDisposable; + onDidDestroy(callback: () => unknown): IDisposable; + getMarker(): atom$Marker; + getProperties(): Object; + setProperties(properties: unknown): void; +} + +declare class atom$DisplayMarkerLayer { + destroy(): void; + clear(): void; + isDestroyed(): boolean; + markBufferPosition( + position: atom$PointLike, + options?: MarkerOptions, + ): atom$Marker; + markBufferRange( + range: atom$Range | atom$RangeLike, + options?: MarkerOptions, + ): atom$Marker; + findMarkers(options: MarkerOptions): Array; + getMarkers(): Array; + onDidUpdate(callback: () => unknown): IDisposable; +} + +declare class atom$LayerDecoration { + destroy(): void; + isDestroyed(): boolean; + getProperties(): Object; + setProperties(properties: unknown): void; + setPropertiesForMarker(marker: atom$Marker, properties: unknown): void; +} + +declare class atom$Disposable { + constructor(disposalAction?: (...args: Array) => any); + disposed: boolean; + dispose(): void; +} + +declare class atom$Emitter { + onEventHandlerException(error: any): IDisposable; + dispose(): void; + on(name: string, callback: (v: any) => unknown): IDisposable; + once(name: string, callback: (v: any) => unknown): IDisposable; + preempt(name: string, callback: (v: any) => void): IDisposable; + // This is a flow hack to prevent emitting more than one value. + // `EventEmitter` allows emitting any number of values - making this a land + // mine, since we tend to think of `emit` as interchangeable. + // This hack only works if the extra value is not `undefined`, so this isn't + // full-proof, but it works for most cases. + emit(name: string, value: any, ...no_extra_args_allowed: Array): void; +} + +declare class atom$Gutter { + name: string; + destroy(): void; + decorateMarker( + marker: atom$Marker, + options?: {type?: string; class?: string; item?: Object | HTMLElement}, + ): atom$Decoration; + show(): void; + hide(): void; + onDidDestroy(callback: () => void): IDisposable; +} + +declare type atom$MarkerChangeEvent = { + oldHeadScreenPosition: atom$Point; + newHeadScreenPosition: atom$Point; + oldTailScreenPosition: atom$Point; + newTailScreenPosition: atom$Point; + + oldHeadBufferPosition: atom$Point; + newHeadBufferPosition: atom$Point; + oldTailBufferPosition: atom$Point; + newTailBufferPosition: atom$Point; + + isValid: boolean; + textChanged: boolean; +}; + +declare class atom$Marker { + destroy(): void; + getBufferRange(): atom$Range; + getStartBufferPosition(): atom$Point; + onDidChange( + callback: (event: atom$MarkerChangeEvent) => unknown, + ): IDisposable; + isValid(): boolean; + isDestroyed(): boolean; + onDidDestroy(callback: () => unknown): IDisposable; + getScreenRange(): atom$Range; + setBufferRange(range: atom$RangeLike, properties?: {reversed: boolean}): void; + id: number; +} + +declare class atom$ServiceHub { + provide(keyPath: string, version: string, service: T): IDisposable; + consume( + keyPath: string, + versionRange: string, + callback: (provider: T) => unknown, + ): IDisposable; +} + +type atom$PackageMetadata = { + name: string; + version: string; +}; + +declare class atom$PackageManager { + readonly initialPackagesActivated: boolean; + + // Event Subscription + onDidLoadInitialPackages(callback: () => void): IDisposable; + onDidActivateInitialPackages(callback: () => void): IDisposable; + onDidActivatePackage(callback: (pkg: atom$Package) => unknown): IDisposable; + onDidDeactivatePackage(callback: (pkg: atom$Package) => unknown): IDisposable; + onDidLoadPackage(callback: (pkg: atom$Package) => unknown): IDisposable; + onDidUnloadPackage(callback: (pkg: atom$Package) => unknown): IDisposable; + onDidTriggerActivationHook( + activationHook: string, + callback: () => unknown, + ): IDisposable; + + // Package system data + getApmPath(): string; + getPackageDirPaths(): Array; + + // General package data + resolvePackagePath(name: string): string | null | undefined; + isBundledPackage(name: string): boolean; + + // Enabling and disabling packages + enablePackage(name: string): atom$Package | null | undefined; + disablePackage(name: string): atom$Package | null | undefined; + isPackageDisabled(name: string): boolean; + + // Accessing active packages + getActivePackage(name: string): atom$Package | null | undefined; + getActivePackages(): Array; + isPackageActive(name: string): boolean; + hasActivatedInitialPackages(): boolean; + + // Activating and deactivating packages + activatePackage(name: string): Promise; + + // Accessing loaded packages + getLoadedPackage(name: string): atom$Package | null | undefined; + getLoadedPackages(): Array; + isPackageLoaded(name: string): boolean; + hasLoadedInitialPackages(): boolean; + + // Accessing available packages + getAvailablePackageNames(): Array; + getAvailablePackageMetadata(): Array; + + // (Undocumented.) + activate(): Promise; + deactivatePackages(): Promise; + deactivatePackage( + name: string, + suppressSerialization?: boolean, + ): Promise; + emitter: atom$Emitter; + loadedPackages: { + [packageName: string]: atom$Package; + }; + loadPackage(name: string): void; + loadPackages(): void; + serializePackage(pkg: atom$Package): void; + serviceHub: atom$ServiceHub; + packageDirPaths: Array; + triggerActivationHook(hook: string): void; + triggerDeferredActivationHooks(): void; + unloadPackage(name: string): void; + unloadPackages(): void; +} + +declare class atom$StyleManager { + // Event Subscription + + // Reading Style Elements + getStyleElements(): Array; + + // Paths + getUserStyleSheetPath(): string; + + // (Undocumented.) + addStyleSheet( + source: string, + params: { + sourcePath?: string; + context?: boolean; + priority?: number; + skipDeprecatedSelectorsTransformation?: boolean; + }, + ): IDisposable; +} + +type atom$PaneSplitParams = { + copyActiveItem?: boolean; + items?: Array; +}; + +type atom$PaneSplitOrientation = 'horizontal' | 'vertical'; +type atom$PaneSplitSide = 'before' | 'after'; + +// Undocumented class +declare class atom$applicationDelegate { + focusWindow(): Promise; + open(params: { + pathsToOpen: Array; + newWindow?: boolean; + devMode?: boolean; + safeMode?: boolean; + }): void; + + // Used by nuclide-config to replicate atom.config saveCallback + setUserSettings( + config: atom$Config, + configFilePath: string, + ): Promise; +} + +type atom$PaneParams = { + activeItem?: Object; + applicationDelegate: atom$applicationDelegate; + focused?: boolean; + container: Object; + config: atom$Config; + notificationManager: atom$NotificationManager; + deserializerManager: atom$DeserializerManager; + items?: Array; + itemStackIndices?: Array; + flexScale?: number; +}; + +declare class atom$Pane { + // Items + addItem(item: Object, options?: {index?: number; pending?: boolean}): Object; + getItems(): Array; + getActiveItem(): Object | null | undefined; + itemAtIndex(index: number): Object | null | undefined; + getActiveItemIndex(): number; + activateItem(item: Object): Object | null | undefined; + activateItemAtIndex(index: number): void; + moveItemToPane(item: Object, pane: atom$Pane, index: number): void; + destroyItem(item: Object, force?: boolean): Promise; + itemForURI(uri: string): Object; + + // Event subscriptions. + onDidAddItem(cb: (event: {item: Object; index: number}) => void): IDisposable; + onDidRemoveItem( + cb: (event: {item: Object; index: number}) => void, + ): IDisposable; + onWillRemoveItem( + cb: (event: {item: Object; index: number}) => void, + ): IDisposable; + onDidDestroy(cb: () => unknown): IDisposable; + onDidChangeFlexScale(cb: (newFlexScale: number) => void): IDisposable; + onWillDestroy(cb: () => void): IDisposable; + observeActiveItem(cb: (item: Object | null | undefined) => void): IDisposable; + + // Lifecycle + isActive(): boolean; + activate(): void; + destroy(): void; + isDestroyed(): void; + + // Splitting + splitLeft(params?: atom$PaneSplitParams): atom$Pane; + splitRight(params?: atom$PaneSplitParams): atom$Pane; + splitUp(params?: atom$PaneSplitParams): atom$Pane; + splitDown(params?: atom$PaneSplitParams): atom$Pane; + split( + orientation: atom$PaneSplitOrientation, + side: atom$PaneSplitSide, + params?: atom$PaneSplitParams, + ): atom$Pane; + + // Undocumented Methods + constructor(params: atom$PaneParams); + getPendingItem(): atom$PaneItem; + setPendingItem(item: atom$PaneItem): void; + clearPendingItem(): void; + getFlexScale(): number; + getElement(): HTMLElement; + getParent(): Object; + removeItem(item: Object, moved: boolean | null | undefined): void; + setActiveItem(item: Object): Object; + setFlexScale(flexScale: number): number; + getContainer(): atom$PaneContainer; + getActiveEditor(): atom$TextEditor | null | undefined; + + element: HTMLElement; +} + +declare interface atom$PaneItem { + // These are all covariant, meaning that these props are read-only. Therefore we can assign an + // object with more strict requirements to an variable of this type. + readonly getTitle: () => string; + readonly getLongTitle?: () => string; + readonly getIconName?: () => string; + readonly getURI?: () => string | null | undefined; + readonly onDidChangeIcon?: (cb: (icon: string) => void) => IDisposable; + readonly onDidChangeTitle?: (cb: (title: string) => void) => IDisposable; + readonly onDidTerminatePendingState?: (arg0: () => unknown) => IDisposable; + readonly serialize?: () => Object; + readonly terminatePendingState?: () => void; +} + +// Undocumented class +declare class atom$PaneAxis { + getFlexScale(): number; + setFlexScale(flexScale: number): number; + getItems(): Array; +} + +// Undocumented class +// Note that this is not the same object returned by `atom.workspace.getPaneContainers()`. (Those +// are typed here as AbstractPaneContainers and, in the current implementation, wrap these.) +declare class atom$PaneContainer { + constructor(arg0: { + config: atom$Config; + applicationDelegate: atom$applicationDelegate; + notificationManager: atom$NotificationManager; + deserializerManager: atom$DeserializerManager; + }); + destroy(): void; + getActivePane(): atom$Pane; + getActivePaneItem(): Object | null | undefined; + getLocation(): atom$PaneLocation; + getPanes(): Array; + getPaneItems(): Array; + observePanes(cb: (pane: atom$Pane) => void): IDisposable; + onDidAddPane(cb: (event: {pane: atom$Pane}) => void): IDisposable; + onDidDestroyPane(cb: (event: {pane: atom$Pane}) => void): IDisposable; + onWillDestroyPane(cb: (event: {pane: atom$Pane}) => void): IDisposable; + onDidAddPaneItem(cb: (item: atom$PaneItem) => void): IDisposable; + onDidDestroyPaneItem(cb: (item: atom$Pane) => void): IDisposable; + paneForItem(item: Object): atom$Pane | null | undefined; + serialize(): Object; +} + +declare class atom$Panel { + // Construction and Destruction + destroy(): void; + + // Event Subscription + onDidChangeVisible(callback: (visible: boolean) => any): IDisposable; + onDidDestroy(callback: (panel: atom$Panel) => any): IDisposable; + + // Panel Details + getElement(): HTMLElement; + getItem(): any; + getPriority(): number; + isVisible(): boolean; + hide(): void; + show(): void; +} + +type atom$PointObject = {row: number; column: number}; + +type atom$PointLike = atom$Point | [number, number] | atom$PointObject; + +declare class atom$Point { + fromObject( + object: atom$PointLike, + copy: boolean | null | undefined, + ): atom$Point; + constructor(row: number, column: number); + row: number; + column: number; + copy(): atom$Point; + negate(): atom$Point; + + // Comparison + min(point1: atom$PointLike, point2: atom$PointLike): atom$Point; + compare(other: atom$PointLike): -1 | 0 | 1; + isEqual(otherRange: atom$PointLike): boolean; + isLessThan(other: atom$PointLike): boolean; + isLessThanOrEqual(other: atom$PointLike): boolean; + isGreaterThan(other: atom$PointLike): boolean; + isGreaterThanOrEqual(other: atom$PointLike): boolean; + + // Operations + translate(other: atom$PointLike): atom$Point; + + // Conversion + serialize(): [number, number]; + toArray(): [number, number]; +} + +type atom$RangeObject = { + start: atom$PointObject; + end: atom$PointObject; +}; + +type atom$RangeLike = + | atom$Range + | atom$RangeObject // TODO: Flow doesn't really handle the real signature below... + | [atom$PointLike, atom$PointLike] + | { + start: atom$PointLike; + end: atom$PointLike; + }; + +declare class atom$Range { + fromObject(object: atom$RangeLike, copy?: boolean): atom$Range; + fromPointWithDelta( + startPoint: atom$PointLike, + rowDelta: number, + columnDelta: number, + ): atom$Range; + + constructor(pointA: atom$PointLike, pointB: atom$PointLike); + compare(other: atom$Range): number; + start: atom$Point; + end: atom$Point; + isEmpty(): boolean; + isEqual(otherRange: atom$RangeLike): boolean; + isSingleLine(): boolean; + intersectsWith(otherRange: atom$RangeLike, exclusive?: boolean): boolean; + containsPoint(point: atom$PointLike, exclusive?: boolean): boolean; + containsRange(other: atom$Range, exclusive?: boolean): boolean; + union(other: atom$Range): atom$Range; + serialize(): Array>; + translate(startDelta: atom$PointLike, endDelta?: atom$PointLike): atom$Range; + getRowCount(): number; + getRows(): Array; +} + +type RawStatusBarTile = { + item: HTMLElement; + priority: number; +}; + +type atom$StatusBarTile = { + getPriority(): number; + getItem(): HTMLElement; + destroy(): void; +}; + +declare class atom$ScopeDescriptor { + constructor(object: {scopes: Array}); + getScopesArray(): Array; +} + +type atom$ScopeDescriptorLike = atom$ScopeDescriptor | Array; + +/** + * This API is defined at https://github.com/atom/status-bar. + */ +declare class atom$StatusBar { + addLeftTile(tile: RawStatusBarTile): atom$StatusBarTile; + addRightTile(tile: RawStatusBarTile): atom$StatusBarTile; + getLeftTiles(): Array; + getRightTiles(): Array; +} + +// https://github.com/atom/atom/blob/v1.9.0/src/text-editor-registry.coffee +declare class atom$TextEditorRegistry { + add(editor: atom$TextEditor): IDisposable; + remove(editor: atom$TextEditor): boolean; + observe(callback: (editor: atom$TextEditor) => void): IDisposable; + build: (params: atom$TextEditorParams) => atom$TextEditor; + + // Private + editors: Set; +} + +declare class atom$ThemeManager { + // Event Subscription + + /** + * As recent as Atom 1.0.10, the implementation of this method was: + * + * ``` + * onDidChangeActiveThemes: (callback) -> + * @emitter.on 'did-change-active-themes', callback + * @emitter.on 'did-reload-all', callback # TODO: Remove once deprecated pre-1.0 APIs are gone + * ``` + * + * Due to the nature of CoffeeScript, onDidChangeActiveThemes returns a Disposable even though it + * is not documented as doing so. However, the Disposable that it does return removes the + * subscription on the 'did-reload-all' event (which is supposed to be deprecated) rather than the + * 'did-change-active-themes' one. + */ + onDidChangeActiveThemes(callback: () => unknown): IDisposable; + + // Accessing Loaded Themes + getLoadedThemeNames(): Array; + getLoadedThemes(): Array; // TODO: Define undocumented ThemePackage class. + + // Accessing Active Themes + getActiveThemeNames(): Array; + getActiveThemes(): Array; // TODO: Define undocumented ThemePackage class. + + // Managing Enabled Themes + getEnabledThemeNames(): Array; + + // Private + activateThemes(): Promise; + requireStylesheet(stylesheetPath: string): IDisposable; +} + +type atom$TooltipsPlacementOption = + | 'top' + | 'bottom' + | 'left' + | 'right' + | 'auto'; + +type atom$TooltipsAddOptions = { + title?: string; + item?: HTMLElement; + keyBindingCommand?: string; + keyBindingTarget?: HTMLElement; + animation?: boolean; + container?: string | false; + delay?: number | {show: number; hide: number}; + placement?: + | atom$TooltipsPlacementOption + | (() => atom$TooltipsPlacementOption); + trigger?: string; +}; + +type atom$Tooltip = { + show(): void; + hide(): void; + getTooltipElement(): HTMLElement; +}; + +declare class atom$TooltipManager { + tooltips: Map>; + add(target: HTMLElement, options: atom$TooltipsAddOptions): IDisposable; + findTooltips(arg0: HTMLElement): Array; +} + +type InsertTextOptions = { + select: boolean; + autoIndent: boolean; + autoIndentNewline: boolean; + autoDecreaseIndent: boolean; + normalizeLineEndings: boolean | null | undefined; + undo: string; +}; + +type DecorateMarkerParams = + | { + type: 'line'; + class: string; + onlyHead?: boolean; + onlyEmpty?: boolean; + onlyNonEmpty?: boolean; + } + | { + type: 'gutter'; + item?: HTMLElement; + class?: string; + onlyHead?: boolean; + onlyEmpty?: boolean; + onlyNonEmpty?: boolean; + gutterName?: string; + } + | { + type: 'highlight'; + class?: string; + gutterName?: string; + } + | { + type: 'overlay'; + item: Object; + position?: 'head' | 'tail'; // Defaults to 'head' when unspecified. + } + | { + type: 'block'; + item: HTMLElement; + position?: 'before' | 'after'; // Defaults to 'before' when unspecified. + } + | { + type: 'line-number'; + class?: string; + }; + +type ChangeCursorPositionEvent = { + oldBufferPosition: atom$Point; + oldScreenPosition: atom$Point; + newBufferPosition: atom$Point; + newScreenPosition: atom$Point; + textChanged: boolean; + cursor: atom$Cursor; +}; + +type MarkerOptions = { + reversed?: boolean; + tailed?: boolean; + invalidate?: 'never' | 'surround' | 'overlap' | 'inside' | 'touch'; + exclusive?: boolean; +}; + +type atom$ChangeSelectionRangeEvent = { + oldBufferRange: atom$Range; + oldScreenRange: atom$Range; + newBufferRange: atom$Range; + newScreenRange: atom$Range; + selection: atom$Selection; +}; + +declare class atom$TextEditor extends atom$Model { + id: number; + verticalScrollMargin: number; + + // Event Subscription + onDidChange(callback: () => void): IDisposable; + onDidChangePath(callback: (newPath: string) => unknown): IDisposable; + onDidStopChanging(callback: () => unknown): IDisposable; + onDidChangeCursorPosition( + callback: (event: ChangeCursorPositionEvent) => unknown, + ): IDisposable; + onDidAddCursor(callback: (cursor: atom$Cursor) => unknown): IDisposable; + onDidRemoveCursor(callback: (cursor: atom$Cursor) => unknown): IDisposable; + onDidDestroy(callback: () => unknown): IDisposable; + onDidSave(callback: (event: {path: string}) => unknown): IDisposable; + getBuffer(): atom$TextBuffer; + observeGrammar(callback: (grammar: atom$Grammar) => unknown): IDisposable; + onWillInsertText( + callback: (event: {cancel: () => void; text: string}) => void, + ): IDisposable; + // Note that the range property of the event is undocumented. + onDidInsertText( + callback: (event: {text: string; range: atom$Range}) => unknown, + ): IDisposable; + onDidChangeSoftWrapped( + callback: (softWrapped: boolean) => unknown, + ): IDisposable; + onDidChangeSelectionRange( + callback: (event: atom$ChangeSelectionRangeEvent) => unknown, + ): IDisposable; + observeSelections( + callback: (selection: atom$Selection) => unknown, + ): IDisposable; + onDidAddSelection( + callback: (selection: atom$Selection) => unknown, + ): IDisposable; + + // File Details + getTitle: () => string; + getLongTitle(): string; + + /** + * If you open Atom via Spotlight such that it opens with a tab named + * "untitled" that does not correspond to a file on disk, this will return + * null. + */ + getPath(): string | null | undefined; + getURI: () => string | null | undefined; + insertNewline(): void; + isModified: () => boolean; + isEmpty(): boolean; + getEncoding(): buffer$Encoding; + setEncoding(encoding: string): void; + getTabLength(): number; + getSoftTabs(): boolean; + getIconName(): string; + onDidChangeIcon(cb: (icon: string) => void): IDisposable; + onDidChangeTitle(cb: (title: string) => void): IDisposable; + + // File Operations + save(): Promise; + // DO NOT USE: Doesn't work with remote text buffers! + // saveAs(filePath: string): void, + + // Reading Text + getText(): string; + getTextInBufferRange(range: atom$RangeLike): string; + getLineCount(): number; + getScreenLineCount(): number; + getLastScreenRow(): number; + + // Mutating Text + setText(text: string, options?: InsertTextOptions): void; + setTextInBufferRange( + range: atom$RangeLike, + text: string, + options?: { + normalizeLineEndings?: boolean; + undo?: string; + }, + ): atom$Range; + insertText(text: string): Array | false; + mutateSelectedText( + fn: (selection: atom$Selection, index: number) => void, + ): void; + delete: () => void; + backspace: () => void; + duplicateLines: () => void; + + // History + createCheckpoint(): atom$TextBufferCheckpoint; + revertToCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean; + terminatePendingState(): void; + transact(fn: () => unknown, _: void): void; + transact(groupingInterval: number, fn: () => unknown): void; + onDidTerminatePendingState(arg0: () => unknown): IDisposable; + + // TextEditor Coordinates + screenPositionForBufferPosition( + bufferPosition: atom$PointLike, + options?: { + wrapBeyondNewlines?: boolean; + wrapAtSoftNewlines?: boolean; + screenLine?: boolean; + }, + ): atom$Point; + bufferPositionForScreenPosition( + screenPosition: atom$PointLike, + options?: { + wrapBeyondNewlines?: boolean; + wrapAtSoftNewlines?: boolean; + screenLine?: boolean; + }, + ): atom$Point; + getEofBufferPosition(): atom$Point; + getVisibleRowRange(): [number, number]; + bufferRowForScreenRow(screenRow: number): number; + screenRangeForBufferRange(bufferRange: atom$RangeLike): atom$Range; + bufferRangeForBufferRow(bufferRow: number): atom$Range; + + // Decorations + decorateMarker( + marker: atom$Marker, + decorationParams: DecorateMarkerParams, + ): atom$Decoration; + decorateMarkerLayer( + markerLayer: atom$DisplayMarkerLayer, + decorationParams: DecorateMarkerParams, + ): atom$LayerDecoration; + decorationsForScreenRowRange( + startScreenRow: number, + endScreenRow: number, + ): { + [markerId: string]: Array; + }; + getDecorations(options?: { + class?: string; + type?: string; + }): Array; + + // Markers + addMarkerLayer(): atom$DisplayMarkerLayer; + getDefaultMarkerLayer(): atom$DisplayMarkerLayer; + markBufferPosition( + position: atom$PointLike, + options?: MarkerOptions, + ): atom$Marker; + markBufferRange(range: atom$RangeLike, options?: MarkerOptions): atom$Marker; + markScreenRange(range: atom$RangeLike, options?: MarkerOptions): atom$Marker; + markScreenPosition( + position: atom$PointLike, + options?: MarkerOptions, + ): atom$Marker; + findMarkers(options: MarkerOptions): Array; + getMarkerCount(): number; + + // Cursors + getCursors(): Array; + setCursorBufferPosition( + position: atom$PointLike, + options?: { + autoscroll?: boolean; + wrapBeyondNewlines?: boolean; + wrapAtSoftNewlines?: boolean; + screenLine?: boolean; + }, + ): void; + getCursorBufferPosition(): atom$Point; + getCursorBufferPositions(): Array; + getCursorScreenPosition(): atom$Point; + getCursorScreenPositions(): Array; + getLastCursor(): atom$Cursor; + addCursorAtBufferPosition(point: atom$PointLike): atom$Cursor; + moveToBeginningOfLine(): void; + moveToEndOfLine(): void; + moveToBottom(): void; + + // Folds + foldCurrentRow(): void; + unfoldCurrentRow(): void; + foldBufferRow(bufferRow: number): void; + unfoldBufferRow(bufferRow: number): void; + + // Selections + getLastSelection(): atom$Selection; + getSelectedText(): string; + selectAll(): void; + getSelectedBufferRange(): atom$Range; + getSelectedBufferRanges(): Array; + getSelections(): Array; + selectToBufferPosition(point: atom$Point): void; + setSelectedBufferRange( + bufferRange: atom$RangeLike, + options?: { + reversed?: boolean; + preserveFolds?: boolean; + }, + ): void; + setSelectedBufferRanges( + bufferRanges: Array, + options?: { + reversed?: boolean; + preserveFolds?: boolean; + }, + ): void; + selectWordsContainingCursors(): void; + + // Folds + unfoldAll(): void; + + // Searching and Replacing + scanInBufferRange( + regex: RegExp, + range: atom$Range, + iterator: (foundMatch: { + match: unknown; + matchText: string; + range: atom$Range; + stop: () => unknown; + replace: (replaceWith: string) => unknown; + }) => unknown, + ): void; + + scan( + regex: RegExp, + iterator: (foundMatch: { + match: RegExp$matchResult; + matchText: string; + range: atom$Range; + stop: () => unknown; + replace: (replaceWith: string) => unknown; + }) => unknown, + ): void; + + // Tab Behavior + // Soft Wrap Behavior + // Indentation + indentationForBufferRow(bufferRow: number): number; + setTabLength(tabLength: number): void; + setSoftTabs(softTabs: boolean): void; + + lineTextForBufferRow(bufferRow: number): string; + lineTextForScreenRow(screenRow: number): string; + + // Grammars + getGrammar(): atom$Grammar; + setGrammar(grammar: atom$Grammar | null | undefined): void; + + // Clipboard Operations + pasteText: (options?: Object) => void; + copySelectedText: () => void; + + // Managing Syntax Scopes + getRootScopeDescriptor(): atom$ScopeDescriptor; + scopeDescriptorForBufferPosition( + bufferPosition: atom$PointLike, + ): atom$ScopeDescriptor; + + // Gutter + addGutter(options: { + name: string; + priority?: number; + visible?: boolean; + }): atom$Gutter; + observeGutters(callback: (gutter: atom$Gutter) => void): IDisposable; + getGutters(): Array; + gutterWithName(name: string): atom$Gutter | null | undefined; + + // Scrolling the TextEditor + scrollToBufferPosition( + position: + | atom$Point + | [number | null | undefined, number | null | undefined], + options?: {center?: boolean}, + ): void; + scrollToScreenPosition( + position: + | atom$Point + | [number | null | undefined, number | null | undefined], + options?: {center?: boolean}, + ): void; + scrollToScreenRange( + screenRange: atom$Range, + options?: {clip?: boolean}, + ): void; + scrollToCursorPosition(options?: {center?: boolean}): void; + scrollToBottom(): void; + scrollToTop(): void; + + // TextEditor Rendering + getPlaceholderText(): string; + setPlaceholderText(placeholderText: string): void; + + // This is undocumented, but Nuclide uses it in the AtomTextEditor wrapper. + setLineNumberGutterVisible(lineNumberGutterVisible: boolean): void; + + // Editor Options + setSoftWrapped(softWrapped: boolean): void; + + isFoldedAtBufferRow(row: number): boolean; + getLastBufferRow(): number; + + // Undocumented Methods + getElement(): atom$TextEditorElement; + getDefaultCharWidth(): number; + getLineHeightInPixels(): number; + moveToTop(): void; + tokenForBufferPosition( + position: + | atom$Point + | [number | null | undefined, number | null | undefined], + ): atom$Token; + onDidConflict(callback: () => void): IDisposable; + serialize(): Object; + foldBufferRowRange(startRow: number, endRow: number): void; + getNonWordCharacters(position?: atom$PointLike): string; + scheduleComponentUpdate(): void; +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need to reach into this object + * via `atom$TextEditorElement` to do some things that we have no other way to do. + */ +declare class atom$TextEditorComponent { + domNode: HTMLElement; + scrollViewNode: HTMLElement; + presenter: atom$TextEditorPresenter; + refs: atom$TextEditorComponentRefs; + linesComponent: atom$LinesComponent; + // NOTE: This is typed as a property to allow overwriting. + startCursorBlinking: () => void; + stopCursorBlinking(): void; + pixelPositionForScreenPosition( + screenPosition: atom$Point, + clip?: boolean, + ): {top: number; left: number}; + screenPositionForMouseEvent(event: MouseEvent): atom$Point; + pixelPositionForMouseEvent( + event: MouseEvent, + linesClientRect?: { + top: number; + left: number; + bottom: number; + right: number; + }, + ): {top: number; left: number; bottom: number; right: number}; + invalidateBlockDecorationDimensions(decoration: atom$Decoration): void; + element: atom$TextEditorElement; + didFocus(): void; + setScrollTop(scrollTop: number): void; + getScrollTop(): number; + + setScrollLeft(scrollLeft: number): void; + getScrollLeft(): number; + updateSync(useScheduler?: boolean): void; +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need to reach into this object + * via `atom$TextEditorComponent` to do some things that we have no other way to do. + */ +declare class atom$TextEditorPresenter { + startBlinkingCursors: () => void; + stopBlinkingCursors(visible: boolean): void; + updateLineNumberGutterState(): void; +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need it to access + * the deepest dom element receiving DOM events. + */ +declare class atom$LinesComponent { + domNode: HTMLElement; + getDomNode(): HTMLElement; +} + +/** + * This is not part of the official Atom 1.0 API. Nevertheless, we need it to access + * the deepest dom element receiving DOM events. + */ +declare class atom$TextEditorComponentRefs { + lineTiles: HTMLElement; +} + +/** + * This is not part of the official Atom 1.0 API, but it really should be. This is the element that + * is returned when you run `atom.views.getView()`. + */ +declare class atom$TextEditorElement extends HTMLElement { + component: atom$TextEditorComponent | null | undefined; + getModel(): atom$TextEditor; + setModel(model: atom$TextEditor): void; + pixelPositionForBufferPosition( + bufferPosition: atom$PointLike, + ): {top: number; left: number}; + pixelPositionForScreenPosition( + screenPosition: atom$Point, + ): { + left: number; + top: number; + }; + + setScrollTop(scrollTop: number): void; + getScrollTop(): number; + + setScrollLeft(scrollLeft: number): void; + getScrollLeft(): number; + + getScrollHeight(): number; + getHeight(): number; + + onDidChangeScrollTop(callback: (scrollTop: number) => unknown): IDisposable; + onDidChangeScrollLeft(callback: (scrollLeft: number) => unknown): IDisposable; + + // Called when the editor is attached to the DOM. + onDidAttach(callback: () => unknown): IDisposable; + // Called when the editor is detached from the DOM. + onDidDetach(callback: () => unknown): IDisposable; + + measureDimensions(): void; + + // Undocumented Methods + + // Returns a promise that resolves after the next update. + getNextUpdatePromise(): Promise; + + // `undefined` means no explicit width. `null` sets a zero width (which is almost certainly a + // mistake) so we don't allow it. + setWidth(width: number | void): void; +} + +declare class atom$ViewProvider { + modelConstructor: Function; +} + +declare class atom$ViewRegistry { + // Methods + addViewProvider( + modelConstructor: any, + createView?: (...args: Array) => HTMLElement | null | undefined, + ): IDisposable; + getView(textEditor: atom$TextEditor): atom$TextEditorElement; + getView(notification: atom$Notification): HTMLElement; + getView(gutter: atom$Gutter): HTMLElement; + getView(panel: atom$Panel): HTMLElement; + getView(workspace: atom$Workspace): HTMLElement; + getView(object: Object): HTMLElement; + providers: Array; +} + +type atom$WorkspaceAddPanelOptions = { + item: Object; + visible?: boolean; + priority?: number; + className?: string; +}; + +type atom$TextEditorParams = { + buffer?: atom$TextBuffer; + lineNumberGutterVisible?: boolean; +}; + +type DestroyPaneItemEvent = { + item: atom$PaneItem; + pane: atom$Pane; + index: number; +}; + +type AddPaneItemEvent = { + item: atom$PaneItem; + pane: atom$Pane; + index: number; +}; + +type OnDidOpenEvent = { + uri: string; + item: unknown; + pane: atom$Pane; + index: number; +}; + +type AddTextEditorEvent = { + textEditor: atom$TextEditor; + pane: atom$Pane; + index: number; +}; + +type atom$WorkspaceOpenOptions = { + activatePane?: boolean | null | undefined; + activateItem?: boolean | null | undefined; + initialLine?: number | null | undefined; + initialColumn?: number | null | undefined; + pending?: boolean | null | undefined; + split?: string | null | undefined; + searchAllPanes?: boolean | null | undefined; + location?: atom$PaneLocation; +}; + +declare class atom$Workspace { + // Event Subscription + observePanes(cb: (pane: atom$Pane) => void): IDisposable; + observeTextEditors( + callback: (editor: atom$TextEditor) => unknown, + ): IDisposable; + observeActiveTextEditor( + callback: (editor: atom$TextEditor | null | undefined) => unknown, + ): IDisposable; + onDidAddTextEditor( + callback: (event: AddTextEditorEvent) => unknown, + ): IDisposable; + onDidChangeActivePaneItem(callback: (item: unknown) => unknown): IDisposable; + onDidDestroyPaneItem( + callback: (event: DestroyPaneItemEvent) => unknown, + ): IDisposable; + onDidAddPaneItem(callback: (event: AddPaneItemEvent) => unknown): IDisposable; + observeActivePaneItem( + callback: (item: unknown | null | undefined) => unknown, + ): IDisposable; + onDidStopChangingActivePaneItem( + callback: (item: unknown | null | undefined) => unknown, + ): IDisposable; + observePaneItems(callback: (item: unknown) => unknown): IDisposable; + onWillDestroyPaneItem( + callback: (event: {item: unknown; pane: unknown; index: number}) => unknown, + ): IDisposable; + onDidOpen(callback: (event: OnDidOpenEvent) => unknown): IDisposable; + + getElement(): HTMLElement; + + // Opening + open( + uri?: string, + options?: atom$WorkspaceOpenOptions, + ): Promise; + openURIInPane( + uri?: string, + pane: atom$Pane, + options?: { + initialLine?: number; + initialColumn?: number; + activePane?: boolean; + searchAllPanes?: boolean; + }, + ): Promise; + isTextEditor(item: unknown | null | undefined): boolean; + + /* Optional method because this was added post-1.0. */ + buildTextEditor: ( + params: atom$TextEditorParams | null | undefined, + ) => atom$TextEditor; + + /* Optional method because this was added in 1.9.0 */ + handleGrammarUsed?: (grammar: atom$Grammar) => void; + reopenItem(): Promise; + addOpener(callback: (uri: string) => any): IDisposable; + hide(uriOrItem: string | Object): void; + toggle(uriOrItem: string | Object): void; + + // Pane Containers + getPaneContainers(): Array; + paneContainerForItem( + item: unknown | null | undefined, + ): atom$AbstractPaneContainer | null | undefined; + + // Pane Items + getPaneItems(): Array; + getActivePaneItem(): Object | null | undefined; + getActivePaneContainer(): atom$PaneContainer; + getTextEditors(): Array; + getActiveTextEditor(): atom$TextEditor | null | undefined; + createItemForURI( + uri: string, + options: atom$WorkspaceOpenOptions, + ): atom$PaneItem; + + // Panes + getPanes(): Array; + getActivePane(): atom$Pane; + activateNextPane(): boolean; + activatePreviousPane(): boolean; + paneForURI(uri: string): atom$Pane; + paneForItem(item: unknown): atom$Pane | null | undefined; + paneContainers: { + [location in atom$PaneLocation]?: atom$AbstractPaneContainer + }; + + // Panels + panelContainers: { + [location: string]: atom$PanelContainer; + }; + getBottomPanels(): Array; + addBottomPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel; + getLeftPanels(): Array; + addLeftPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel; + getRightPanels(): Array; + addRightPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel; + getTopPanels(): Array; + addTopPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel; + getModalPanels(): Array; + addModalPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel; + getHeaderPanels(): Array; + addHeaderPanel(options: atom$WorkspaceAddPanelOptions): atom$Panel; + + getLeftDock(): atom$Dock; + getRightDock(): atom$Dock; + getBottomDock(): atom$Dock; + getCenter(): atom$WorkspaceCenter; + + // Searching and Replacing + scan( + regex: RegExp, + options: { + paths?: Array; + onPathsSearched?: (numSearched: number) => unknown; + leadingContextLineCount?: number; + trailingContextLineCount?: number; + }, + iterator: ( + arg0: + | { + filePath: string; + matches: Array<{ + leadingContextLines: Array; + lineText: string; + lineTextOffset: number; + range: atom$RangeLike; + matchText: string; + trailingContextLines: Array; + }>; + } + | null + | undefined, + arg1: Error, + ) => unknown, + ): Promise; + + destroyActivePaneItemOrEmptyPane(): void; + destroyActivePaneItem(): void; +} + +declare class atom$AbstractPaneContainer { + activate(): void; + getLocation(): atom$PaneLocation; + getElement(): HTMLElement; + isVisible(): boolean; + show(): void; + hide(): void; + getActivePane(): atom$Pane; + getPanes(): Array; + onDidAddPaneItem(arg0: (item: {item: Object}) => void): IDisposable; + observePanes(cb: (pane: atom$Pane) => void): IDisposable; + state: { + size: number; + }; +} + +declare class atom$Dock extends atom$AbstractPaneContainer { + // This is a woefully incomplete list, items can be added as needed from + // https://github.com/atom/atom/blob/master/src/dock.js + toggle(): void; +} + +declare class atom$WorkspaceCenter extends atom$AbstractPaneContainer { + activate(): void; + + // Pane Items + getPaneItems(): Array; + getActivePaneItem(): atom$PaneItem | null | undefined; + getTextEditors(): Array; + getActiveTextEditor(): atom$TextEditor | null | undefined; + + observeActivePaneItem( + callback: (arg0: atom$PaneItem) => unknown, + ): IDisposable; + onDidChangeActivePaneItem(callback: (item: unknown) => unknown): IDisposable; + onDidAddTextEditor( + callback: (item: { + textEditor: atom$TextEditor; + pane: atom$Pane; + index: number; + }) => unknown, + ): IDisposable; + // This should be removed soon anyway, it's currently deprecated. + paneContainer: Object; +} + +/** + * Extended Classes + */ +declare class atom$BufferedNodeProcess {} + +declare class atom$BufferedProcess { + // Event Subscription + onWillThrowError( + callback: (errorObject: {error: Object; handle: unknown}) => unknown, + ): IDisposable; + // Helper Methods + kill(): void; +} + +declare class atom$Clipboard { + // Methods + write(text: string, metadata?: unknown): void; + read(): string; + readWithMetadata(): { + metadata: unknown | null | undefined; + text: string; + }; +} + +declare class atom$ContextMenuManager { + add(itemsBySelector: { + [cssSelector: string]: Array; + }): IDisposable; + itemSets: Array; + + // Undocumented methods + showForEvent(event: Event): void; + templateForEvent(event: Event): Array; +} + +declare class atom$ContextMenuItemSet { + items: Array; + selector: string; +} + +type atom$ContextMenuItem = { + command?: string; + created?: (event: MouseEvent) => void; + enabled?: boolean; + label?: string; + shouldDisplay?: (event: MouseEvent) => boolean; + submenu?: Array; + type?: string; + visible?: boolean; +}; + +type atom$Deserializer = { + name: string; + deserialize: (state: Object) => unknown; +}; + +declare class atom$DeserializerManager { + add(...deserializers: Array): IDisposable; + deserialize(state: Object, params?: Object): unknown; +} + +// Apparently it can sometimes include a `code` property. +declare class atom$GetEntriesError extends Error { + code?: string; +} + +declare class atom$Directory { + constructor(dirname?: string); + + symlink: boolean; + + // Construction + create(mode?: number): Promise; + + // Event Subscription + onDidChange(callback: () => unknown): IDisposable; + + // Directory Metadata + isFile(): boolean; + isDirectory(): boolean; + exists(): Promise; + + // Managing Paths + getPath(): string; + getBaseName(): string; + relativize(fullPath: string): string; + + // Event Subscription + onDidRename(callback: () => void): IDisposable; + onDidDelete(callback: () => void): IDisposable; + + // Traversing + getParent(): atom$Directory; + getFile(filename: string): atom$File; + getSubdirectory(dirname: string): atom$Directory; + getEntries( + callback: ( + error: atom$GetEntriesError | null | undefined, + entries: Array | null | undefined, + ) => unknown, + ): void; + contains(path: string): boolean; +} + +// These are the methods called on a file by atom-text-buffer +interface atom$Fileish { + existsSync(): boolean; + setEncoding(encoding: string): void; + getEncoding(): string | null | undefined; + onDidRename(callback: () => void): IDisposable; + onDidDelete(callback: () => void): IDisposable; + onDidChange(callback: () => void): IDisposable; + onWillThrowWatchError(callback: () => unknown): IDisposable; + getPath(): string; + getBaseName(): string; + createReadStream(): stream$Readable; + createWriteStream(): stream$Writable; +} + +declare class atom$File +/* implements atom$Fileish */ +{ + constructor(filePath?: string, symlink?: boolean); + + symlink: boolean; + + // Construction + create(): Promise; + + // File Metadata + isFile(): boolean; + isDirectory(): boolean; + exists(): Promise; + existsSync(): boolean; + setEncoding(encoding: string): void; + getEncoding(): string; + + // Event Subscription + onDidRename(callback: () => void): IDisposable; + onDidDelete(callback: () => void): IDisposable; + onDidChange(callback: () => void): IDisposable; + onWillThrowWatchError(callback: () => unknown): IDisposable; + + // Managing Paths + getPath(): string; + getBaseName(): string; + + // Traversing + getParent(): atom$Directory; + + // Reading and Writing + read(flushCache?: boolean): Promise; + write(text: string): Promise; + writeSync(text: string): void; + createReadStream(): stream$Readable; + createWriteStream(): stream$Writable; +} + +declare class atom$GitRepository extends atom$Repository { + // Unofficial API. + statuses: { + [filePath: string]: number; + }; + // Return the `git-utils` async repo. + getRepo(): atom$GitRepositoryInternal; +} + +declare class atom$Grammar { + name: string; + scopeName: string; + tokenizeLines(text: string): Array>; + tokenizeLine( + line: string, + ruleStack: unknown, + firstLine: boolean, + ): { + line: string; + tags: Array; + // Dynamic property: invoking it will incur additional overhead + tokens: Array; + ruleStack: unknown; + }; +} + +type atom$GrammarToken = { + value: string; + scopes: Array; +}; + +declare class atom$GrammarRegistry { + // Event Subscription + onDidAddGrammar(callback: (grammar: atom$Grammar) => void): IDisposable; + + // Managing Grammars + grammarForScopeName(scopeName: string): atom$Grammar | null | undefined; + removeGrammarForScopeName(scopeName: string): atom$Grammar | null | undefined; + loadGrammarSync(grammarPath: string): atom$Grammar; + selectGrammar(filePath: string, fileContents: string): atom$Grammar; + autoAssignLanguageMode(buffer: atom$TextBuffer): void; + assignLanguageMode(buffer: atom$TextBuffer, languageId: string): void; + + // Extended + getGrammarScore( + grammar: atom$Grammar, + filePath: string, + contents?: string, + ): number; + forEachGrammar(callback: (grammar: atom$Grammar) => unknown): void; + + // Private API + clear(): IDisposable; +} + +declare class atom$HistoryManager { + removeProject(paths: Array): void; + getProjects(): Array; +} + +declare class atom$HistoryProject { + paths(): Array; + lastOpened(): Date; +} + +// https://github.com/atom/atom-keymap/blob/18f00ac307de5770bb8f98958bd9a13ecffa9e68/src/key-binding.coffee +declare class atom$KeyBinding { + cachedKeyups: Array | null | undefined; + command: string; + index: number; + keystrokeArray: Array; + keystrokeCount: number; + keystrokes: string; + priority: number; + selector: string; + source: string; + specificity: number; + + matches(keystroke: string): boolean; + compare(keybinding: atom$KeyBinding): number; + getKeyups(): Array | null | undefined; + matchesKeystrokes( + userKeystrokes: Array, + ): boolean | 'exact' | 'partial' | 'pendingKeyup'; +} + +declare class atom$KeymapManager { + // Event Subscription + onDidMatchBinding( + callback: (event: { + keystrokes: string; + binding: atom$KeyBinding; + keyboardEventTarget: HTMLElement; + }) => unknown, + ): IDisposable; + + onDidPartiallyMatchBinding( + callback: (event: { + keystrokes: string; + partiallyMatchedBindings: atom$KeyBinding; + keyboardEventTarget: HTMLElement; + }) => unknown, + ): IDisposable; + + onDidFailToMatchBinding( + callback: (event: { + keystrokes: string; + partiallyMatchedBindings: atom$KeyBinding; + keyboardEventTarget: HTMLElement; + }) => unknown, + ): IDisposable; + + onDidFailToReadFile( + callback: (error: {message: string; stack: string}) => unknown, + ): IDisposable; + + // Adding and Removing Bindings + add(source: string, bindings: Object): IDisposable; + removeBindingsFromSource(source: string): void; + + // Accessing Bindings + getKeyBindings(): Array; + findKeyBindings(params: { + keystrokes?: string; + command?: string; + target?: HTMLElement; + }): Array; + + // Managing Keymap Files + loadKeymap(path: string, options?: {watch: boolean}): void; + watchKeymap(path: string): void; + + // Managing Keyboard Events + handleKeyboardEvent(event: Event): void; + keystrokeForKeyboardEvent(event: Event): string; + getPartialMatchTimeout(): number; + + buildKeydownEvent( + key: string, + options: { + target: HTMLElement; + alt?: boolean; + cmd?: boolean; + ctrl?: boolean; + shift?: boolean; + }, + ): Event; +} + +declare class atom$MenuManager { + add(items: Array): IDisposable; + update(): void; + + // Private API + template: Array; +} + +type atom$ProjectSpecification = { + originPath: string; + paths?: Array; + config?: { + [key: string]: unknown; + }; +}; + +declare class atom$Project { + // Event Subscription + onDidChangePaths( + callback: (projectPaths: Array) => unknown, + ): IDisposable; + onDidAddBuffer(callback: (buffer: atom$TextBuffer) => unknown): IDisposable; + onDidReplace( + arg0: (settings: atom$ProjectSpecification) => unknown, + ): IDisposable; + observeBuffers(callback: (buffer: atom$TextBuffer) => unknown): IDisposable; + observeRepositories( + callback: (repository: atom$Repository) => unknown, + ): IDisposable; + replace?: (newSettings: atom$ProjectSpecification) => void; + // Accessing the git repository + getRepositories(): Array; + repositoryForDirectory( + directory: atom$Directory, + ): Promise; + + // Managing Paths + getPaths(): Array; + addPath( + projectPath: string, + options?: { + emitEvent?: boolean; + exact?: boolean; + mustExist?: boolean; + }, + ): void; + setPaths(paths: Array): void; + removePath(projectPath: string): void; + getDirectories(): Array; + relativizePath(relativizePath?: string): Array; // [projectPath: ?string, relativePath: string] + relativize(filePath: string): string; + contains(path: string): boolean; + + // Private API + findBufferForPath(path: string): atom$TextBuffer | null | undefined; + addBuffer(buffer: atom$TextBuffer): void; + removeBuffer(buffer: atom$TextBuffer): void; + getBuffers(): Array; +} + +type TextBufferScanIterator = (arg: { + match: Array; + matchText: string; + range: atom$Range; + stop(): void; + replace(replacement: string): void; +}) => void; + +// This happens to be a number but it would be better if the type could be entirely opaque. All you +// need to know is that if something needs a checkpoint you should only pass it values received from +// TextBuffer::createCheckpoint +type atom$TextBufferCheckpoint = number; + +// TextBuffer did-change/will-change +type atom$TextEditEvent = { + oldRange: atom$Range; + newRange: atom$Range; + oldText: string; + newText: string; +}; + +type atom$AggregatedTextEditEvent = { + changes: Array; +}; + +declare class atom$LanguageMode { + getLanguageId(): string; +} + +declare class atom$TextBuffer { + constructor(text?: string); + constructor(params?: {filePath?: string; text?: string}); + + file: atom$File | null | undefined; + + // Mixin + deserialize: (state: Object, params: Object) => unknown; + load: ( + file: string | atom$Fileish, + params: Object, + ) => Promise; + + setFile(file: atom$Fileish): void; + + // Events + onWillChange(callback: () => unknown): IDisposable; + onDidChangeText( + callback: (event: atom$AggregatedTextEditEvent) => unknown, + ): IDisposable; + onDidStopChanging(callback: () => unknown): IDisposable; + onDidConflict(callback: () => unknown): IDisposable; + onDidChangeModified(callback: () => unknown): IDisposable; + onDidUpdateMarkers(callback: () => unknown): IDisposable; + onDidCreateMarker(callback: () => unknown): IDisposable; + onDidChangePath(callback: () => unknown): IDisposable; + onDidChangeEncoding(callback: () => unknown): IDisposable; + onWillSave(callback: () => unknown): IDisposable; + onDidSave(callback: (event: {path: string}) => unknown): IDisposable; + onDidDelete(callback: () => unknown): IDisposable; + onWillReload(callback: () => unknown): IDisposable; + onDidReload(callback: () => unknown): IDisposable; + onDidDestroy(callback: () => unknown): IDisposable; + onWillThrowWatchError(callback: () => unknown): IDisposable; + + // File Details + // DO NOT USE (T21363106): Doesn't work with remote text buffers! + // setPath(filePath: string): void, + getPath(): string | null | undefined; + setEncoding(encoding: string): void; + getEncoding(): string; + getUri(): string; + getId(): string; + getLanguageMode(): atom$LanguageMode; + + // Reading Text + isEmpty(): boolean; + getText(): string; + getTextInRange(range: atom$RangeLike): string; + getLineCount(): number; + getLines(): Array; + getLastLine(): string; + lineForRow(row: number): string; + lineEndingForRow(row: number): string; + lineLengthForRow(row: number): number; + isRowBlank(row: number): boolean; + previousNonBlankRow(startRow: number): number | null | undefined; + nextNonBlankRow(startRow: number): number | null | undefined; + + // Mutating Text + setText: (text: string) => atom$Range; + setTextInRange( + range: atom$RangeLike, + text: string, + options?: Object, + ): atom$Range; + setTextViaDiff(text: string): void; + insert( + position: atom$Point, + text: string, + options?: { + normalizeLineEndings?: boolean; + undo?: string; + }, + ): atom$Range; + append( + text: string, + options: + | { + normalizeLineEndings?: boolean; + undo?: string; + } + | null + | undefined, + ): atom$Range; + delete(range: atom$Range): atom$Range; + deleteRows(startRow: number, endRow: number): atom$Range; + + // History + undo(): void; + redo(): void; + transact(fn: () => unknown, _: void): void; + transact(groupingInterval: number, fn: () => unknown): void; + clearUndoStack(): void; + createCheckpoint(): atom$TextBufferCheckpoint; + revertToCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean; + groupChangesSinceCheckpoint(checkpoint: atom$TextBufferCheckpoint): boolean; + // TODO describe the return type more precisely. + getChangesSinceCheckpoint( + checkpoint: atom$TextBufferCheckpoint, + ): Array; + + // Search And Replace + scan(regex: RegExp, iterator: TextBufferScanIterator): void; + scanInRange( + regex: RegExp, + range: atom$Range, + iterator: TextBufferScanIterator, + ): void; + backwardsScanInRange( + regex: RegExp, + range: atom$Range, + iterator: TextBufferScanIterator, + ): void; + + // Buffer Range Details + getLastRow(): number; + getRange(): atom$Range; + rangeForRow(row: number, includeNewLine?: boolean): atom$Range; + getLength(): number; + + // Position/Index mapping + characterIndexForPosition(position: atom$PointLike): number; + positionForCharacterIndex(index: number): atom$Point; + + // Buffer Operations + reload(): void; + load(): Promise; + save(): Promise; + + isInConflict(): boolean; + isModified(): boolean; + + // Private APIs + cachedDiskContents: string | null | undefined; + emitter: atom$Emitter; + refcount: number; + loaded: boolean; + wasModifiedBeforeRemove: boolean; + finishLoading(): atom$TextBuffer; + updateCachedDiskContents( + flushCache?: boolean, + callback?: () => unknown, + ): Promise; + emitModifiedStatusChanged(changed: boolean): void; + destroy(): void; + isDestroyed(): boolean; + applyChange: () => void; + shouldDestroyOnFileDelete?: () => boolean; +} + +declare class atom$Notification { + // Event Subscription + onDidDismiss(callback: () => unknown): IDisposable; + onDidDisplay(callback: () => unknown): IDisposable; + + // Methods + getType(): string; + getMessage(): string; + getOptions(): Object; + dismiss(): void; + isDismissed(): boolean; +} + +type atom$NotificationButton = { + text: string; + className?: string; + onDidClick?: () => unknown; +}; + +type atom$NotificationOptions = { + detail?: string; + dismissable?: boolean; + description?: string; + icon?: string; + stack?: string; + buttons?: Array; +}; + +declare class atom$NotificationManager { + // Events + onDidAddNotification( + callback: (notification: atom$Notification) => void, + ): IDisposable; + + // Adding Notifications + add( + type: string, + message: string, + options?: atom$NotificationOptions, + ): atom$Notification; + addSuccess( + message: string, + options?: atom$NotificationOptions, + ): atom$Notification; + addInfo( + message: string, + options?: atom$NotificationOptions, + ): atom$Notification; + addWarning( + message: string, + options?: atom$NotificationOptions, + ): atom$Notification; + addError( + message: string, + options?: atom$NotificationOptions, + ): atom$Notification; + addFatalError( + message: string, + options?: atom$NotificationOptions, + ): atom$Notification; + addNotification(notification: atom$Notification): atom$Notification; + + // Getting Notifications + getNotifications(): Array; +} + +// The items in this declaration are available off of `require('atom')`. +// This list is not complete. +declare module 'atom' { + declare var BufferedNodeProcess: typeof atom$BufferedNodeProcess; + declare var BufferedProcess: typeof atom$BufferedProcess; + declare var CompositeDisposable: typeof atom$CompositeDisposable; + declare var Directory: typeof atom$Directory; + declare var Disposable: typeof atom$Disposable; + declare var Emitter: typeof atom$Emitter; + declare var File: typeof atom$File; + declare var GitRepository: typeof atom$GitRepository; + declare var Notification: typeof atom$Notification; + declare var Point: typeof atom$Point; + declare var Range: typeof atom$Range; + declare var TextBuffer: typeof atom$TextBuffer; + declare var TextEditor: typeof atom$TextEditor; +} + +// Make sure that common types can be referenced without the `atom$` prefix +// in type declarations. +declare var Cursor: typeof atom$Cursor; +declare var Panel: typeof atom$Panel; +declare var TextEditor: typeof atom$TextEditor; + +type atom$UnhandledErrorEvent = { + originalError: Object; + message: string; + url: string; + line: number; + column: number; +}; + +// The properties of this type match the properties of the `atom` global. +// This list is not complete. +type AtomGlobal = { + // Properties + appVersion: string; + atomScriptMode: boolean | null | undefined; // Added by nuclide-atom-script. + clipboard: atom$Clipboard; + commands: atom$CommandRegistry; + config: atom$Config; + contextMenu: atom$ContextMenuManager; + applicationDelegate: atom$applicationDelegate; + deserializers: atom$DeserializerManager; + grammars: atom$GrammarRegistry; + history: atom$HistoryManager; + keymaps: atom$KeymapManager; + menu: atom$MenuManager; + notifications: atom$NotificationManager; + packages: atom$PackageManager; + styles: atom$StyleManager; + themes: atom$ThemeManager; + textEditors: atom$TextEditorRegistry; + tooltips: atom$TooltipManager; + views: atom$ViewRegistry; + workspace: atom$Workspace; + project: atom$Project; + devMode: boolean; + + // Event Subscription + onWillThrowError( + callback: (event: atom$UnhandledErrorEvent) => unknown, + ): IDisposable; + onDidThrowError( + callback: (event: atom$UnhandledErrorEvent) => unknown, + ): IDisposable; + whenShellEnvironmentLoaded(callback: () => unknown): IDisposable; + + // Atom Details + inDevMode(): boolean; + inSafeMode(): boolean; + inSpecMode(): boolean; + getVersion(): string; + isReleasedVersion(): boolean; + getWindowLoadTime(): number; + + // This is an undocumented way to reach the Electron BrowserWindow. + // Use `electron.remote.getCurrentWindow` instead. + getCurrentWindow: void; + + // Messaging the User + readonly confirm: (( + arg0: { + message: string; + detail?: string; + buttons?: Array; + }, + arg1: (arg0: number) => void, + ) => void) & // The synchronous form. You really shouldn't use this. + ((arg0: { + message: string; + detailedMessage?: string; + buttons?: + | Array + | { + [buttonName: string]: () => unknown; + }; + }) => number | null | undefined); + + open(params: { + pathsToOpen?: Array; + newWindow?: boolean; + devMode?: boolean; + safeMode?: boolean; + }): void; + reload(): void; + + // Undocumented Methods + getConfigDirPath(): string; + showSaveDialogSync(options: Object): string; + loadState(): Promise; + getLoadSettings(): Object; +}; + +declare var atom: AtomGlobal; + +type RepositoryDidChangeStatusCallback = (event: { + path: string; + pathStatus: number; +}) => unknown; +type RepositoryLineDiff = { + oldStart: number; + newStart: number; + oldLines: number; + newLines: number; +}; + +// Taken from the interface of [`GitRepository`][1], which is also implemented by +// `HgRepositoryClient`. +// +// [1]: https://github.com/atom/atom/blob/v1.7.3/src/git-repository.coffee +declare class atom$Repository { + constructor(path: string, options?: {refreshOnWindowFocus?: boolean}); + + // Event Subscription + onDidChangeStatus: ( + callback: RepositoryDidChangeStatusCallback, + ) => IDisposable; + onDidChangeStatuses: (callback: () => unknown) => IDisposable; + + // Repository Details + getType: () => string; + getPath: () => string; + getWorkingDirectory: () => string; + isProjectAtRoot: () => boolean; + relativize: (aPath: string) => string; + getOriginURL: (aPath: string | null | undefined) => string | null | undefined; + + // Reading Status + isPathModified: (aPath: string) => boolean; + isPathNew: (aPath: string) => boolean; + isPathIgnored: (aPath: string) => boolean; + getDirectoryStatus: (aPath: string) => number; + getPathStatus: (aPath: string) => number; + getCachedPathStatus: (aPath: string) => number | null | undefined; + isStatusModified: (status: number) => boolean; + isStatusNew: (status: number) => boolean; + refreshStatus: () => Promise; + + // Retrieving Diffs + getDiffStats: (filePath: string) => {added: number; deleted: number}; + getLineDiffs: (aPath: string, text: string) => Array; + + // Checking Out + checkoutHead: (aPath: string) => boolean; + checkoutReference: (reference: string, create: boolean) => Promise; + + // Event Subscription + onDidDestroy(callback: () => unknown): IDisposable; + isDestroyed(): boolean; +} + +declare class atom$GitRepositoryInternal { + // Reading Status + isStatusModified: (status: number) => boolean; + isStatusNew: (status: number) => boolean; + isStatusIgnored: (status: number) => boolean; + isStatusStaged: (status: number) => boolean; + isStatusDeleted: (status: number) => boolean; +} + +// One of text or snippet is required. +// TODO(hansonw): use a union + intersection type +type atom$AutocompleteSuggestion = { + text?: string; + snippet?: string; + displayText?: string; + replacementPrefix?: string; + type?: string | null | undefined; + leftLabel?: string | null | undefined; + leftLabelHTML?: string | null | undefined; + rightLabel?: string | null | undefined; + rightLabelHTML?: string | null | undefined; + className?: string | null | undefined; + iconHTML?: string | null | undefined; + description?: string | null | undefined; + descriptionMarkdown?: string | null | undefined; + descriptionMoreURL?: string | null | undefined; +}; + +type atom$AutocompleteRequest = { + editor: TextEditor; + bufferPosition: atom$Point; + scopeDescriptor: atom$ScopeDescriptor; + prefix: string; + activatedManually?: boolean; +}; + +type atom$AutocompleteProvider = { + readonly selector: string; + readonly getSuggestions: ( + request: atom$AutocompleteRequest, + ) => + | Promise | null | undefined> + | (Array | null | undefined); + readonly getSuggestionDetailsOnSelect?: ( + suggestion: atom$AutocompleteSuggestion, + ) => Promise; + readonly disableForSelector?: string; + readonly inclusionPriority?: number; + readonly excludeLowerPriority?: boolean; + readonly suggestionPriority?: number; + readonly filterSuggestions?: boolean; + readonly disposable?: () => void; + readonly onDidInsertSuggestion?: ( + insertedSuggestion: atom$SuggestionInsertedRequest, + ) => void; +}; + +type atom$SuggestionInsertedRequest = { + readonly editor: atom$TextEditor; + readonly triggerPosition: atom$Point; + readonly suggestion: atom$AutocompleteSuggestion; +}; + +// https://github.com/atom/autocomplete-plus/blob/master/README.md#the-watcheditor-api +type atom$AutocompleteWatchEditor = ( + editor: atom$TextEditor, + labels?: Array, +) => IDisposable; + +// Undocumented API. +declare class atom$Token { + value: string; + matchesScopeSelector(selector: string): boolean; +} + +declare class atom$Selection { + clear(): void; + getText(): string; + getBufferRange(): atom$Range; + insertText( + text: string, + options?: { + select?: boolean; + autoIndent?: boolean; + autoIndentNewLine?: boolean; + autoDecreaseIdent?: boolean; + normalizeLineEndings?: boolean; + undo?: boolean; + }, + ): string; + isEmpty(): boolean; +} + +declare class atom$PanelContainer { + dock: atom$Dock; + element: HTMLElement; + emitter: atom$Emitter; + location: atom$PaneLocation; + panels: Array; + subscriptions: atom$CompositeDisposable; + viewRegistry: atom$ViewRegistry; + + getPanels(): Array; +} From 3e9ea0f643343e332046f4b4e0fd3511812548d3 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:45:27 -0500 Subject: [PATCH 03/15] fix: add definitions from need-to-upstream-to-flow-lib.js --- nuclide/types/atom.ts | 112 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 241251b6..221cc268 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -2464,3 +2464,115 @@ declare class atom$PanelContainer { getPanels(): Array; } + +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the license found in the LICENSE file in + * the root directory of this source tree. + * + * @flow + */ + +/* + * APIs listed in this file are ones that should be built into Flow and need to be upstreamed. + */ +type IDisposable = { + dispose(): unknown; +}; + +/* + * These Notification & NotificationOptions definitions are not exhaustive while standardization, + * browser, and Electron support remain incomplete. + */ +type NotificationOptions = { + body?: string; + icon?: string; +}; + +declare class Notification { + constructor(message: string, options?: NotificationOptions); + onclick: () => void; +} + +// T9254051 - Fix flow http/https definitions. +declare class http$fixed$Server extends events$EventEmitter { + listen( + port: number, + hostname?: string, + backlog?: number, + callback?: Function, + ): http$fixed$Server; + listen(path: string, callback?: Function): http$fixed$Server; + listen(handle: Object, callback?: Function): http$fixed$Server; + close(callback?: Function): http$fixed$Server; + address(): {port: number; fmaily: string; address: string}; + maxHeadersCount: number; +} + +declare class http$fixed$IncomingMessage extends stream$Readable { + headers: Object; + httpVersion: string; + method: string; + trailers: Object; + setTimeout(msecs: number, callback: Function): void; + socket: any; // TODO net.Socket + statusCode: number; + url: string; + connection: {destroy: () => void}; +} + +declare class http$fixed$ClientRequest extends stream$Writable {} + +declare class http$fixed$ServerResponse { + setHeader(name: string, value: string): void; + statusCode: number; + write(value: string): void; + end(): void; +} + +declare class https$fixed { + Server: typeof http$fixed$Server; + createServer( + options: Object, + requestListener?: ( + request: http$fixed$IncomingMessage, + response: http$fixed$ServerResponse, + ) => void, + ): http$fixed$Server; + request( + options: Object | string, + callback: (response: http$fixed$IncomingMessage) => void, + ): http$fixed$ClientRequest; + get( + options: Object | string, + callback: (response: http$fixed$IncomingMessage) => void, + ): http$fixed$ClientRequest; +} + +declare class http$fixed { + Server: typeof http$fixed$Server; + createServer( + requestListener?: ( + request: http$fixed$IncomingMessage, + response: http$fixed$ServerResponse, + ) => void, + ): http$fixed$Server; + request( + options: Object | string, + callback: (response: http$fixed$IncomingMessage) => void, + ): http$fixed$ClientRequest; + get( + options: Object | string, + callback: (response: http$fixed$IncomingMessage) => void, + ): http$fixed$ClientRequest; +} + +declare interface net$ListenOptions { + port?: number; + host?: string; + backlog?: number; + path?: string; + exclusive?: boolean; +} From 597f4cdd4defea4c2262a56aab7e418f7e511b38 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:49:30 -0500 Subject: [PATCH 04/15] fix: remove excess declare --- nuclide/types/atom.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 221cc268..549eff61 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -2191,19 +2191,19 @@ declare class atom$NotificationManager { // The items in this declaration are available off of `require('atom')`. // This list is not complete. declare module 'atom' { - declare var BufferedNodeProcess: typeof atom$BufferedNodeProcess; - declare var BufferedProcess: typeof atom$BufferedProcess; - declare var CompositeDisposable: typeof atom$CompositeDisposable; - declare var Directory: typeof atom$Directory; - declare var Disposable: typeof atom$Disposable; - declare var Emitter: typeof atom$Emitter; - declare var File: typeof atom$File; - declare var GitRepository: typeof atom$GitRepository; - declare var Notification: typeof atom$Notification; - declare var Point: typeof atom$Point; - declare var Range: typeof atom$Range; - declare var TextBuffer: typeof atom$TextBuffer; - declare var TextEditor: typeof atom$TextEditor; + var BufferedNodeProcess: typeof atom$BufferedNodeProcess; + var BufferedProcess: typeof atom$BufferedProcess; + var CompositeDisposable: typeof atom$CompositeDisposable; + var Directory: typeof atom$Directory; + var Disposable: typeof atom$Disposable; + var Emitter: typeof atom$Emitter; + var File: typeof atom$File; + var GitRepository: typeof atom$GitRepository; + var Notification: typeof atom$Notification; + var Point: typeof atom$Point; + var Range: typeof atom$Range; + var TextBuffer: typeof atom$TextBuffer; + var TextEditor: typeof atom$TextEditor; } // Make sure that common types can be referenced without the `atom$` prefix From a9cb76be1098e2cd98d1be46dfa8240deae0e2ac Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:49:37 -0500 Subject: [PATCH 05/15] fix: add eventKit types --- nuclide/types/atom.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 549eff61..b4201591 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -2576,3 +2576,9 @@ declare interface net$ListenOptions { path?: string; exclusive?: boolean; } + +declare module 'event-kit' { + var Emitter: typeof atom$Emitter; + var Disposable: typeof atom$Disposable; + var CompositeDisposable: typeof atom$CompositeDisposable; +} From c555a581a5be6d4e834161f2b7d692f77f2b9dea Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:53:14 -0500 Subject: [PATCH 06/15] feat: add missing atom types from Atom source code --- types-packages/atom.d.ts | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 types-packages/atom.d.ts diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts new file mode 100644 index 00000000..afab7b30 --- /dev/null +++ b/types-packages/atom.d.ts @@ -0,0 +1,115 @@ +// TODO add to @types/Atom + +export {} + +// An {Object} with the following fields: +interface BufferChangeEvent { + // The deleted text + oldText: string + + // The {Range} of the deleted text before the change took place. + oldRange: Range + + // The inserted text + newText: string + + // The {Range} of the inserted text after the change took place. + newRange: Range +} + +type HighlightingChangeEvent = (range: Range) => void + +declare module "atom" { + interface TextEditor { + // Get the Element for the editor. + getElement(): TextEditorElement + + // Controls visibility based on the given {Boolean}. + setVisible(visible: boolean): void + + // Experimental: Get a notification when async tokenization is completed. + onDidTokenize(callback: () => any): Disposable + + component: { + getNextUpdatePromise(): Promise + } + + isDestroyed(): boolean + + getDefaultCharWidth(): number + } + + interface LanguageMode { + // A {Function} that returns a {String} identifying the language. + getLanguageId(): string + + // A {Function} that is called whenever the buffer changes. + bufferDidChange(change: BufferChangeEvent): void + + // A {Function} that takes a callback {Function} and calls it with a {Range} argument whenever the syntax of a given part of the buffer is updated. + onDidChangeHighlighting(callback: HighlightingChangeEvent): void + + // A function that returns an iterator object with the following methods: + buildHighlightIterator(): { + // A {Function} that takes a {Point} and resets the iterator to that position. + seek(point: Point): any + + // A {Function} that advances the iterator to the next token + moveToSuccessor(): void + + // A {Function} that returns a {Point} representing the iterator's current position in the buffer. + getPosition(): Point + + // A {Function} that returns an {Array} of {Number}s representing tokens that end at the current position. + getCloseTags(): Array + + // A {Function} that returns an {Array} of {Number}s representing tokens that begin at the current position. + getOpenTags(): Array + } + } + + interface TextMateLanguageMode { + fullyTokenized: boolean + + // Get the suggested indentation level for an existing line in the buffer. + // + // * bufferRow - A {Number} indicating the buffer row + // + // Returns a {Number}. + suggestedIndentForBufferRow(bufferRow: number, tabLength: number, options: object): number + + // Get the suggested indentation level for a given line of text, if it were inserted at the given + // row in the buffer. + // + // * bufferRow - A {Number} indicating the buffer row + // + // Returns a {Number}. + suggestedIndentForLineAtBufferRow(bufferRow: number, line: number, tabLength: number): number + + // Get the suggested indentation level for a line in the buffer on which the user is currently + // typing. This may return a different result from {::suggestedIndentForBufferRow} in order + // to avoid unexpected changes in indentation. It may also return undefined if no change should + // be made. + // + // * bufferRow - The row {Number} + // + // Returns a {Number}. + suggestedIndentForEditedBufferRow(bufferRow: number, tabLength: number): number + } + + interface TextBuffer { + // Experimental: Get the language mode associated with this buffer. + // + // Returns a language mode {Object} (See {TextBuffer::setLanguageMode} for its interface). + getLanguageMode(): LanguageMode | TextMateLanguageMode + + // Experimental: Set the LanguageMode for this buffer. + // + // * `languageMode` - an {Object} with the following methods: + setLanguageMode(languageMode: LanguageMode | TextMateLanguageMode): void + } + + interface TextEditorElement { + setUpdatedSynchronously(val: boolean): void + } +} From 1310ec8d158f3291968abfd4159016529eb21cae Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:56:19 -0500 Subject: [PATCH 07/15] fix: remove redundant atom declaration --- nuclide/types/atom.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index b4201591..2ae1f49c 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -2188,24 +2188,6 @@ declare class atom$NotificationManager { getNotifications(): Array; } -// The items in this declaration are available off of `require('atom')`. -// This list is not complete. -declare module 'atom' { - var BufferedNodeProcess: typeof atom$BufferedNodeProcess; - var BufferedProcess: typeof atom$BufferedProcess; - var CompositeDisposable: typeof atom$CompositeDisposable; - var Directory: typeof atom$Directory; - var Disposable: typeof atom$Disposable; - var Emitter: typeof atom$Emitter; - var File: typeof atom$File; - var GitRepository: typeof atom$GitRepository; - var Notification: typeof atom$Notification; - var Point: typeof atom$Point; - var Range: typeof atom$Range; - var TextBuffer: typeof atom$TextBuffer; - var TextEditor: typeof atom$TextEditor; -} - // Make sure that common types can be referenced without the `atom$` prefix // in type declarations. declare var Cursor: typeof atom$Cursor; From 708ef7d0878c9a79336d915b8e2d17e9af2ccb5e Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 20:58:30 -0500 Subject: [PATCH 08/15] fix: remove atom$Color --- nuclide/types/atom.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 2ae1f49c..e07dfa3c 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -54,12 +54,8 @@ type atom$Octicon = 'alert' | 'alignment-align' | 'alignment-aligned-to' | 'alig type atom$PaneLocation = 'left' | 'right' | 'bottom' | 'center'; -declare type atom$Color = { - // Returns a String in the form '#abcdef'. - toHexString(): string; - // Returns a String in the form 'rgba(25, 50, 75, .9)'. - toRGBAString(): string; -}; +import { Color } from "atom" +export type atom$Color = Color; declare class atom$Model { destroy(): void; From 8a2a6ff13c43297b4224484ea6f2b81523229268 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:00:03 -0500 Subject: [PATCH 09/15] fix: remove atom$Model --- nuclide/types/atom.ts | 6 ++---- types-packages/atom.d.ts | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index e07dfa3c..f861a91b 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -57,10 +57,8 @@ type atom$PaneLocation = 'left' | 'right' | 'bottom' | 'center'; import { Color } from "atom" export type atom$Color = Color; -declare class atom$Model { - destroy(): void; - isDestroyed(): boolean; -} +import { Model } from "atom" +export type atom$Model = Model; declare class atom$Package { path: string; diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts index afab7b30..05325ab1 100644 --- a/types-packages/atom.d.ts +++ b/types-packages/atom.d.ts @@ -20,6 +20,12 @@ interface BufferChangeEvent { type HighlightingChangeEvent = (range: Range) => void declare module "atom" { + + class Model { + destroy(): void; + isDestroyed(): boolean; + } + interface TextEditor { // Get the Element for the editor. getElement(): TextEditorElement From b86d8f238a160e2437995a02a6d2735c9c90577b Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:02:00 -0500 Subject: [PATCH 10/15] fix: remove atom$Package --- nuclide/types/atom.ts | 22 ++-------------------- types-packages/atom.d.ts | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index f861a91b..6da5254f 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -60,26 +60,8 @@ export type atom$Color = Color; import { Model } from "atom" export type atom$Model = Model; -declare class atom$Package { - path: string; - activateTime: number; - mainModule: any; - mainModulePath: string; - metadata: Object; - name: string; - loadTime: number; - getType(): 'atom' | 'textmate' | 'theme'; - hasActivationCommands(): boolean; - hasActivationHooks(): boolean; - initializeTime: number; - getActivationHooks(): Array; - onDidDeactivate(cb: () => unknown): IDisposable; - activateNow(): void; - // Undocumented - bundledPackage: boolean; - getCanDeferMainModuleRequireStorageKey(): string; - initializeIfNeeded(): void; -} +import { Package } from "atom" +export type atom$Package = Package; /** * Essential Classes diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts index 05325ab1..305c5fa2 100644 --- a/types-packages/atom.d.ts +++ b/types-packages/atom.d.ts @@ -20,7 +20,26 @@ interface BufferChangeEvent { type HighlightingChangeEvent = (range: Range) => void declare module "atom" { - + + interface Package { + activateTime: number; + mainModule: any; + mainModulePath: string; + metadata: Object; + loadTime: number; + getType(): 'atom' | 'textmate' | 'theme'; + hasActivationCommands(): boolean; + hasActivationHooks(): boolean; + initializeTime: number; + getActivationHooks(): Array; + onDidDeactivate(cb: () => unknown): Disposable; + activateNow(): void; + // Undocumented + bundledPackage: boolean; + getCanDeferMainModuleRequireStorageKey(): string; + initializeIfNeeded(): void; + } + class Model { destroy(): void; isDestroyed(): boolean; From 40c1029dde79ee481a464cc0c49179f73edaf0c0 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:08:00 -0500 Subject: [PATCH 11/15] fix: remove CustomEvent --- nuclide/types/atom.ts | 5 ++--- types-packages/atom.d.ts | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 6da5254f..971c245a 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -66,9 +66,8 @@ export type atom$Package = Package; /** * Essential Classes */ -declare type atom$CustomEvent = CustomEvent & { - originalEvent?: Event; -}; +import { CustomEvent } from "atom" +export type atom$CustomEvent = CustomEvent; type atom$CommandCallback = (event: atom$CustomEvent) => unknown; diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts index 305c5fa2..b8dd2370 100644 --- a/types-packages/atom.d.ts +++ b/types-packages/atom.d.ts @@ -21,6 +21,10 @@ type HighlightingChangeEvent = (range: Range) => void declare module "atom" { + interface CustomEvent { + originalEvent?: Event; + } + interface Package { activateTime: number; mainModule: any; From 03b70f25b66f08183551e6c83fbae5cae62c2a39 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:12:22 -0500 Subject: [PATCH 12/15] fix: remove atom$CommandRegistry --- nuclide/types/atom.ts | 37 ++----------------------------------- types-packages/atom.d.ts | 5 +++++ 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 971c245a..3e6057db 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -69,41 +69,8 @@ export type atom$Package = Package; import { CustomEvent } from "atom" export type atom$CustomEvent = CustomEvent; -type atom$CommandCallback = (event: atom$CustomEvent) => unknown; - -type atom$CommandDescriptor = { - name: string; - displayName: string; - description?: string; - hiddenInCommandPalette?: boolean; - tags?: Array; -}; - -type atom$CommandListener = - | atom$CommandCallback - | { - displayName?: string; - description?: string; - didDispatch: atom$CommandCallback; - }; - -declare class atom$CommandRegistry { - // Methods - add( - target: string | HTMLElement, - commandNameOrCommands: - | string - | { - [commandName: string]: atom$CommandListener; - }, - listener?: atom$CommandListener, - throwOnInvalidSelector?: boolean, - ): IDisposable; - dispatch(target: HTMLElement, commandName: string, detail?: Object): void; - onDidDispatch(callback: (event: atom$CustomEvent) => unknown): IDisposable; - onWillDispatch(callback: (event: atom$CustomEvent) => unknown): IDisposable; - findCommands(opts: {target: Node}): Array; -} +import { CommandRegistry } from "atom" +export type atom$CommandRegistry = CommandRegistry; declare class atom$CompositeDisposable { constructor(...disposables: Array); diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts index b8dd2370..dbd75a42 100644 --- a/types-packages/atom.d.ts +++ b/types-packages/atom.d.ts @@ -20,6 +20,11 @@ interface BufferChangeEvent { type HighlightingChangeEvent = (range: Range) => void declare module "atom" { + + type CommandRegistryListener_Extra = { + name: string; + tags?: Array; + } interface CustomEvent { originalEvent?: Event; From d7ffe4c11b0b349480b937ebfdd93a715cc7e456 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:13:15 -0500 Subject: [PATCH 13/15] fix: remove CompositeDisposable --- nuclide/types/atom.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 3e6057db..fe7c4bc5 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -72,14 +72,8 @@ export type atom$CustomEvent = CustomEvent; import { CommandRegistry } from "atom" export type atom$CommandRegistry = CommandRegistry; -declare class atom$CompositeDisposable { - constructor(...disposables: Array); - dispose(): void; - - add(...disposables: Array): void; - remove(disposable: IDisposable): void; - clear(): void; -} +import { CompositeDisposable } from "atom" +export type atom$CompositeDisposable = CompositeDisposable; type atom$ConfigParams = { saveCallback?: (arg0: Object) => void; From 8788c98af09e02a600f7ff9487d1b7eb6540e325 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:23:02 -0500 Subject: [PATCH 14/15] fix: remove atom$Config --- nuclide/types/atom.ts | 98 +--------------------------------------- types-packages/atom.d.ts | 51 ++++++++++++++++++++- 2 files changed, 52 insertions(+), 97 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index fe7c4bc5..24059b22 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -75,103 +75,9 @@ export type atom$CommandRegistry = CommandRegistry; import { CompositeDisposable } from "atom" export type atom$CompositeDisposable = CompositeDisposable; -type atom$ConfigParams = { - saveCallback?: (arg0: Object) => void; - mainSource?: string; - projectHomeSchema?: atom$ConfigSchema; -}; - -type atom$ConfigType = - | 'boolean' - | 'string' - | 'integer' - | 'number' - | 'array' - | 'object' - | 'color' - | 'any'; - -type atom$ConfigSchema = { - default?: unknown; - description?: string; - enum?: Array; - maximum?: number; - minimum?: number; - properties?: Object; - title?: string; - type: Array | atom$ConfigType; -}; - -declare class atom$Config { - defaultSettings: Object; - settings: Object; - - // Config Subscription - observe( - keyPath: string, - optionsOrCallback?: - | {scope?: atom$ScopeDescriptorLike} - | ((value: unknown) => void), - callback?: (value: unknown) => unknown, - ): IDisposable; - - onDidChange( - keyPathOrCallback: - | string - | ((event: {oldValue: unknown; newValue: unknown}) => unknown), - optionsOrCallback?: - | {scope?: atom$ScopeDescriptorLike} - | ((event: {oldValue: unknown; newValue: unknown}) => unknown), - callback?: (event: {oldValue: unknown; newValue: unknown}) => unknown, - ): IDisposable; - - // Managing Settings - get( - keyPath?: string, - options?: { - excludeSources?: Array; - sources?: Array; - scope?: atom$ScopeDescriptorLike; - }, - ): unknown; - - set( - keyPath: string, - value: unknown | null | undefined, - options?: { - scopeSelector?: string; - source?: string; - }, - ): boolean; - - unset( - keyPath: string, - options?: { - scopeSelector?: string; - source?: string; - }, - ): void; +import { Config } from "atom" +export type atom$Config = Config; - getUserConfigPath(): string; - - // Undocumented Methods - constructor(params?: atom$ConfigParams); - getRawValue( - keyPath: string | null | undefined, - options: {excludeSources?: string; sources?: string}, - ): unknown; - getSchema(keyPath: string): atom$ConfigSchema; - save(): void; - setRawValue(keyPath: string, value: unknown): void; - setSchema(keyPath: string, schema: atom$ConfigSchema): void; - removeAtKeyPath( - keyPath: string | null | undefined, - value: unknown | null | undefined, - ): unknown; - - // Used by nuclide-config to set the initial settings from disk - resetUserSettings(newSettings: Object, options?: {source?: string}): void; -} declare class atom$Cursor { // Cursor Marker diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts index dbd75a42..b8f199a7 100644 --- a/types-packages/atom.d.ts +++ b/types-packages/atom.d.ts @@ -20,7 +20,56 @@ interface BufferChangeEvent { type HighlightingChangeEvent = (range: Range) => void declare module "atom" { - + + interface ConfigParams { + saveCallback?: (arg0: Object) => void; + mainSource?: string; + projectHomeSchema?: ConfigSchema; + } + + type ConfigType = + | 'boolean' + | 'string' + | 'integer' + | 'number' + | 'array' + | 'object' + | 'color' + | 'any'; + + interface ConfigSchema { + default?: unknown; + description?: string; + enum?: Array; + maximum?: number; + minimum?: number; + properties?: Object; + title?: string; + type: Array | ConfigType; + } + + interface Config { + defaultSettings: Object; + settings: Object; + + constructor(params?: ConfigParams): Config; + getRawValue( + keyPath: string | null | undefined, + options: {excludeSources?: string; sources?: string}, + ): unknown; + getSchema(keyPath: string): ConfigSchema | null; + save(): void; + setRawValue(keyPath: string, value: unknown): void; + setSchema(keyPath: string, schema: ConfigSchema): void; + removeAtKeyPath( + keyPath: string | null | undefined, + value: unknown | null | undefined, + ): unknown; + + // Used to set the initial settings from disk + resetUserSettings(newSettings: Object, options?: {source?: string}): void; + } + type CommandRegistryListener_Extra = { name: string; tags?: Array; From c83a31a078ca95c23c8170c748ca0c389a4b4468 Mon Sep 17 00:00:00 2001 From: aminya Date: Wed, 21 Oct 2020 21:26:49 -0500 Subject: [PATCH 15/15] fix: remove atom$Cursor --- nuclide/types/atom.ts | 39 ++------------------------------------- types-packages/atom.d.ts | 6 ++++++ 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/nuclide/types/atom.ts b/nuclide/types/atom.ts index 24059b22..ea15f802 100644 --- a/nuclide/types/atom.ts +++ b/nuclide/types/atom.ts @@ -78,43 +78,8 @@ export type atom$CompositeDisposable = CompositeDisposable; import { Config } from "atom" export type atom$Config = Config; - -declare class atom$Cursor { - // Cursor Marker - marker: atom$Marker; - editor: atom$TextEditor; - - // Event Subscription - onDidChangePosition( - callback: (event: { - oldBufferPosition: atom$Point; - oldScreenPosition: atom$Point; - newBufferPosition: atom$Point; - newScreenPosition: atom$Point; - textChanged: boolean; - Cursor: atom$Cursor; - }) => unknown, - ): IDisposable; - - // Managing Cursor Position - getBufferRow(): number; - getBufferColumn(): number; - getBufferPosition(): atom$Point; - - // Cursor Position Details - // Moving the Cursor - moveUp(rowCount: number, arg1: {moveToEndOfSelection?: boolean}): void; - moveDown(rowCount: number, arg1: {moveToEndOfSelection?: boolean}): void; - - // Local Positions and Ranges - getCurrentWordBufferRange(options?: {wordRegex: RegExp}): atom$Range; - getCurrentWordPrefix(): string; - - // Visibility - // Comparing to another cursor - // Utilities - wordRegExp(options?: {includeNonWordCharacters: boolean}): RegExp; -} +import { Cursor } from "atom" +export type atom$Cursor = Cursor; declare class atom$Decoration { destroy(): void; diff --git a/types-packages/atom.d.ts b/types-packages/atom.d.ts index b8f199a7..22793d7d 100644 --- a/types-packages/atom.d.ts +++ b/types-packages/atom.d.ts @@ -70,6 +70,12 @@ declare module "atom" { resetUserSettings(newSettings: Object, options?: {source?: string}): void; } + interface Cursor { + // Cursor Marker + marker: Marker; + editor: TextEditor; + } + type CommandRegistryListener_Extra = { name: string; tags?: Array;