Search in sources :

Example 1 with JSLibraryMappings

use of com.intellij.lang.javascript.library.JSLibraryMappings in project intellij-plugins by JetBrains.

the class JstdResolveTest method addJstdLibrary.

private static void addJstdLibrary(@NotNull final Project project, @NotNull final Collection<VirtualFile> libSourceFiles) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        JSLibraryManager jsLibraryManager = ServiceManager.getService(project, JSLibraryManager.class);
        ScriptingLibraryModel libraryModel = jsLibraryManager.createLibrary(JstdLibraryUtil.LIBRARY_NAME, VfsUtilCore.toVirtualFileArray(libSourceFiles), VirtualFile.EMPTY_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, ScriptingLibraryModel.LibraryLevel.GLOBAL, false);
        JSLibraryMappings jsLibraryMappings = ServiceManager.getService(project, JSLibraryMappings.class);
        jsLibraryMappings.associate(null, libraryModel.getName());
        jsLibraryManager.commitChanges();
    });
}
Also used : ScriptingLibraryModel(com.intellij.webcore.libraries.ScriptingLibraryModel) JSLibraryManager(com.intellij.lang.javascript.library.JSLibraryManager) JSLibraryMappings(com.intellij.lang.javascript.library.JSLibraryMappings)

Example 2 with JSLibraryMappings

use of com.intellij.lang.javascript.library.JSLibraryMappings in project intellij-plugins by JetBrains.

the class JstdLibraryUtil method isCorrectMapping.

private static boolean isCorrectMapping(@NotNull Project project, @NotNull VirtualFile file) {
    JSLibraryMappings jsLibraryMappings = JSLibraryMappings.getInstance(project);
    // TODO search for all JsTD libraries
    List<VirtualFile> usageScope = jsLibraryMappings.getMappingsByLibraryName(LIBRARY_NAME);
    String filePath = file.getPath();
    for (VirtualFile root : usageScope) {
        if (root == null) {
            return true;
        }
        if (filePath.startsWith(root.getPath())) {
            return true;
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSLibraryMappings(com.intellij.lang.javascript.library.JSLibraryMappings)

Aggregations

JSLibraryMappings (com.intellij.lang.javascript.library.JSLibraryMappings)2 JSLibraryManager (com.intellij.lang.javascript.library.JSLibraryManager)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ScriptingLibraryModel (com.intellij.webcore.libraries.ScriptingLibraryModel)1