mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-08 01:25:23 +02:00
Patch for Bogdan Gheorghe:
- Add in option (which is turned on by default) to limit the scope of the code assist search to the file and it's inclusions as opposed to the entire project.
This commit is contained in:
parent
20320968f2
commit
b648b93070
7 changed files with 115 additions and 9 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2003-10-06 Bogdan Gheorghe
|
||||||
|
- added createCFileSearchScope() to SearchEngine.java to improve
|
||||||
|
code complete performance
|
||||||
|
|
||||||
2003-10-01 Andrew Niefer
|
2003-10-01 Andrew Niefer
|
||||||
- fix bug 44026 by checking scope before reporting match in MatchLocator.report
|
- fix bug 44026 by checking scope before reporting match in MatchLocator.report
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core.search;
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
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.indexing.IndexManager;
|
||||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||||
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
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.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,6 +101,40 @@ public class SearchEngine implements ICSearchConstants{
|
||||||
return scope;
|
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){
|
public static ICSearchPattern createSearchPattern( String stringPattern, SearchFor searchFor, LimitTo limitTo, boolean isCaseSensitive){
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
2003-10-01 Andrew Niefer
|
||||||
-bug44032 - deleting/moving files breaks search
|
-bug44032 - deleting/moving files breaks search
|
||||||
* modified src/org/eclipse/cdt/ui/CSearchResultLabelProvider getText to return empty string instead of null
|
* modified src/org/eclipse/cdt/ui/CSearchResultLabelProvider getText to return empty string instead of null
|
||||||
|
|
|
@ -251,6 +251,7 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
|
||||||
overlayKeys.add(
|
overlayKeys.add(
|
||||||
new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.CASE_SENSITIVITY));
|
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.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.PROPOSALS_FOREGROUND),
|
||||||
//new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PARAMETERS_BACKGROUND),
|
//new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PARAMETERS_BACKGROUND),
|
||||||
//new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PARAMETERS_FOREGROUND),
|
//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.CASE_SENSITIVITY, false);
|
||||||
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
|
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
|
||||||
store.setDefault(ContentAssistPreference.ADD_INCLUDE, true);
|
store.setDefault(ContentAssistPreference.ADD_INCLUDE, true);
|
||||||
|
store.setDefault(ContentAssistPreference.PROJECT_SCOPE_SEARCH, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,7 +890,10 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
|
||||||
layout.numColumns = 2;
|
layout.numColumns = 2;
|
||||||
contentAssistComposite.setLayout(layout);
|
contentAssistComposite.setLayout(layout);
|
||||||
|
|
||||||
String label = "Insert single &proposals automatically";
|
String label= "&Search entire project for completion proposals";
|
||||||
|
addCheckBox(contentAssistComposite, label, ContentAssistPreference.PROJECT_SCOPE_SEARCH, 0);
|
||||||
|
|
||||||
|
label = "Insert single &proposals automatically";
|
||||||
addCheckBox(contentAssistComposite, label, ContentAssistPreference.AUTOINSERT, 0);
|
addCheckBox(contentAssistComposite, label, ContentAssistPreference.AUTOINSERT, 0);
|
||||||
|
|
||||||
//label= "Show only proposals visible in the invocation conte&xt";
|
//label= "Show only proposals visible in the invocation conte&xt";
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IMember;
|
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.ICSearchScope;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.core.model.CElement;
|
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.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.ContextType;
|
||||||
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
|
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
|
||||||
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
|
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.IFunctionSummary;
|
||||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||||
import org.eclipse.core.resources.IFile;
|
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.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
|
@ -486,12 +492,37 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
String prefix = frag + "*";
|
String prefix = frag + "*";
|
||||||
|
|
||||||
// TODO: change that to resource scope later
|
// TODO: change that to resource scope later
|
||||||
|
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];
|
ICElement[] projectScopeElement = new ICElement[1];
|
||||||
projectScopeElement[0] = (ICElement)currentScope.getCProject();
|
projectScopeElement[0] = (ICElement)currentScope.getCProject();
|
||||||
ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
|
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();
|
OrPattern orPattern = new OrPattern();
|
||||||
// search for global variables, functions, classes, structs, unions, enums and macros
|
// 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.VAR, ICSearchConstants.DECLARATIONS, false ));
|
||||||
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
|
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
|
||||||
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
|
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
|
||||||
|
|
|
@ -46,6 +46,8 @@ public class ContentAssistPreference {
|
||||||
public final static String CASE_SENSITIVITY= "content_assist_case_sensitivity";
|
public final static String CASE_SENSITIVITY= "content_assist_case_sensitivity";
|
||||||
/** Preference key for adding imports on code assist */
|
/** Preference key for adding imports on code assist */
|
||||||
public final static String ADD_INCLUDE= "content_assist_add_import";
|
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) {
|
private static Color getColor(IPreferenceStore store, String key, IColorManager manager) {
|
||||||
RGB rgb= PreferenceConverter.getColor(store, key);
|
RGB rgb= PreferenceConverter.getColor(store, key);
|
||||||
|
@ -118,6 +120,8 @@ public class ContentAssistPreference {
|
||||||
enabled= store.getBoolean(AUTOINSERT);
|
enabled= store.getBoolean(AUTOINSERT);
|
||||||
assistant.enableAutoInsert(enabled);
|
assistant.enableAutoInsert(enabled);
|
||||||
|
|
||||||
|
enabled= store.getBoolean(PROJECT_SCOPE_SEARCH);
|
||||||
|
|
||||||
configureCProcessor(assistant, store);
|
configureCProcessor(assistant, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue