From ed0860feecfaa4aab5ca62ffbe36c5e0fd0fa7fa Mon Sep 17 00:00:00 2001 From: Calvin Fernandez Date: Wed, 24 Jun 2015 18:59:57 -0400 Subject: [PATCH] added typings for codemirror's lint addon --- codemirror/codemirror-tests.ts | 30 ++++++++++++++++++++ codemirror/codemirror.d.ts | 51 ++++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/codemirror/codemirror-tests.ts b/codemirror/codemirror-tests.ts index d81838ba95..d0da7f5228 100644 --- a/codemirror/codemirror-tests.ts +++ b/codemirror/codemirror-tests.ts @@ -16,3 +16,33 @@ var myCodeMirror4: CodeMirror.Editor = CodeMirror.fromTextArea(myTextArea); var doc: CodeMirror.Doc = new CodeMirror.Doc('text'); var doc2: CodeMirror.Doc = CodeMirror(document.body).getDoc(); + +var lintStateOptions: CodeMirror.LintStateOptions = { + async: true, + hasGutters: true +}; + +var lintOptions: CodeMirror.LintOptions = { + async: true, + hasGutters: true, + getAnnotations: (content: string, + updateLintingCallback: CodeMirror.UpdateLintingCallback, + options: CodeMirror.LintStateOptions, + codeMirror: CodeMirror.Editor) => {} +}; + +var updateLintingCallback: CodeMirror.UpdateLintingCallback = (codeMirror: CodeMirror.Editor, + annotations: CodeMirror.Annotation[]) => {}; + +var annotation: CodeMirror.Annotation = { + from: { + ch: 0, + line: 0 + }, + to: { + ch: 1, + line: 0 + }, + message: "test", + severity: "warning" +}; diff --git a/codemirror/codemirror.d.ts b/codemirror/codemirror.d.ts index 65692cf1c1..4b0a7ca6d4 100644 --- a/codemirror/codemirror.d.ts +++ b/codemirror/codemirror.d.ts @@ -761,7 +761,10 @@ declare module CodeMirror { This affects the amount of updates needed when scrolling, and the amount of work that such an update does. You should usually leave it at its default, 10. Can be set to Infinity to make sure the whole document is always rendered, and thus the browser's text search works on it. This will have bad effects on performance of big documents. */ - viewportMargin?: number; + viewportMargin?: number; + + /** Optional lint configuration to be used in conjunction with CodeMirror's linter addon. */ + lint?: LintOptions; } interface TextMarkerOptions { @@ -1004,6 +1007,48 @@ declare module CodeMirror { * Both modes get to parse all of the text, but when both assign a non-null style to a piece of code, the overlay wins, unless * the combine argument was true and not overridden, or state.overlay.combineTokens was true, in which case the styles are combined. */ - function overlayMode(base: Mode, overlay: Mode, combine?: boolean): Mode - + function overlayMode(base: Mode, overlay: Mode, combine?: boolean): Mode + + /** + * async specifies that the lint process runs asynchronously. hasGutters specifies that lint errors should be displayed in the CodeMirror + * gutter, note that you must use this in conjunction with [ "CodeMirror-lint-markers" ] as an element in the gutters argument on + * initialization of the CodeMirror instance. + */ + interface LintStateOptions { + async: boolean; + hasGutters: boolean; + } + + /** + * Adds the getAnnotations callback to LintStateOptions which may be overridden by the user if they choose use their own + * linter. + */ + interface LintOptions extends LintStateOptions { + getAnnotations: AnnotationsCallback; + } + + /** + * A function that calls the updateLintingCallback with any errors found during the linting process. + */ + interface AnnotationsCallback { + (content: string, updateLintingCallback: UpdateLintingCallback, options: LintStateOptions, codeMirror: Editor): void; + } + + /** + * A function that, given an array of annotations, updates the CodeMirror linting GUI with those annotations + */ + interface UpdateLintingCallback { + (codeMirror: Editor, annotations: Annotation[]): void; + } + + /** + * An annotation contains a description of a lint error, detailing the location of the error within the code, the severity of the error, + * and an explaination as to why the error was thrown. + */ + interface Annotation { + from: Position; + message?: string; + severity?: string; + to?: Position; + } }