UNPKG

5.74 kBTypeScriptView Raw
1// Autocomplete Plus 2.x
2// https://atom.io/packages/autocomplete-plus
3
4/// <reference path="./config.d.ts" />
5
6import { Point, ScopeDescriptor, TextEditor } from '../index';
7
8/** The parameters passed into getSuggestions by Autocomplete+. */
9export interface SuggestionsRequestedEvent {
10 /** The current TextEditor. */
11 editor: TextEditor;
12
13 /** The position of the cursor. */
14 bufferPosition: Point;
15
16 /** The scope descriptor for the current cursor position. */
17 scopeDescriptor: ScopeDescriptor;
18
19 /** The prefix for the word immediately preceding the current cursor position. */
20 prefix: string;
21
22 /** Whether the autocomplete request was initiated by the user. */
23 activatedManually: boolean;
24}
25
26/** The parameters passed into onDidInsertSuggestion by Autocomplete+. */
27export interface SuggestionInsertedEvent {
28 editor: TextEditor;
29 triggerPosition: Point;
30 suggestion: TextSuggestion | SnippetSuggestion;
31}
32
33/**
34 * An autocompletion suggestion for the user.
35 * Primary data type for the Atom Autocomplete+ service.
36 */
37export interface SuggestionBase {
38 /**
39 * A string that will show in the UI for this suggestion.
40 * When not set, snippet || text is displayed.
41 */
42 displayText?: string;
43
44 /**
45 * The text immediately preceding the cursor, which will be replaced by the text.
46 * If not provided, the prefix passed into getSuggestions will be used.
47 */
48 replacementPrefix?: string;
49
50 /**
51 * The suggestion type. It will be converted into an icon shown against the
52 * suggestion.
53 */
54 type?: string;
55
56 /** This is shown before the suggestion. Useful for return values. */
57 leftLabel?: string;
58
59 /** Use this instead of leftLabel if you want to use html for the left label. */
60 leftLabelHTML?: string;
61
62 /**
63 * An indicator (e.g. function, variable) denoting the "kind" of suggestion this
64 * represents.
65 */
66 rightLabel?: string;
67
68 /** Use this instead of rightLabel if you want to use html for the right label. */
69 rightLabelHTML?: string;
70
71 /**
72 * Class name for the suggestion in the suggestion list. Allows you to style your
73 * suggestion via CSS, if desired.
74 */
75 className?: string;
76
77 /**
78 * If you want complete control over the icon shown against the suggestion.
79 * e.g. iconHTML: <i class="icon-move-right"></i>
80 */
81 iconHTML?: string;
82
83 /**
84 * A doc-string summary or short description of the suggestion. When specified, it
85 * will be displayed at the bottom of the suggestions list.
86 */
87 description?: string;
88
89 /**
90 * A url to the documentation or more information about this suggestion.
91 * When specified, a More.. link will be displayed in the description area.
92 */
93 descriptionMoreURL?: string;
94
95 /**
96 * (experimental) Description with Markdown formatting.
97 * Takes precedence over plaintext description.
98 */
99 descriptionMarkdown?: string;
100}
101
102export interface TextSuggestion extends SuggestionBase {
103 /** The text which will be inserted into the editor, in place of the prefix. */
104 text: string;
105}
106
107export interface SnippetSuggestion extends SuggestionBase {
108 /**
109 * A snippet string. This will allow users to tab through function arguments
110 * or other options.
111 */
112 snippet: string;
113}
114
115export type AnySuggestion = TextSuggestion | SnippetSuggestion;
116export type Suggestion = AnySuggestion;
117export type Suggestions = AnySuggestion[];
118
119/** The interface that all Autocomplete+ providers must implement. */
120export interface AutocompleteProvider {
121 /**
122 * Defines the scope selector(s) (can be comma-separated) for which your provider
123 * should receive suggestion requests.
124 */
125 selector: string;
126
127 /**
128 * Defines the scope selector(s) (can be comma-separated) for which your provider
129 * should not be used.
130 */
131 disableForSelector?: string;
132
133 /**
134 * A number to indicate its priority to be included in a suggestions request.
135 * The default provider has an inclusion priority of 0. Higher priority providers
136 * can suppress lower priority providers with excludeLowerPriority.
137 */
138 inclusionPriority?: number;
139
140 /** Will not use lower priority providers when this provider is used. */
141 excludeLowerPriority?: boolean;
142
143 /**
144 * A number to determine the sort order of suggestions. The default provider has
145 * an suggestion priority of 1.
146 */
147 suggestionPriority?: number;
148
149 /** Let autocomplete+ filter and sort the suggestions you provide. */
150 filterSuggestions?: boolean;
151
152 /**
153 * Is called when a suggestion request has been dispatched by autocomplete+ to
154 * your provider. Return an array of suggestions (if any) in the order you would
155 * like them displayed to the user. Returning a Promise of an array of suggestions
156 * is also supported.
157 */
158 getSuggestions(params: SuggestionsRequestedEvent): Suggestions | Promise<Suggestions>;
159
160 /**
161 * (experimental) Is called when a suggestion is selected by the user for
162 * the purpose of loading more information about the suggestion. Return a
163 * Promise of the new suggestion to replace it with or return null if
164 * no change is needed.
165 */
166 getSuggestionDetailsOnSelect?(suggestion: AnySuggestion): Promise<AnySuggestion | null> | AnySuggestion | null;
167
168 /**
169 * Function that is called when a suggestion from your provider was inserted
170 * into the buffer.
171 */
172 onDidInsertSuggestion?(params: SuggestionInsertedEvent): void;
173
174 /** Will be called if your provider is being destroyed by autocomplete+ */
175 dispose?(): void;
176}