Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core/search/ChangeLog4
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java42
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java15
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ContentAssistPreference.java8
7 files changed, 115 insertions, 9 deletions
diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog
index 162118f66b..cd3ad83569 100644
--- a/core/org.eclipse.cdt.core/search/ChangeLog
+++ b/core/org.eclipse.cdt.core/search/ChangeLog
@@ -1,3 +1,7 @@
+2003-10-06 Bogdan Gheorghe
+ - added createCFileSearchScope() to SearchEngine.java to improve
+ code complete performance
+
2003-10-01 Andrew Niefer
- fix bug 44026 by checking scope before reporting match in MatchLocator.report
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java
index cb4606817d..17852d4a56 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java
@@ -13,8 +13,11 @@
*/
package org.eclipse.cdt.core.search;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.Util;
@@ -27,9 +30,12 @@ import org.eclipse.cdt.internal.core.search.PatternSearchJob;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
/**
@@ -95,6 +101,40 @@ public class SearchEngine implements ICSearchConstants{
return scope;
}
+ /**
+ * @param objects
+ * @return
+ */
+ public static ICSearchScope createCFileSearchScope(IFile sourceFile, ArrayList elements) {
+ CSearchScope scope = new CSearchScope();
+ HashSet visitedProjects = new HashSet(2);
+
+ if (sourceFile != null){
+ //Add the source file and project
+ scope.addFile(sourceFile.getFullPath(), sourceFile.getProject());
+ IPath rootPath = CCorePlugin.getWorkspace().getRoot().getLocation();
+ int segCount = CCorePlugin.getWorkspace().getRoot().getLocation().segmentCount();
+ if (elements!=null){
+ Iterator i = elements.iterator();
+ while (i.hasNext()){
+ IPath tempPath = new Path((String) i.next());
+ if (rootPath.isPrefixOf(tempPath)){
+ //path is in workspace
+ IFile tempFile = CCorePlugin.getWorkspace().getRoot().getFile(tempPath);
+ IPath finalPath = tempFile.getFullPath().removeFirstSegments(segCount);
+ tempFile = CCorePlugin.getWorkspace().getRoot().getFile(finalPath);
+ scope.addFile(tempFile.getFullPath(), tempFile.getProject());
+ }
+ else{
+ scope.addFile(tempPath,null);
+ }
+
+ }
+ }
+ }
+ return scope;
+ }
+
public static ICSearchPattern createSearchPattern( String stringPattern, SearchFor searchFor, LimitTo limitTo, boolean isCaseSensitive){
int mode;
@@ -147,7 +187,7 @@ public class SearchEngine implements ICSearchConstants{
pathCollector,
indexManager
),
- ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
+ ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
subMonitor );
subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 95 );
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java
index f4a47b3923..5142b55652 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java
@@ -233,4 +233,19 @@ public class CSearchScope implements ICSearchScope {
}
}
}
+
+ /**
+ * @param finalPath
+ */
+ public void addFile(IPath filePath, IProject fileProject) {
+ //Add the file
+ this.add(filePath, true);
+ //Add the files' containing project - unless it's an external file
+ //in which case this is null
+ if (fileProject != null){
+ this.addEnclosingProject(fileProject.getFullPath());
+ }
+
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 3fc6d6b8be..62dcdad08c 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,10 @@
+2003-10-08 Bogdan Gheorghe
+
+ - Modified CCompletionProcessor.java to create a file scope
+ instead of a project scope
+
+ * src/org/eclipse/cdt/internal/ui/txt/CCompletionProcessor.java
+
2003-10-01 Andrew Niefer
-bug44032 - deleting/moving files breaks search
* modified src/org/eclipse/cdt/ui/CSearchResultLabelProvider getText to return empty string instead of null
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
index 7ba7def728..2e2644ab26 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
@@ -251,6 +251,7 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
overlayKeys.add(
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.CASE_SENSITIVITY));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ADD_INCLUDE));
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.PROJECT_SCOPE_SEARCH));
//new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PROPOSALS_FOREGROUND),
//new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PARAMETERS_BACKGROUND),
//new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PARAMETERS_FOREGROUND),
@@ -346,6 +347,7 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
store.setDefault(ContentAssistPreference.CASE_SENSITIVITY, false);
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
store.setDefault(ContentAssistPreference.ADD_INCLUDE, true);
+ store.setDefault(ContentAssistPreference.PROJECT_SCOPE_SEARCH, false);
}
@@ -887,10 +889,13 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
GridLayout layout = new GridLayout();
layout.numColumns = 2;
contentAssistComposite.setLayout(layout);
+
+ String label= "&Search entire project for completion proposals";
+ addCheckBox(contentAssistComposite, label, ContentAssistPreference.PROJECT_SCOPE_SEARCH, 0);
- String label = "Insert single &proposals automatically";
+ label = "Insert single &proposals automatically";
addCheckBox(contentAssistComposite, label, ContentAssistPreference.AUTOINSERT, 0);
-
+
//label= "Show only proposals visible in the invocation conte&xt";
//addCheckBox(contentAssistComposite, label, ContentAssistPreference.SHOW_VISIBLE_PROPOSALS, 0);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
index 9f10d2d99b..145c2d90b4 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
@@ -12,6 +12,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IMember;
@@ -26,7 +27,9 @@ import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CElement;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.OrPattern;
+import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob;
import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
@@ -39,6 +42,9 @@ import org.eclipse.cdt.ui.FunctionPrototypeSummary;
import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -486,12 +492,37 @@ public class CCompletionProcessor implements IContentAssistProcessor {
String prefix = frag + "*";
// TODO: change that to resource scope later
- ICElement[] projectScopeElement = new ICElement[1];
- projectScopeElement[0] = (ICElement)currentScope.getCProject();
- ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
+ if (currentScope == null)
+ return;
+
+ IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
+ boolean projectScope = store.getBoolean(ContentAssistPreference.PROJECT_SCOPE_SEARCH);
+ ICSearchScope scope = null;
+
+ if (projectScope){
+ ICElement[] projectScopeElement = new ICElement[1];
+ projectScopeElement[0] = (ICElement)currentScope.getCProject();
+ scope = SearchEngine.createCSearchScope(projectScopeElement, true);
+ }
+ else{
+ //Try to get the file
+ IResource actualFile = currentScope.getUnderlyingResource();
+ IProject project = currentScope.getCProject().getProject();
+ ArrayList dependencies = new ArrayList();
+ if (actualFile != null){
+ //Get file's dependencies
+ try {
+ IndexManager indexMan = CCorePlugin.getDefault().getCoreModel().getIndexManager();
+ indexMan.performConcurrentJob(new DependencyQueryJob(project, (IFile)actualFile, indexMan, dependencies), ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ } catch (Exception e) {
+ }
+ }
+ //Create CFileSearchScope
+ scope = SearchEngine.createCFileSearchScope((IFile) actualFile, dependencies);
+ }
+
OrPattern orPattern = new OrPattern();
// search for global variables, functions, classes, structs, unions, enums and macros
-
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ContentAssistPreference.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ContentAssistPreference.java
index 0efe572ef4..21413ab768 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ContentAssistPreference.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/ContentAssistPreference.java
@@ -46,7 +46,9 @@ public class ContentAssistPreference {
public final static String CASE_SENSITIVITY= "content_assist_case_sensitivity";
/** Preference key for adding imports on code assist */
public final static String ADD_INCLUDE= "content_assist_add_import";
-
+ /** Preference key for completion search scope */
+ public final static String PROJECT_SCOPE_SEARCH= "content_assist_project_scope_search";
+
private static Color getColor(IPreferenceStore store, String key, IColorManager manager) {
RGB rgb= PreferenceConverter.getColor(store, key);
return manager.getColor(rgb);
@@ -118,6 +120,8 @@ public class ContentAssistPreference {
enabled= store.getBoolean(AUTOINSERT);
assistant.enableAutoInsert(enabled);
+ enabled= store.getBoolean(PROJECT_SCOPE_SEARCH);
+
configureCProcessor(assistant, store);
}
@@ -177,7 +181,7 @@ public class ContentAssistPreference {
} else if (AUTOINSERT.equals(p)) {
boolean enabled= store.getBoolean(AUTOINSERT);
assistant.enableAutoInsert(enabled);
- }
+ }
changeCProcessor(assistant, store, p);
}

Back to the top