Skip to content

Instantly share code, notes, and snippets.

@mamacdon
Created July 24, 2015 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamacdon/cb1e20fd8f967e97cfb4 to your computer and use it in GitHub Desktop.
Save mamacdon/cb1e20fd8f967e97cfb4 to your computer and use it in GitHub Desktop.
Orion validator example
<!DOCTYPE html>
<html>
<head>
<title>Validator example</title>
<script src="https://orion.eclipse.org/orion/Deferred.js"></script> <!--must be loaded before plugin-->
<script src="https://orion.eclipse.org/orion/plugin.js"></script> <!--must be loaded before script tag -->
<script>
/*global orion Deferred*/
var provider = new orion.PluginProvider();
provider.registerServiceProvider("orion.edit.validator", {
computeProblems: function(editorContext, options) {
var problems = [];
return editorContext.getText().then(function(contents) {
var lines = contents.split(/\r?\n/);
for (var i=0; i < lines.length; i++) {
var line = lines[i];
var match = /\t \t| \t /.exec(line);
if (match) {
problems.push({
description: "Mixed spaces and tabs.",
line: i + 1,
start: match.index + 1,
end: match.index + match[0].length + 1,
severity: "warning"
});
}
}
var result = { problems: problems };
return result;
});
}
},
{ contentType: ["application/javascript"]
});
provider.connect();
</script>
</head>
<body>
Install this page as an Orion plugin
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment