Skip to content

Commit 3832040

Browse files
committed
add types for atom-ide packages
1 parent e585ed0 commit 3832040

File tree

10 files changed

+422
-0
lines changed

10 files changed

+422
-0
lines changed

index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// atom-ide
2+
// https://github.com/atom-ide-community/atom-ide
3+
4+
declare module "atom-ide" {
5+
/// <reference path="./src/busy-signal.d.ts" />
6+
/// <reference path="./src/code-actions.d.ts" />
7+
/// <reference path="./src/code-highlight.d.ts" />
8+
/// <reference path="./src/datatip.d.ts" />
9+
/// <reference path="./src/definitions.d.ts" />
10+
/// <reference path="./src/find-references.d.ts" />
11+
/// <reference path="./src/hyperclick.d.ts" />
12+
/// <reference path="./src/outline.d.ts" />
13+
/// <reference path="./src/sig-help.d.ts" />
14+
}

src/busy-signal.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
declare module "atom-ide" {
2+
export interface BusySignalOptions {
3+
// Can say that a busy signal will only appear when a given file is open.
4+
// Default = `null`, meaning the busy signal applies to all files.
5+
onlyForFile?: string;
6+
// Is user waiting for computer to finish a task? (traditional busy spinner)
7+
// or is the computer waiting for user to finish a task? (action required)
8+
// Default = spinner.
9+
waitingFor?: "computer" | "user";
10+
// Debounce it? default = `true` for busy-signal, and false for action-required.
11+
debounce?: boolean;
12+
// If `onClick` is set, then the tooltip will be clickable. Default = `null`.
13+
onDidClick?: () => void;
14+
// If set to `true`, the busy signal tooltip will be immediately revealed
15+
// when it first becomes visible (without explicit mouse interaction).
16+
revealTooltip?: boolean;
17+
}
18+
19+
export interface BusySignalService {
20+
// Activates the busy signal with the given title and returns the promise
21+
// from the provided callback.
22+
// The busy signal automatically deactivates when the returned promise
23+
// either resolves or rejects.
24+
reportBusyWhile<T>(
25+
title: string,
26+
f: () => Promise<T>,
27+
options?: BusySignalOptions
28+
): Promise<T>;
29+
30+
// Activates the busy signal. Set the title in the returned BusySignal
31+
// object (you can update the title multiple times) and dispose it when done.
32+
reportBusy(title: string, options?: BusySignalOptions): BusyMessage;
33+
34+
// This is a no-op. When someone consumes the busy service, they get back a
35+
// reference to the single shared instance, so disposing of it would be wrong.
36+
dispose(): void;
37+
}
38+
39+
export interface BusyMessage {
40+
// You can set/update the title.
41+
setTitle(title: string): void;
42+
// Dispose of the signal when done to make it go away.
43+
dispose(): void;
44+
}
45+
}

src/code-actions.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as Atom from "atom";
2+
import { Message } from "../linter";
3+
4+
declare module "atom-ide" {
5+
export interface CodeAction {
6+
apply(): Promise<void>;
7+
getTitle(): Promise<string>;
8+
dispose(): void;
9+
}
10+
11+
export interface CodeActionProvider {
12+
grammarScopes?: ReadonlyArray<string>;
13+
priority: number;
14+
getCodeActions(
15+
editor: Atom.TextEditor,
16+
range: Atom.Range,
17+
diagnostics: Message[]
18+
): Promise<CodeAction[] | null | undefined>;
19+
}
20+
21+
/**
22+
* atom-ide-code-actions provides a CodeActionFetcher which offers an API to
23+
* request CodeActions from all CodeAction providers. For now, CodeActionFetcher
24+
* can only fetch CodeActions for a Diagnostic. In the future, this API can be
25+
* extended to provide a stream of CodeActions based on the cursor position.
26+
*/
27+
export interface CodeActionFetcher {
28+
getCodeActionForDiagnostic: (
29+
diagnostic: Message,
30+
editor: Atom.TextEditor
31+
) => Promise<CodeAction[]>;
32+
}
33+
}

src/code-highlight.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Atom from "atom";
2+
3+
declare module "atom-ide" {
4+
export interface CodeHighlightProvider {
5+
priority: number;
6+
grammarScopes: ReadonlyArray<string>;
7+
highlight(
8+
editor: Atom.TextEditor,
9+
bufferPosition: Atom.Point
10+
): Promise<Atom.Range[] | undefined | null>;
11+
}
12+
}

