From b35e77ddefd1ea5a09b2e6748391b123ab476b55 Mon Sep 17 00:00:00 2001 From: Nikolaj Kappler Date: Tue, 6 Nov 2018 16:01:50 +0100 Subject: [PATCH 1/2] initial commit for tern addon typings. still WIP. workstream: --- types/codemirror/codemirror-tern.d.ts | 80 +++++++++++++++++++++++++++ types/codemirror/tsconfig.json | 1 + 2 files changed, 81 insertions(+) create mode 100644 types/codemirror/codemirror-tern.d.ts diff --git a/types/codemirror/codemirror-tern.d.ts b/types/codemirror/codemirror-tern.d.ts new file mode 100644 index 0000000000..5b882a096a --- /dev/null +++ b/types/codemirror/codemirror-tern.d.ts @@ -0,0 +1,80 @@ +//MUCH TODO + + +import * as CodeMirror from "codemirror"; + +declare module "codemiror" { + + export const TernServer: TernConstructor; + + interface TernServer { + + addDoc: ( + name: string, + doc: CodeMirror.Doc + ) => { + doc: CodeMirror.Doc, + name: string, + changed: { from: number, to: number } | null + }; + + delDoc: (id: string | CodeMirror.Editor | CodeMirror.Doc) => void; + + hideDoc: (id: string | CodeMirror.Editor | CodeMirror.Doc) => void; + + complete: (cm: CodeMirror.Editor) => void; + + showType: (cm: CodeMirror.Editor, pos?: CodeMirror.Position, callback?: Function) => void; + + showDocs: (cm: CodeMirror.Editor, pos?: CodeMirror.Position, callback?: Function) => void; + + updateArgHints: (cm: CodeMirror.Editor) => void; + + jumpToDef: (cm: CodeMirror.Editor) => void; + + jumpBack: (cm: CodeMirror.Editor) => void; + + rename: (cm: CodeMirror.Editor) => void; + + selectName: (cm: CodeMirror.Editor) => void; + + request: (cm: CodeMirror.Editor, query: string | Query, callback: (error: any, data?: any) => void, pos?: CodeMirror.Position) => void; + + destroy: () => void; + } + + interface TernConstructor { + new(options?: TernOptions): TernServer; + } + + interface TernOptions { + plugins?: any; + defs?: any[]; + getFile?: (name: string, callback: (doc: any) => void) => void; + fileFilter?: (value: any, docName: string, doc: any) => any; + switchToDoc?: (name: string, doc: any) => any; + showError?: (editor: CodeMirror.Editor, message: any) => void; + completionTip?: any; + typeTip?: any; + responseFilter?: (doc, query, request, error, data) => any; + useWorker?: boolean; + workerScript?: any; + workerDeps?: string[]; + } + + interface Query { + type: string; + file: string; //either the file name or a number in the following representation #0 #1 #2 etc... + scope?: Scope; + lineCharPositions?: boolean; + lineNumber?: number; + groupByFiles?: any; + start?: CodeMirror.Position; + end?: CodeMirror.Position; + } + +} + +declare module "codemirror/addon/tern/tern" { + export = CodeMirror; +} diff --git a/types/codemirror/tsconfig.json b/types/codemirror/tsconfig.json index 79d2eae5c3..caf680e2c2 100644 --- a/types/codemirror/tsconfig.json +++ b/types/codemirror/tsconfig.json @@ -23,6 +23,7 @@ "codemirror-panel.d.ts", "codemirror-runmode.d.ts", "codemirror-showhint.d.ts", + "codemirror-tern.d.ts", "searchcursor.d.ts", "test/index.ts", "test/matchbrackets.ts", From cdb4f1157697e1868d18744db83c28d570272ee1 Mon Sep 17 00:00:00 2001 From: Nikolaj Kappler Date: Tue, 6 Nov 2018 16:01:50 +0100 Subject: [PATCH 2/2] initial commit for tern addon typings. still WIP. workstream: --- types/codemirror/codemirror-tern.d.ts | 112 ++++++++++++++++++++++++++ types/codemirror/tsconfig.json | 1 + 2 files changed, 113 insertions(+) create mode 100644 types/codemirror/codemirror-tern.d.ts diff --git a/types/codemirror/codemirror-tern.d.ts b/types/codemirror/codemirror-tern.d.ts new file mode 100644 index 0000000000..087307e200 --- /dev/null +++ b/types/codemirror/codemirror-tern.d.ts @@ -0,0 +1,112 @@ +//MUCH TODO + + +import * as CodeMirror from "codemirror"; +import * as Tern from "tern"; + +declare module "codemiror" { + + interface Editor { + server: TernServer; + } + + interface TernServer { + + addDoc: ( + name: string, + doc: CodeMirror.Doc + ) => { + doc: CodeMirror.Doc, + name: string, + changed: { from: number, to: number } | null + }; + + delDoc: (id: string | CodeMirror.Editor | CodeMirror.Doc) => void; + + hideDoc: (id: string | CodeMirror.Editor | CodeMirror.Doc) => void; + + complete: (cm: CodeMirror.Editor) => void; + + showType: (cm: CodeMirror.Editor, pos?: CodeMirror.Position, callback?: Function) => void; + + showDocs: (cm: CodeMirror.Editor, pos?: CodeMirror.Position, callback?: Function) => void; + + updateArgHints: (cm: CodeMirror.Editor) => void; + + jumpToDef: (cm: CodeMirror.Editor) => void; + + jumpBack: (cm: CodeMirror.Editor) => void; + + rename: (cm: CodeMirror.Editor) => void; + + selectName: (cm: CodeMirror.Editor) => void; + + request: (cm: CodeMirror.Editor, query: string | Tern.QueryRegistry[keyof Tern.QueryRegistry]["query"], callback: (error: any, data?: any) => void, pos?: CodeMirror.Position) => void; + + destroy: () => void; + } + + interface TernConstructor { + new(options?: TernOptions): TernServer; + } + export const TernServer: TernConstructor; + + interface TernOptions { + /** An object mapping plugin names to configuration options. */ + plugins?: Tern.ConstructorOptions["plugins"]; + /** An array of JSON definition data structures. */ + defs?: Tern.ConstructorOptions["defs"]; + /** + * Can be used to access files in + * the project that haven't been loaded yet. Simply do callback(null) to + * indicate that a file is not available. + */ + getFile?: (name: string, callback: (doc: CodeMirror.Doc | null) => void) => void; + /** + * This function will be applied + * to documents before passing them on to Tern. + */ + fileFilter?: (value: any, docName: string, doc: CodeMirror.Doc) => any; + /** This function should, when providing a multi-file view, switch the view or focus to the named file. */ + switchToDoc?: (name: string, doc: CodeMirror.Doc) => any; + /** Can be used to override the way errors are displayed. */ + showError?: (editor: CodeMirror.Editor, message: any) => void; + /** + * Customize the content in tooltips for completions. + * Is passed a single argument—the completion's data as returned by + * Tern—and may return a string, DOM node, or null to indicate that + * no tip should be shown. By default the docstring is shown. + */ + completionTip?: (data: Tern.QueryRegistry["completions"]["result"]) => string | HTMLElement | null; + /** Like completionTip, but for the tooltips shown for type queries. */ + typeTip?: (data: Tern.QueryRegistry["type"]["result"]) => string | HTMLElement | null; + /** This function will be applied to the Tern responses before treating them */ + responseFilter?: ( + doc: CodeMirror.Doc, + query: Tern.QueryRegistry[keyof Tern.QueryRegistry]["query"], + request: any, + error: Error, + data: any + ) => any; + /** + * Set to true to enable web worker mode. You'll probably + * want to feature detect the actual value you use here, for example + * !!window.Worker. + */ + useWorker?: boolean; + /** The main script of the worker. Point this to wherever you are hosting worker.js from this directory. */ + workerScript?: any; + /** + * An array of paths pointing (relative to workerScript) + * to the Acorn and Tern libraries and any Tern plugins you want to + * load. Or, if you minified those into a single script and included + * them in the workerScript, simply leave this undefined. + */ + workerDeps?: string[]; + } + +} + +declare module "codemirror/addon/tern/tern" { + export = CodeMirror; +} diff --git a/types/codemirror/tsconfig.json b/types/codemirror/tsconfig.json index 79d2eae5c3..caf680e2c2 100644 --- a/types/codemirror/tsconfig.json +++ b/types/codemirror/tsconfig.json @@ -23,6 +23,7 @@ "codemirror-panel.d.ts", "codemirror-runmode.d.ts", "codemirror-showhint.d.ts", + "codemirror-tern.d.ts", "searchcursor.d.ts", "test/index.ts", "test/matchbrackets.ts",