Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hack to support start/end location of eslint by waiting for
- Loading branch information
1 parent
f353663
commit de16502
Showing
5 changed files
with
23,352 additions
and
17,239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<!doctype html> | ||
|
||
<title>CodeMirror: Tern Demo</title> | ||
<meta charset="utf-8"/> | ||
|
||
<!-- CodeMirror --> | ||
<link rel="stylesheet" href="../node_modules/codemirror/lib/codemirror.css"> | ||
<script src="../node_modules/codemirror/lib/codemirror.js"></script> | ||
<link rel="stylesheet" href="../node_modules/codemirror/theme/eclipse.css"> | ||
<script src="../node_modules/codemirror/addon/edit/closetag.js"></script> | ||
<script src="../node_modules/codemirror/addon/edit/closebrackets.js"></script> | ||
<script src="../node_modules/codemirror/addon/edit/matchbrackets.js"></script> | ||
<script src="../node_modules/codemirror/addon/selection/active-line.js"></script> | ||
<script src="../node_modules/codemirror/addon/runmode/runmode.js"></script> | ||
<script src="../node_modules/codemirror/mode/javascript/javascript.js"></script> | ||
|
||
<script src="../node_modules/codemirror/addon/lint/lint.js"></script> | ||
<link rel="stylesheet" href="../node_modules/codemirror/addon/lint/lint.css"> | ||
|
||
|
||
<script> | ||
var defs = []; | ||
CodeMirror.tern = {}; | ||
CodeMirror.tern.addDef = function(def) { | ||
defs.push(def); | ||
} | ||
</script> | ||
<script src="../node_modules/codemirror-javascript/demo/defs/ecma5.json.js"></script> | ||
<script src="../node_modules/codemirror-javascript/demo/defs/browser.json.js"></script> | ||
|
||
<!-- Tern JS --> | ||
<script src="../node_modules/tern/node_modules/acorn/dist/acorn.js"></script> | ||
<script src=" ../node_modules/tern/node_modules/acorn/dist/acorn_loose.js"></script> | ||
<script src="../node_modules/tern/node_modules/acorn/dist/walk.js"></script> | ||
<script src="../node_modules/tern/lib/signal.js"></script> | ||
<script src="../node_modules/tern/lib/tern.js"></script> | ||
<script src="../node_modules/tern/lib/def.js"></script> | ||
<script src="../node_modules/tern/lib/comment.js"></script> | ||
<script src="../node_modules/tern/lib/infer.js"></script> | ||
<script src="../node_modules/tern/plugin/requirejs.js"></script> | ||
|
||
<!-- Official CodeMirror Tern addon --> | ||
<script src="../node_modules/codemirror/addon/tern/tern.js"></script> | ||
|
||
<link rel="stylesheet" href="../node_modules/codemirror/addon/dialog/dialog.css"> | ||
<link rel="stylesheet" href="../node_modules/codemirror/addon/hint/show-hint.css"> | ||
<link rel="stylesheet" href="../node_modules/codemirror/addon/tern/tern.css"> | ||
<script src="../node_modules/codemirror/addon/dialog/dialog.js"></script> | ||
<script src="../node_modules/codemirror/addon/hint/show-hint.js"></script> | ||
<script src="../node_modules/codemirror/addon/tern/tern.js"></script> | ||
|
||
<!-- Tern Eslint Lint --> | ||
<script src="resources/eslint/eslint.js"></script> | ||
<script src="../codemirror/addon/lint/tern-eslint.js"></script> | ||
<script src="../eslint.js"></script> | ||
|
||
<style> | ||
.CodeMirror {border: 1px solid #ddd;} | ||
</style> | ||
|
||
<article> | ||
<h2>Tern ESLint Demo</h2> | ||
<form><textarea id="code" name="code">var abcd; // abcd should be highlighted</textarea></p> | ||
|
||
<p>Demonstrates integration of <a href="http://ternjs.net/">Tern</a> | ||
and CodeMirror. The following keys are bound:</p> | ||
|
||
<dl> | ||
<dt>Ctrl-Space</dt><dd>Autocomplete</dd> | ||
<dt>Ctrl-I</dt><dd>Find type at cursor</dd> | ||
<dt>Alt-.</dt><dd>Jump to definition (Alt-, to jump back)</dd> | ||
<dt>Ctrl-Q</dt><dd>Rename variable</dd> | ||
</dl> | ||
|
||
<p>Documentation is sparse for now. See the top of | ||
the <a href="../node_modules/codemirror/addon/tern/tern.js">script</a> for a rough API | ||
overview.</p> | ||
|
||
<script> | ||
|
||
function getURL(url, c) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("get", url, true); | ||
xhr.send(); | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState != 4) return; | ||
if (xhr.status < 400) return c(null, xhr.responseText); | ||
var e = new Error(xhr.responseText || "No response"); | ||
e.status = xhr.status; | ||
c(e); | ||
}; | ||
} | ||
|
||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
lineNumbers: true, | ||
mode: "javascript" | ||
}); | ||
|
||
//var server; | ||
//getURL("http://ternjs.net/defs/ecma5.json", function(err, code) { | ||
// if (err) throw new Error("Request for ecma5.json: " + err); | ||
var server = new CodeMirror.TernServer({defs: defs, plugins:{"eslint": {}}}); | ||
editor.setOption("extraKeys", { | ||
"Ctrl-Space": function(cm) { server.complete(cm); }, | ||
"Ctrl-I": function(cm) { server.showType(cm); }, | ||
"Alt-.": function(cm) { server.jumpToDef(cm); }, | ||
"Alt-,": function(cm) { server.jumpBack(cm); }, | ||
"Ctrl-Q": function(cm) { server.rename(cm); }, | ||
}) | ||
editor.setOption("gutters",["CodeMirror-lint-markers"]); | ||
editor.setOption("lint", {getAnnotations: CodeMirror.ternESLint, async : true, server: server}) | ||
editor.on("cursorActivity", function(cm) { server.updateArgHints(cm); }); | ||
//}); | ||
|
||
</script> | ||
|
||
</article> |
Oops, something went wrong.