Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse extension point for third party repository and/or tern module contributions #322

Closed
demonfiddler opened this issue Sep 15, 2015 · 9 comments
Milestone

Comments

@demonfiddler
Copy link
Contributor

Raised at Angelo's invitation, see #321.

The proposal is for an Eclipse extension point that would enable third party plug-ins to contribute a custom Tern repository (or Tern modules). These contributions would then be automatically included in the list of available modules when configuring your Tern Eclipse IDE workspace or Tern project. The extension point schema could be designed to allow a complete repository or individual modules to be contributed from a folder within a designated plug-in (defaulting to the plug-in contributing the extension). NOTE: I played around with such a schema but it soon became clear that implementing support for explicit module contributions would be hard, as the existing repository implementation seems to assume a fixed directory structure (metadata, node_modules/tern/defs|lib|node_modules|plugins).

Implementation note: the current repository implementation assumes that the modules are files in a physical file system, which forces plug-ins to be installed as unpacked directories rather than JAR files (the latter is generally preferred). However, given that these files are loaded by a JavaScript engine there's probably no alternative.

From issue 321: the default tern repository currently enumerates Tern modules as children of the node_modules/tern folder within the ternjs Eclipse plug-in. A binary plug-in's installed image should be treated as a read-only location. Eclipse plug-ins have a writable 'state location' (see Plugin.getStateLocation() : IPath), which would be an appropriate place for maintaining user-downloaded modules. So it might be better to aim for a 'composed repository' that presents the contents of several repositories as if they were a single repository. That way, you could still read the built-in modules from the ternjs binary plug-in image, read downloaded custom modules from the plug-in state location, and read additional repositories contributed by 3rd party Eclipse plug-ins via the proposed extension point from within their contributing plug-ins.

@angelozerr angelozerr added this to the 1.1.0 milestone Sep 15, 2015
@angelozerr
Copy link
Owner

@demonfiddler at first ternjs is able to load external tern plugins/JSON Type Defiition with convention name tern-* See http://ternjs.net/doc/manual.html#plugin_third_party

In tern.java,I have called that tern repository which follow node modules structures :

  • node_modules
    • acorn
    • tern
    • tern-*

The tern folder is the official tern project which hosts plugins+defs folder which contains official tern plugins/defs like brower,ecma5, node,etc. It should not contains external plugins (today it contains external plugin like extjs, but I must change that).

In other words, the extension point of this issue must copy a tern-* folder (or zip) from the Eclipse Plugin to folder of tern repository. tern.java have a default tern repository, but you can define your own tern repository. So my idea is to copy/paste tern-* from Eclipse plugin to the list of tern repositories.

I will implement at first a simple solution which deploy the tern-* folder from the Eclipse Plugin to tern repositories when Tern Core IDE is started (by checking the exist of the tern-* to avoid deploying each time that Eclipse will be started).

We will see after if we can improve this idea. Are you OK with that?

@angelozerr
Copy link
Owner

@demonfiddler I have started to implement this extension point. Please see sample of the extension point with the project https://github.com/angelozerr/tern.java/tree/master/samples/ternModuleInstalls which install tern-library tern module.

metadata is not supported for this moment. Tell me if you like, if it works for you. Any PR are welcome if you need to improve it.

@demonfiddler
Copy link
Contributor Author

@angelozerr, the new extension point looks good - thanks, I'll experiment with it today. The basic approach to managing custom repositories seems sound.

Also re. your first point I hadn't realised that you don't actually need to create a Tern plug-in to load a custom JSON defs file, which is useful to know.

@angelozerr
Copy link
Owner

@angelozerr, the new extension point looks good - thanks, I'll experiment with it today. The basic approach to managing custom repositories seems sound.

Glad the extension point seems to please you, but it should be improved:

  • today it unzip every time the tern plugin when Tern repository is loaded.
  • you can not use a folder (you must use a zip or jar)

Also re. your first point I hadn't realised that you don't actually need to create a Tern plug-in to load a custom JSON defs file, which is useful to know.

I prefer creating a tern plugin which uses a JSON Type Definition, because you can load it easily with Web Browser. If you must load JSON from the web browser, you need Ajax and for local HTML file it throws cross origin problem.

@demonfiddler
Copy link
Contributor Author

I finally got it working, took a while to figure out how to load my *.json def file as the Node.js world is somewhat unfamiliar territory for me. My plug-in actually loads the defs from a sibling JSON def in the plug-in directory since the JSON will be generated from the JavaScript which is generated from the XSDs as part of the build process.

Right now I'm focussed on getting this working in Eclipse, so it would be a nice plus if the extension point supported a way to register a def file directly rather than having to write a plug-in to do it (although I've already done just that). It looks like the Tern IDE framework would have to copy a JSON def file to /node_modules/tern/defs rather than /node_modules/; the extension point would need to provide a declarative means to differentiate a definition module installation from a plugin module installation, perhaps by providing a type attribute : string (definitions | plugins).

For future browser-based applications, I suppose I could always generate the plugin.js to embed the defs as other plug-ins have done, to avoid having to download the JSON file.

P.S. regarding support for folders (which would be better for a JAR-style plug-in), you can always use the OSGi Bundle API to read the structure and entries from the src path within the plug-in, and this approach would work regardless of whether the bundle is a directory or an archive. Then you wouldn't even need to support a ZIPped format (which is more work for a plug-in developer to create).

@angelozerr
Copy link
Owner

Right now I'm focussed on getting this working in Eclipse, so it would be a nice plus if the extension point supported a way to register a def file directly rather than having to write a plug-in to do it

At first, external plugin and JSON Type Definition are managed in teh same mean (creat ea folder with tern-mylibrary + create a package.json with a main field which is linked to the JS or JSON file).

When metadata will be supported, you will able to do that. You will have mylibrary.zip which contains mylibrary.json, package.json (which declare a main to mylibrary.js) and a metadata file with "def" to true like https://github.com/angelozerr/tern.java/blob/master/core/ternjs/metadata/titanium.metadata.json#L8 This info is needed by tern.java to know if it's the libs or plugin filed which must be updated in .tern-project when the tern module is selected.

So next step is to deploy metadata, an dafter it will work.

@demonfiddler
Copy link
Contributor Author

Cool, sounds good!

@angelozerr
Copy link
Owner

@demonfiddler now you can add metadata file in the tern plugin. See sample https://github.com/angelozerr/tern.java/tree/master/samples/ternModuleInstalls/modules/tern-mylibrary/metadata

I close this issue. If you have some bugs, please create an aother issue. Thanks.

@demonfiddler
Copy link
Contributor Author

Thanks Angelo, the metadata works now. Have logged an enhancement request #332 per my earlier comment in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants