added typings for codemirror's lint addon

This commit is contained in:
Calvin Fernandez 2015-06-24 18:59:57 -04:00
parent 8ebc099072
commit ed0860feec
2 changed files with 78 additions and 3 deletions

View File

@ -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"
};

View File

@ -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<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
* 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;
}
}