From b56761f148ed35c0faf42af642ddbde033b3cccf Mon Sep 17 00:00:00 2001 From: Ludovic L'Hours Date: Sat, 17 Jun 2017 22:44:01 +0200 Subject: [PATCH] [codemirror] Linter function can either be sync or async --- types/codemirror/index.d.ts | 13 ++++++++++--- types/codemirror/test/index.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/types/codemirror/index.d.ts b/types/codemirror/index.d.ts index 9a74dc1e53..b42ebabae3 100644 --- a/types/codemirror/index.d.ts +++ b/types/codemirror/index.d.ts @@ -1097,7 +1097,7 @@ declare namespace 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 @@ -1114,13 +1114,20 @@ declare namespace CodeMirror { * linter. */ interface LintOptions extends LintStateOptions { - getAnnotations: AnnotationsCallback; + getAnnotations: Linter | AsyncLinter; + } + + /** + * A function that return errors found during the linting process. + */ + interface Linter { + (content: string, options: LintStateOptions, codeMirror: Editor): Annotation[] | PromiseLike; } /** * A function that calls the updateLintingCallback with any errors found during the linting process. */ - interface AnnotationsCallback { + interface AsyncLinter { (content: string, updateLintingCallback: UpdateLintingCallback, options: LintStateOptions, codeMirror: Editor): void; } diff --git a/types/codemirror/test/index.ts b/types/codemirror/test/index.ts index 41b7170fd1..e283abe974 100644 --- a/types/codemirror/test/index.ts +++ b/types/codemirror/test/index.ts @@ -28,7 +28,7 @@ var lintStateOptions: CodeMirror.LintStateOptions = { hasGutters: true }; -var lintOptions: CodeMirror.LintOptions = { +var asyncLintOptions: CodeMirror.LintOptions = { async: true, hasGutters: true, getAnnotations: (content: string, @@ -37,6 +37,14 @@ var lintOptions: CodeMirror.LintOptions = { codeMirror: CodeMirror.Editor) => {} }; +var syncLintOptions: CodeMirror.LintOptions = { + async: false, + hasGutters: true, + getAnnotations: (content: string, + options: CodeMirror.LintStateOptions, + codeMirror: CodeMirror.Editor): CodeMirror.Annotation[] => { return []; } +}; + var updateLintingCallback: CodeMirror.UpdateLintingCallback = (codeMirror: CodeMirror.Editor, annotations: CodeMirror.Annotation[]) => {};