TimoStaudinger / tern-openui5

🛠 Autocomplete for the OpenUI5 framework for your favorite code editor, powered by Tern.
Other
27 stars 3 forks source link

Support for sap.ui.define #3

Open angelozerr opened 8 years ago

angelozerr commented 8 years ago

sap.ui.define seems working like RequireJS define. It should inject the well type. I suggest you that you do the same thing by developping a custom tern function like "requirejs_define" https://github.com/ternjs/tern/blob/master/plugin/requirejs.js#L178

TimoStaudinger commented 8 years ago

I was actually looking into this exact thing today! It seems like UI5 is using its own implementation similar to RequireJS, with some additional 'features'. As you said, the way the RequireJS tern plugin deals with it should however easily be adaptable to this, I believe.

Feel free to contribute if you want! :-)

 * <b>Differences to requireJS</b><br>
 * The current implementation of <code>sap.ui.define</code> differs from <code>requireJS</code>
 * or other AMD loaders in several aspects:
 * <ul>
 * <li>the name <code>sap.ui.define</code> is different from the plain <code>define</code>.
 * This has two reasons: first, it avoids the impression that <code>sap.ui.define</code> is
 * an exact implementation of an AMD loader. And second, it allows the coexistence of an AMD
 * loader (requireJS) and <code>sap.ui.define</code> in one application as long as UI5 or
 * apps using UI5 are not fully prepared to run with an AMD loader</li>
 * <li><code>sap.ui.define</code> currently loads modules with synchronous XHR calls. This is
 * basically a tribute to the synchronous history of UI5.
 * <b>BUT:</b> synchronous dependency loading and factory execution explicitly it not part of
 * contract of <code>sap.ui.define</code>. To the contrary, it is already clear and planned
 * that asynchronous loading will be implemented, at least as an alternative if not as the only
 * implementation. Also check section <b>Asynchronous Contract</b> above.<br>
 * Applications that need to ensure synchronous loading of dependencies <b>MUST</b> use the old
 * {@link jQuery.sap.require} API.</li>
 * <li><code>sap.ui.define</code> does not support plugins to use other file types, formats or
 * protocols. It is not planned to support this in future</li>
 * <li><code>sap.ui.define</code> does <b>not</b> support the 'sugar' of requireJS where CommonJS
 * style dependency declarations using <code>sap.ui.require("something")</code> are automagically
 * converted into <code>sap.ui.define</code> dependencies before executing the factory function.</li>
 * </ul>

Source

angelozerr commented 8 years ago

Feel free to contribute if you want! :-)

To be honnest with you, I don't know OpenUI5. I would like to integrate your tern plugin with Eclipse it like other plugins https://github.com/angelozerr/tern.java/wiki

I will have no time to do this contribution. When you will support define, I will integrate inside tern.java.

I suggest you that you write tests too when you will develop this feature. Good luck!