loading javascript file to library.

Hi,

Can anybody please tell how to load a pure javascript file in to the global library programmaticaly.

I did it via creating a library of a jar file which contains that javascript file. But it did not serve the purpose. ( I need to inherit some syntax highlighting like in Ajax.js, HTML5.js).

Thanks..!!

3 comments
Comment actions Permalink

Hi,

I could load the js file  using following procedure. But it is not loaded as javascript library.

   jsVirtualFile=LocalFileSystem.getInstance().findFileByIoFile(vf) ;
                                                    project = psiManager.getProject();



                                                    module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
                                                    rootManager = ModuleRootManager.getInstance(module1);
                                                    rootModel = rootManager.getModifiableModel();



                                                    Library myLibrary = rootModel.getModuleLibraryTable().createLibrary("MyLibrary");      //set the name as MyLibrary and create the library



                                                    System.out.println("MyLibrary ="+myLibrary.getName());
                                                    Library.ModifiableModel libraryModel = myLibrary.getModifiableModel();
                                                    libraryModel.addRoot(jsVirtualFile, OrderRootType.CLASSES);
                                                    libraryModel.commit();

                                                    rootModel.commit();




But it is not loaded as javascript library.

For an example I want to do the fllowing  procedure programatically.

Settings ----> Project Settings ----->Javascript ----->Libraries ------------> Configure ---------> Load the js file.

Above code loaded the .js file as library but not configured as javascript library.( File loaded is not shown in Javascript libraries)

How can I achieve that. Where have I gone wrong?. Can I achieve it through scripting libraries. But the source code for getting scripting libraries are not available.

Your kind help is highly appreciated.


Thanks..!!

0
Comment actions Permalink

JS plug-in has an extension point called JSPredefinedLibraryProvider which allows other dependent plug-ins have bundled js libraries. In turn it also depends on webcore module but it's not a part of the public API. Just adding a file like a class root type will not work because normally roots are expected to be directories. The best you can do is to add a parent directory as a root instead.

0
Comment actions Permalink

Hi,
Thanks for the exact answer Rustam.
Needed to extend JSPredefinedLibraryProvider defined in Javascript jar. (It was in the IDEA installation folder).

Thanks ..!!

0

Please sign in to leave a comment.