Merge pull request #17275 from madbrain/master

[codemirror] Linter function can either be sync or async
This commit is contained in:
Nathan Shively-Sanders
2017-06-20 11:01:28 -07:00
committed by GitHub
2 changed files with 19 additions and 4 deletions

View File

@@ -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<T, S>(base: Mode<T>, overlay: Mode<S>, combine?: boolean): Mode<any>
function overlayMode<T, S>(base: Mode<T>, overlay: Mode<S>, combine?: boolean): Mode<any>;
/**
* 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<Annotation[]>;
}
/**
* 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;
}

View File

@@ -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[]) => {};