[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Patch proposal for Bug 43174
|
What's the problem?
In its current state, code assist takes
a long time to pop up completions and they aren't always correct.
Why?
Code assist currently uses a project
scope when performing a search. Thus all files in a project are searched
- which
contributes to the long pop up time
(especially in large projects) and the inaccurate results (as a file rarely
includes all
the other files in the same project).
What's in this patch?
This patch changes the search scope
for code assist from a project scope to a file scope. This improves both
performance and
accuracy of the matches.
Automation Suite run on both Windows
+ Linux.
Thanks,
Bogdan
Index: search/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/ChangeLog,v
retrieving revision 1.37
diff -u -r1.37 ChangeLog
--- search/ChangeLog 1 Oct 2003 21:33:17 -0000 1.37
+++ search/ChangeLog 8 Oct 2003 12:46:30 -0000
@@ -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
Index: search/org/eclipse/cdt/core/search/SearchEngine.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java,v
retrieving revision 1.9
diff -u -r1.9 SearchEngine.java
--- search/org/eclipse/cdt/core/search/SearchEngine.java 22 Sep 2003 18:38:24 -0000 1.9
+++ search/org/eclipse/cdt/core/search/SearchEngine.java 8 Oct 2003 12:46:30 -0000
@@ -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.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 @@
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 @@
pathCollector,
indexManager
),
- ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
+ ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
subMonitor );
subMonitor = (progressMonitor == null ) ? null : new SubProgressMonitor( progressMonitor, 95 );
Index: search/org/eclipse/cdt/internal/core/search/CSearchScope.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java,v
retrieving revision 1.4
diff -u -r1.4 CSearchScope.java
--- search/org/eclipse/cdt/internal/core/search/CSearchScope.java 29 Sep 2003 21:35:10 -0000 1.4
+++ search/org/eclipse/cdt/internal/core/search/CSearchScope.java 8 Oct 2003 12:46:30 -0000
@@ -233,4 +233,19 @@
}
}
}
+
+ /**
+ * @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());
+ }
+
+ }
+
}
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.203
diff -u -r1.203 ChangeLog
--- ChangeLog 1 Oct 2003 21:33:23 -0000 1.203
+++ ChangeLog 8 Oct 2003 12:46:48 -0000
@@ -1,3 +1,11 @@
+2003-10-06 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
Index: src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java,v
retrieving revision 1.15
diff -u -r1.15 CCompletionProcessor.java
--- src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java 26 Sep 2003 15:25:45 -0000 1.15
+++ src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java 8 Oct 2003 12:46:49 -0000
@@ -12,6 +12,7 @@
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.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,8 @@
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.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -486,12 +491,25 @@
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;
+
+ //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
+ ICSearchScope 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 ));