| Summary: | Make grammar provider configurable in edit.js | ||
|---|---|---|---|
| Product: | [ECD] Orion | Reporter: | Miro Spönemann <miro.spoenemann> |
| Component: | Editor | Assignee: | Grant Gayed <grant_gayed> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | mamacdon |
| Version: | 8.0 | ||
| Target Milestone: | 10.0 | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| See Also: | https://git.eclipse.org/r/50522 | ||
| Whiteboard: | |||
|
Description
Miro Spönemann
New Gerrit change created: https://git.eclipse.org/r/50522 It might make sense to generalize this a bit, and allow the caller to provide an alternative impl of lines 262-275 [1] For example, suppose the caller could provide a function like this: > function loadGrammar(contentType, onDone, onError) { > // Obtains the grammar for the given contentType. > // On success invokes onDone(grammar) > // On error invokes onError(error) > } This way, the caller injects the loading logic into the editor. So they are not forced to provide a require()-able path; they can obtain a grammar through any means. @Grant what is your opinion on this? [1] https://github.com/eclipse/orion.client/blob/master/bundles/org.eclipse.orion.client.editor/web/orion/editor/edit.js#L262-L275 (In reply to Mark Macdonald from comment #2) Agreed, this would definitely be a better path to take. I think both would make sense as alternative options: options.grammarLoader to pass a function that obtains the syntax options.grammarModule to pass a module name to be loaded with require Having both seems redundant, in the interest of API succinctness I've only added the option to provide a function. The function must return a promise so that if needed it can answer the grammars asynchronously. The commit is: http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=b847251179cd41a62222443a7c3f84efcefcff55 . An example of using it follows, based on org.eclipse.orion.client.editor/web/examples/editor/edit.html. As a side note, in the new stand-alone editor story this would be done by simply providing the additional language grammars in new plug-in(s). <script> /*eslint-env browser, amd*/ require({ baseUrl: '../..', paths: { i18n: 'requirejs/i18n', csslint: 'csslint/csslint', } }); var CONTENT_TYPE = "application/asdf"; require(["orion/editor/edit", "orion/Deferred"], function(edit, Deferred) { edit({ contentType: CONTENT_TYPE, grammarProvider: function(contentType) { var result = new Deferred(); if (contentType === CONTENT_TYPE) { require(["orion/editor/stylers/application_javascript/syntax"], function(grammar) { result.resolve(grammar); }, function(error) { result.reject(); }); } else { result.resolve(); } return result; } }); }); </script> |