mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
OC-9697 Include ObjC symbols into search everywhere
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.ide.actions;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DefaultSearchEverywhereClassifier implements SearchEverywhereClassifier {
|
||||
@Override
|
||||
public boolean isClass(@Nullable Object o) {
|
||||
return o instanceof PsiElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSymbol(@Nullable Object o) {
|
||||
if (o instanceof PsiElement) {
|
||||
final PsiElement e = (PsiElement)o;
|
||||
return !e.getLanguage().is(Language.findLanguageByID("JAVA")) || !(e.getParent() instanceof PsiFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VirtualFile getVirtualFile(@NotNull Object o) {
|
||||
if (o instanceof PsiElement) {
|
||||
final PsiElement element = (PsiElement)o;
|
||||
final PsiFile file = element.getContainingFile();
|
||||
return file != null ? file.getVirtualFile() : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguagePsiElementExternalizer;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.navigation.PsiElementNavigationItem;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
@@ -1737,12 +1738,14 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
|
||||
myProgressIndicator, new Processor<Object>() {
|
||||
@Override
|
||||
public boolean process(Object o) {
|
||||
if (isSymbol(o)) {
|
||||
final PsiElement element = (PsiElement)o;
|
||||
final PsiFile file = element.getContainingFile();
|
||||
if (!myListModel.contains(o) && !symbols.contains(o) &&
|
||||
//some elements are non-physical like DB columns
|
||||
(file == null || (file.getVirtualFile() != null && (includeLibs || scope.accept(file.getVirtualFile()))))) {
|
||||
if (SearchEverywhereClassifier.EP_Manager.isSymbol(o) && !myListModel.contains(o) && !symbols.contains(o)) {
|
||||
VirtualFile virtualFile = SearchEverywhereClassifier.EP_Manager.getVirtualFile(o);
|
||||
//some elements are non-physical like DB columns
|
||||
if (o instanceof PsiElementNavigationItem) {
|
||||
o = ((PsiElementNavigationItem)o).getTargetElement();
|
||||
}
|
||||
if ((o instanceof PsiElement && ((PsiElement)o).getContainingFile() == null) ||
|
||||
(virtualFile != null && (includeLibs || scope.accept(virtualFile)))) {
|
||||
symbols.add(o);
|
||||
}
|
||||
}
|
||||
@@ -1758,16 +1761,6 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
|
||||
return symbols;
|
||||
}
|
||||
|
||||
protected boolean isSymbol(Object o) {
|
||||
if (o instanceof PsiElement) {
|
||||
final PsiElement e = (PsiElement)o;
|
||||
//todo[kb] need a better way to avoid mixing java classes with symbols. Same to other languages where
|
||||
//todo[kb] symbol provider returns classes. We need kind of suppressor API & EP here.
|
||||
return !e.getLanguage().is(Language.findLanguageByID("JAVA")) || !(e.getParent() instanceof PsiFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private SearchResult getClasses(String pattern, boolean includeLibs, final int max, ChooseByNamePopup chooseByNamePopup) {
|
||||
final SearchResult classes = new SearchResult();
|
||||
if (chooseByNamePopup == null || shouldSkipPattern(pattern)) {
|
||||
@@ -1777,17 +1770,20 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA
|
||||
myProgressIndicator, new Processor<Object>() {
|
||||
@Override
|
||||
public boolean process(Object o) {
|
||||
if (o instanceof PsiElement && !myListModel.contains(o) && !classes.contains(o)) {
|
||||
if (SearchEverywhereClassifier.EP_Manager.isClass(o) && !myListModel.contains(o) && !classes.contains(o)) {
|
||||
if (classes.size() == max) {
|
||||
classes.needMore = true;
|
||||
return false;
|
||||
}
|
||||
classes.add(o);
|
||||
|
||||
if (o instanceof PsiElementNavigationItem) {
|
||||
o = ((PsiElementNavigationItem)o).getTargetElement();
|
||||
}
|
||||
if (o instanceof PsiNamedElement) {
|
||||
final String name = ((PsiNamedElement)o).getName();
|
||||
final PsiFile file = ((PsiNamedElement)o).getContainingFile();
|
||||
if (file != null) {
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
VirtualFile virtualFile = SearchEverywhereClassifier.EP_Manager.getVirtualFile(o);
|
||||
if (virtualFile != null) {
|
||||
if (StringUtil.equals(name, virtualFile.getNameWithoutExtension())) {
|
||||
myAlreadyAddedFiles.add(virtualFile);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.ide.actions;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Philipp Smorygo
|
||||
*/
|
||||
public interface SearchEverywhereClassifier {
|
||||
class EP_Manager {
|
||||
private EP_Manager() {}
|
||||
|
||||
public static boolean isClass(@Nullable Object o) {
|
||||
for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) {
|
||||
if (classifier.isClass(o)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSymbol(@Nullable Object o) {
|
||||
for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) {
|
||||
if (classifier.isSymbol(o)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VirtualFile getVirtualFile(@NotNull Object o) {
|
||||
for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) {
|
||||
VirtualFile virtualFile = classifier.getVirtualFile(o);
|
||||
if (virtualFile != null) return virtualFile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ExtensionPointName<SearchEverywhereClassifier> EP_NAME = ExtensionPointName.create("com.intellij.searchEverywhereClassifier");
|
||||
|
||||
boolean isClass(@Nullable Object o);
|
||||
|
||||
boolean isSymbol(@Nullable Object o);
|
||||
|
||||
@Nullable
|
||||
VirtualFile getVirtualFile(@NotNull Object o);
|
||||
}
|
||||
@@ -843,6 +843,7 @@
|
||||
<extensionPoint name="sdkResolveScopeProvider" interface="com.intellij.psi.SdkResolveScopeProvider"/>
|
||||
|
||||
<extensionPoint name="goto.nonProjectScopeDisabler" beanClass="com.intellij.ide.actions.NonProjectScopeDisablerEP"/>
|
||||
<extensionPoint name="searchEverywhereClassifier" interface="com.intellij.ide.actions.SearchEverywhereClassifier"/>
|
||||
<extensionPoint qualifiedName="com.intellij.equivalenceDescriptorProvider" interface="com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider"/>
|
||||
|
||||
<extensionPoint name="previewPanelProvider" interface="com.intellij.openapi.preview.PreviewPanelProvider" area="IDEA_PROJECT"/>
|
||||
|
||||
@@ -557,6 +557,7 @@
|
||||
<lookup.charFilter implementation="com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceCharFilter" id="fileRef"
|
||||
order="before completion"/>
|
||||
|
||||
<searchEverywhereClassifier implementation="com.intellij.ide.actions.DefaultSearchEverywhereClassifier"/>
|
||||
<gotoFileContributor implementation="com.intellij.ide.util.gotoByName.DefaultFileNavigationContributor"/>
|
||||
<gotoTargetRendererProvider implementation="com.intellij.xml.impl.schema.GotoXmlSchemaTypeRendererProvider"/>
|
||||
<gotoRelatedProvider implementation="com.intellij.ide.actions.RelatedItemLineMarkerGotoAdapter"/>
|
||||
|
||||
Reference in New Issue
Block a user