Created
July 24, 2015 15:24
-
-
Save mamacdon/cb1e20fd8f967e97cfb4 to your computer and use it in GitHub Desktop.
Orion validator example
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
<!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