UNPKG

4.49 kBTypeScriptView Raw
1// See docs https://codemirror.net/doc/manual.html#addon_tern and https://codemirror.net/addon/tern/tern.js (comments in the beginning of the file)
2// Docs for tern itself might also be helpful: http://ternjs.net/doc/manual.html
3
4import * as Tern from 'tern';
5import '../../';
6
7declare module '../../' {
8 class TernServer {
9 constructor(options?: TernOptions);
10
11 readonly options: TernOptions;
12 readonly docs: {
13 readonly [key: string]: {
14 doc: Doc;
15 name: string;
16 changed: {
17 from: number;
18 to: number;
19 } | null;
20 };
21 };
22 readonly server: Tern.Server;
23 addDoc(
24 name: string,
25 doc: Doc,
26 ): { doc: Doc; name: string; changed: { from: number; to: number } | null };
27 delDoc(id: string | Editor | Doc): void;
28 hideDoc(id: string | Editor | Doc): void;
29 complete(cm: Editor): void;
30 showType(cm: Editor, pos?: Position, callback?: () => void): void;
31 showDocs(cm: Editor, pos?: Position, callback?: () => void): void;
32 updateArgHints(cm: Editor): void;
33 jumpToDef(cm: Editor): void;
34 jumpBack(cm: Editor): void;
35 rename(cm: Editor): void;
36 selectName(cm: Editor): void;
37 request<Q extends Tern.Query>(
38 cm: Doc,
39 query: Q,
40 callback: (error?: Error, data?: Tern.QueryResult<Q>) => void,
41 pos?: Position,
42 ): void;
43 request<Q extends Tern.Query['type']>(
44 cm: Doc,
45 query: Q,
46 callback: (error?: Error, data?: Tern.QueryRegistry[Q]['result']) => void,
47 pos?: Position,
48 ): void;
49 destroy(): void;
50 }
51
52 interface TernOptions {
53 /** An object mapping plugin names to configuration options. */
54 plugins?: Tern.ConstructorOptions['plugins'] | undefined;
55 /** An array of JSON definition data structures. */
56 defs?: Tern.Def[] | undefined;
57 /**
58 * Can be used to access files in
59 * the project that haven't been loaded yet. Simply do callback(null) to
60 * indicate that a file is not available.
61 */
62 getFile?(name: string, callback: (docValue: string | null) => any): any;
63 /**
64 * This function will be applied
65 * to documents before passing them on to Tern.
66 */
67 fileFilter?(value: string, docName: string, doc: Doc): string;
68 /** This function should, when providing a multi-file view, switch the view or focus to the named file. */
69 switchToDoc?(name: string, doc: Doc): void;
70 /** Can be used to override the way errors are displayed. */
71 showError?(editor: Editor, message: Error | string): void;
72 /**
73 * Customize the content in tooltips for completions.
74 * Is passed a single argumentthe completion's data as returned by
75 * Ternand may return a string, DOM node, or null to indicate that
76 * no tip should be shown. By default the docstring is shown.
77 */
78 completionTip?(data: Tern.CompletionsQueryResult): string | HTMLElement | null;
79 /** Like completionTip, but for the tooltips shown for type queries. */
80 typeTip?(data: Tern.TypeQueryResult): string | HTMLElement | null;
81 /** This function will be applied to the Tern responses before treating them */
82 responseFilter?<Q extends Tern.Query>(
83 doc: Doc,
84 query: Q,
85 request: Tern.Document,
86 error: Error | undefined,
87 data: Tern.QueryResult<Q> | undefined,
88 ): Tern.QueryResult<Q> | undefined;
89 /**
90 * Set to true to enable web worker mode. You'll probably
91 * want to feature detect the actual value you use here, for example
92 * !!window.Worker.
93 */
94 useWorker?: boolean | undefined;
95 /** The main script of the worker. Point this to wherever you are hosting worker.js from this directory. */
96 workerScript?: string | undefined;
97 /**
98 * An array of paths pointing (relative to workerScript)
99 * to the Acorn and Tern libraries and any Tern plugins you want to
100 * load. Or, if you minified those into a single script and included
101 * them in the workerScript, simply leave this undefined.
102 */
103 workerDeps?: string[] | undefined;
104 }
105}
106
\No newline at end of file