WI-2477: Ability to specify to a file a JavaScript library/file to autocomplete from (in progress)

This commit is contained in:
Rustam.Vishnyakov
2010-10-14 16:10:29 +04:00
parent c1bcf9645e
commit 78156dd3b1
5 changed files with 81 additions and 10 deletions
@@ -16,13 +16,11 @@
package com.intellij.ide.scriptingContext;
import com.intellij.ide.scriptingContext.ui.ScriptingLibrariesPanel;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.scripting.ScriptingLibraryManager;
import org.jetbrains.annotations.Nls;
import javax.swing.*;
@@ -16,11 +16,10 @@
package com.intellij.ide.scriptingContext;
import com.intellij.ide.scriptingContext.ui.MainScriptingContextsPanel;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.scripting.ScriptingLibraryManager;
import org.jetbrains.annotations.Nls;
import javax.swing.*;
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.scriptingContext;
package com.intellij.openapi.roots.libraries.scripting;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
@@ -25,7 +26,6 @@ import com.intellij.util.indexing.IndexableSetContributor;
import gnu.trove.THashSet;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Set;
/**
@@ -38,6 +38,12 @@ public abstract class ScriptingIndexableSetContributor extends IndexableSetContr
final Set<VirtualFile> predefinedFiles = getPredefinedFilesToIndex();
final THashSet<VirtualFile> filesToIndex = new THashSet<VirtualFile>();
filesToIndex.addAll(predefinedFiles);
filesToIndex.addAll(getLibraryFiles(project));
return filesToIndex;
}
public Set<VirtualFile> getLibraryFiles(Project project) {
final THashSet<VirtualFile> libFiles = new THashSet<VirtualFile>();
if (project != null) {
ScriptingLibraryManager manager = new ScriptingLibraryManager(project);
LibraryTable libTable = manager.getLibraryTable();
@@ -45,13 +51,13 @@ public abstract class ScriptingIndexableSetContributor extends IndexableSetContr
for (Library lib : libTable.getLibraries()) {
for (VirtualFile libFile : lib.getFiles(OrderRootType.CLASSES)) {
libFile.putUserData(getIndexKey(), "");
filesToIndex.add(libFile);
libFiles.add(libFile);
}
}
}
manager.disposeModel();
}
return filesToIndex;
return libFiles;
}
@Override
@@ -0,0 +1,68 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.roots.libraries.scripting;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.indexing.IndexableSetContributor;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* @author Rustam Vishnyakov
*/
public class ScriptingLibrariesScope extends GlobalSearchScope {
private GlobalSearchScope myBaseScope;
private ScriptingIndexableSetContributor myContributor;
public ScriptingLibrariesScope(GlobalSearchScope baseScope, Class<? extends IndexableSetContributor> providerClass) {
super(baseScope.getProject());
myBaseScope = baseScope;
IndexableSetContributor contributor = IndexableSetContributor.EP_NAME.findExtension(providerClass);
if (contributor instanceof ScriptingIndexableSetContributor) {
myContributor = (ScriptingIndexableSetContributor)contributor;
}
}
public boolean contains(VirtualFile file) {
return myBaseScope.contains(file) | contributorContains(file);
}
private boolean contributorContains(VirtualFile file) {
if (myContributor == null) return false;
return myContributor.getLibraryFiles(myBaseScope.getProject()).contains(file);
}
@Override
public boolean isSearchOutsideRootModel() {
return true;
}
public int compare(VirtualFile file1, VirtualFile file2) {
return myBaseScope.compare(file1, file2);
}
public boolean isSearchInModuleContent(@NotNull Module aModule) {
return myBaseScope.isSearchInModuleContent(aModule);
}
public boolean isSearchInLibraries() {
return myBaseScope.isSearchInLibraries();
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.scriptingContext;
package com.intellij.openapi.roots.libraries.scripting;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;