src/datatip.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as Atom from "atom";
2+
3+
declare module "atom-ide" {
4+
export interface DatatipService {
5+
addProvider(provider: DatatipProvider): Atom.DisposableLike;
6+
addModifierProvider(provider: ModifierDatatipProvider): Atom.DisposableLike;
7+
createPinnedDataTip(
8+
datatip: Datatip,
9+
editor: Atom.TextEditor,
10+
options?: PinnedDatatipOptions
11+
): Atom.DisposableLike;
12+
}
13+
14+
export interface PinnedDatatipOptions {
15+
// Defaults to 'end-of-line'.
16+
position?: PinnedDatatipPosition;
17+
// Defaults to true.
18+
showRangeHighlight?: boolean;
19+
}
20+
21+
export type PinnedDatatipPosition = "end-of-line" | "above-range";
22+
23+
export interface DatatipProvider {
24+
priority: number;
25+
grammarScopes?: ReadonlyArray<string>;
26+
// A unique name for the provider to be used for analytics.
27+
// It is recommended that it be the name of the provider's package.
28+
providerName: string;
29+
datatip(
30+
editor: Atom.TextEditor,
31+
bufferPosition: Atom.Point
32+
): Promise<Datatip | undefined | null>;
33+
}
34+
35+
export interface ModifierDatatipProvider {
36+
priority: number;
37+
grammarScopes?: string[];
38+
providerName: string;
39+
modifierDatatip(
40+
editor: Atom.TextEditor,
41+
bufferPosition: Atom.Point,
42+
heldKeys: Set<ModifierKey>
43+
): Promise<Datatip | undefined | null>;
44+
}
45+
46+
export type AnyDatatipProvider = DatatipProvider | ModifierDatatipProvider;
47+
48+
export type Datatip =
49+
| {
50+
markedStrings: MarkedString[];
51+
range: Atom.Range;
52+
pinnable?: boolean;
53+
}
54+
| {
55+
component: () => JSX.Element; // React component
56+
range: Atom.Range;
57+
pinnable?: boolean;
58+
};
59+
60+
// Borrowed from the LSP API.
61+
export type MarkedString =
62+
| {
63+
type: "markdown";
64+
value: string;
65+
}
66+
| {
67+
type: "snippet";
68+
grammar: Atom.Grammar;
69+
value: string;
70+
};
71+
72+
export type ModifierKey = "metaKey" | "shiftKey" | "altKey" | "ctrlKey";
73+
}

src/definitions.d.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as Atom from "atom";
2+
3+
declare module "atom-ide" {
4+
export interface Definition {
5+
// Path of the file in which the definition is located.
6+
path: string;
7+
// First character of the definition's identifier.
8+
// e.g. "F" in `class Foo {}`
9+
position: Atom.Point;
10+
// Optional: the range of the entire definition.
11+
// e.g. "c" to "}" in `class Foo {}`
12+
range?: Atom.Range;
13+
// Optional: `name` and `projectRoot` can be provided to display a more human-readable title
14+
// inside of Hyperclick when there are multiple definitions.
15+
name?: string;
16+
// If provided, `projectRoot` will be used to display a relativized version of `path`.
17+
projectRoot?: string;
18+
// `language` may be used by consumers to identify the source of definitions.
19+
language: string;
20+
}
21+
22+
// Definition queries supply a point.
23+
// The returned queryRange is the range within which the returned definition is valid.
24+
// Typically queryRange spans the containing identifier around the query point.
25+
// (If a null queryRange is returned, the range of the word containing the point is used.)
26+
export interface DefinitionQueryResult {
27+
queryRange: ReadonlyArray<Atom.Range> | null | undefined;
28+
definitions: ReadonlyArray<Definition>; // Must be non-empty.
29+
}
30+
31+
// Provides definitions for a set of language grammars.
32+
export interface DefinitionProvider {
33+
// If there are multiple providers for a given grammar,
34+
// the one with the highest priority will be used.
35+
priority: number;
36+
grammarScopes: ReadonlyArray<string>;
37+
wordRegExp: RegExp | null | undefined;
38+
// Obtains the definition in an editor at the given point.
39+
// This should return null if no definition is available.
40+
getDefinition: (
41+
editor: Atom.TextEditor,
42+
position: Atom.Point
43+
) => Promise<DefinitionQueryResult | null | undefined>;
44+
}
45+
46+
export interface DefinitionPreviewProvider {
47+
getDefinitionPreview(
48+
definition: Definition
49+
): Promise<
50+
| {
51+
mime: string;
52+
contents: string;
53+
encoding: string;
54+
}
55+
| null
56+
| undefined
57+
>;
58+
}
59+
}

src/find-references.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as Atom from "atom";
2+
3+
declare module "atom-ide" {
4+
export interface FindReferencesProvider {
5+
// Return true if your provider supports finding references for the provided Atom.TextEditor.
6+
isEditorSupported(editor: Atom.TextEditor): Promise<boolean>;
7+
8+
// `findReferences` will only be called if `isEditorSupported` previously returned true
9+
// for the given Atom.TextEditor.
10+
findReferences(
11+
editor: Atom.TextEditor,
12+
position: Atom.Point
13+
): Promise<FindReferencesReturn | undefined | null>;
14+
}
15+
16+
export interface Reference {
17+
uri: string; // Nuclide URI of the file path
18+
name: string | undefined | null; // name of calling method/function/symbol
19+
range: Atom.Range;
20+
}
21+
22+
export interface FindReferencesData {
23+
type: "data";
24+
baseUri: string;
25+
referencedSymbolName: string;
26+
references: Reference[];
27+
title?: string; // defaults to 'Symbol References'
28+
}
29+
30+
export interface FindReferencesError {
31+
type: "error";
32+
message: string;
33+
}
34+
35+
export type FindReferencesReturn = FindReferencesData | FindReferencesError;
36+
}

src/hyperclick.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as Atom from "atom";
2+
3+
declare module "atom-ide" {
4+
export interface HyperclickProvider {
5+
// Use this to provide a suggestion for single-word matches.
6+
// Optionally set `wordRegExp` to adjust word-matching.
7+
getSuggestionForWord?: (
8+
textEditor: Atom.TextEditor,
9+
text: string,
10+
range: Atom.Range
11+
) => Promise<HyperclickSuggestion | null | undefined>;
12+
13+
wordRegExp?: RegExp;
14+
15+
// Use this to provide a suggestion if it can have non-contiguous ranges.
16+
// A primary use-case for this is Objective-C methods.
17+
getSuggestion?: (
18+
textEditor: Atom.TextEditor,
19+
position: Atom.Point
20+
) => Promise<HyperclickSuggestion | null | undefined>;
21+
22+
// Must be unique. Used for analytics.
23+
providerName?: string;
24+
25+
// The higher this is, the more precedence the provider gets.
26+
priority: number;
27+
28+
// Optionally, limit the set of grammar scopes the provider should apply to.
29+
grammarScopes?: string[];
30+
}
31+
32+
export interface HyperclickSuggestion {
33+
// The range(s) to underline to provide as a visual cue for clicking.
34+
range: Atom.Range | Atom.Range[];
35+
36+
// The function to call when the underlined text is clicked.
37+
callback:
38+
| (() => void)
39+
| Array<{ rightLabel?: string; title: string; callback: () => void }>;
40+
}
41+
}

src/outline.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as Atom from "atom";
2+
3+
declare module "atom-ide" {
4+
export interface OutlineProvider {
5+
name: string;
6+
// If there are multiple providers for a given grammar, the one with the highest priority will be
7+
// used.
8+
priority: number;
9+
grammarScopes: ReadonlyArray<string>;
10+
updateOnEdit?: boolean;
11+
getOutline(editor: Atom.TextEditor): Promise<Outline | null | undefined>;
12+
}
13+
14+
export interface OutlineTree {
15+
icon?: string; // from Atom.Octicon (that type's not allowed over rpc so we use string)
16+
kind?: OutlineTreeKind; // kind you can pass to the UI for theming
17+
18+
// Must be one or the other. If both are present, tokenizedText is preferred.
19+
plainText?: string;
20+
tokenizedText?: TokenizedText;
21+
22+
// If user has atom-ide-outline-view.nameOnly then representativeName is used instead.
23+
representativeName?: string;
24+
25+
startPosition: Atom.Point;
26+
endPosition?: Atom.Point;
27+
landingPosition?: Atom.Point;
28+
children: OutlineTree[];
29+
}
30+
31+
export interface Outline {
32+
outlineTrees: OutlineTree[];
33+
}
34+
35+
// Kind of outline tree - matches the names from the Language Server Protocol v2.
36+
export type OutlineTreeKind =
37+
| "file"
38+
| "module"
39+
| "namespace"
40+
| "package"
41+
| "class"
42+
| "method"
43+
| "property"
44+
| "field"
45+
| "constructor"
46+
| "enum"
47+
| "interface"
48+
| "function"
49+
| "variable"
50+
| "constant"
51+
| "string"
52+
| "number"
53+
| "boolean"
54+
| "array";
55+
56+
export type TokenKind =
57+
| "keyword"
58+
| "class-name"
59+
| "constructor"
60+
| "method"
61+
| "param"
62+
| "string"
63+
| "whitespace"
64+
| "plain"
65+
| "type";
66+
67+
export interface TextToken {
68+
kind: TokenKind;
69+
value: string;
70+
}
71+
72+
export type TokenizedText = TextToken[];
73+
}

0 commit comments

Comments
 (0)