mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
Patch for Devin Steffler: Fix for Bug 102182 ([F3] Open Declaration on macro not working in particular project)
This commit is contained in:
parent
f4b1edba07
commit
c1c91403c4
6 changed files with 297 additions and 321 deletions
|
@ -90,7 +90,6 @@ CSearchResultLabelProvider.potentialMatch= \ (inexact)
|
|||
|
||||
CSearchOperation.operationUnavailable.title= Operation Unavailable
|
||||
CSearchOperation.operationUnavailable.message= The operation is unavailable on the current selection.
|
||||
CSearchOperation.tooManyNames.message= The operation is unavailable on the current selection (too many different names selected).
|
||||
CSearchOperation.noNamesSelected.message= The operation is unavailable on the current selection (no name selected).
|
||||
CSearchOperation.noDefinitionFound.message= No definition was found.
|
||||
CSearchOperation.noDeclarationFound.message= No declaration was found.
|
||||
|
|
|
@ -71,12 +71,14 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
|||
private IASTName searchName=null;
|
||||
private LimitTo limitTo=null;
|
||||
private ICSearchScope scope=null;
|
||||
private String searchPattern=null;
|
||||
|
||||
public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope) {
|
||||
public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope, String searchPattern) {
|
||||
super(CUIPlugin.getWorkspace(), displaySearchPattern, false, null, null, null, displaySearchPattern);
|
||||
this.searchName = name;
|
||||
this.limitTo = limitTo;
|
||||
this.scope = scope;
|
||||
this.searchPattern = searchPattern;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -91,6 +93,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
|||
|
||||
// fix for 43128
|
||||
Set matches=null;
|
||||
IASTName[] foundNames=null;
|
||||
if (!isLocal())
|
||||
matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo);
|
||||
|
||||
|
@ -107,7 +110,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
|||
}
|
||||
}
|
||||
} else { // only search against the DOM if the index failed to get results... i.e. don't want duplicates
|
||||
IASTName[] foundNames = DOMSearchUtil.getNamesFromDOM(searchName, limitTo);
|
||||
foundNames = DOMSearchUtil.getNamesFromDOM(searchName, limitTo);
|
||||
|
||||
for (int i=0; i<foundNames.length; i++) {
|
||||
try {
|
||||
|
@ -138,6 +141,23 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
|||
}
|
||||
}
|
||||
|
||||
if (searchPattern != null && matches.size() == 0 && (foundNames == null || foundNames.length == 0)) {
|
||||
// last try: search the index for the selected string, even if no name was found for that selection
|
||||
matches = DOMSearchUtil.getMatchesFromSearchEngine( scope, searchPattern, limitTo );
|
||||
|
||||
Iterator itr = matches.iterator();
|
||||
while(itr.hasNext()) {
|
||||
Object next = itr.next();
|
||||
if (next instanceof IMatch) {
|
||||
try {
|
||||
collector.acceptMatch((IMatch)next);
|
||||
} catch (CoreException e) {
|
||||
// don't do anything if the match wasn't accepted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mainSearchPM.done();
|
||||
collector.done();
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
|
||||
|
@ -74,14 +73,7 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
* @return
|
||||
*/
|
||||
public CSearchQuery createDOMSearchQueryForName( IASTName name, LimitTo limitTo, ICSearchScope scope, String searchPattern){
|
||||
if (name != null) {
|
||||
return new DOMQuery(DOMSearchUtil.getSearchPattern(name), name, limitTo, scope);
|
||||
} else {
|
||||
if (searchPattern != null)
|
||||
return createSearchQuery(searchPattern, ICSearchConstants.UNKNOWN_SEARCH_FOR);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
return new DOMQuery(DOMSearchUtil.getSearchPattern(name), name, limitTo, scope, searchPattern);
|
||||
}
|
||||
|
||||
|
||||
|
@ -216,9 +208,6 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
} else if (names.size() == 0) { // no names selected
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE);
|
||||
return;
|
||||
} else if (names.size() > 1) { // too many names selected
|
||||
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
foundName = (IASTName)names.get(0);
|
||||
|
|
|
@ -127,6 +127,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
// step 1 starts here
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
|
||||
|
||||
try {
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||
IASTName searchName = selectedNames[0];
|
||||
// step 2 starts here
|
||||
|
@ -162,8 +163,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
storage.setFileName(fileName);
|
||||
storage.setLocatable(new OffsetLocatable(start,end));
|
||||
storage.setResource(ParserUtil.getResourceForFilename( fileName ));
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// step 3 starts here
|
||||
|
@ -183,11 +183,12 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (selectedNames.length == 0){
|
||||
}
|
||||
} catch(Exception e) {} // catch all exceptions from DOM so the indexer can still be tried
|
||||
|
||||
// last try: search the index for the selected string, even if no name was found for that selection
|
||||
ICElement[] scope = new ICElement[1];
|
||||
scope[0] = project;
|
||||
|
@ -209,24 +210,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
operationNotAvailable(CSEARCH_OPERATION_NO_DECLARATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// private String findProjectName(IFile resourceFile) {
|
||||
// if( resourceFile == null ) return ""; //$NON-NLS-1$
|
||||
// IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
// for( int i = 0; i < projects.length; ++i )
|
||||
// {
|
||||
// if( projects[i].contains(resourceFile) )
|
||||
// return projects[i].getName();
|
||||
// }
|
||||
// return ""; //$NON-NLS-1$
|
||||
// }
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
|
@ -35,8 +35,6 @@ import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
|||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
|
@ -135,13 +133,14 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
|||
return;
|
||||
}
|
||||
lang = DOMSearchUtil.getLanguageFromFile(resourceFile);
|
||||
projectName = findProjectName(resourceFile);
|
||||
project = new CProject(null, resourceFile.getProject());
|
||||
}
|
||||
|
||||
// step 1 starts here
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(tu, selectionStart, selectionLength, lang);
|
||||
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||
try {
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) {
|
||||
IASTName searchName = selectedNames[0];
|
||||
// step 2 starts here
|
||||
IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DEFINITIONS);
|
||||
|
@ -164,17 +163,19 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
|||
|
||||
if ( domNames[0].getTranslationUnit() != null ) {
|
||||
IASTFileLocation location = domNames[0].getFileLocation();
|
||||
if (location != null)
|
||||
{
|
||||
fileName = location.getFileName();
|
||||
start = location.getNodeOffset();
|
||||
end = location.getNodeOffset() + location.getNodeLength();
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName != null) {
|
||||
storage.setFileName(fileName);
|
||||
storage.setLocatable(new OffsetLocatable(start,end));
|
||||
storage.setResource(ParserUtil.getResourceForFilename( fileName ));
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// step 3 starts here
|
||||
|
@ -194,11 +195,12 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
|||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (selectedNames.length == 0){
|
||||
}
|
||||
} catch (Exception e) {} // catch all exceptions from DOM so the indexer can still be tried
|
||||
|
||||
// last try: search the index for the selected string, even if no name was found for that selection
|
||||
ICElement[] scope = new ICElement[1];
|
||||
scope[0] = project;
|
||||
|
@ -220,23 +222,6 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
|||
operationNotAvailable(CSEARCH_OPERATION_NO_DEFINITION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private String findProjectName(IFile resourceFile) {
|
||||
if( resourceFile == null ) return ""; //$NON-NLS-1$
|
||||
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
for( int i = 0; i < projects.length; ++i )
|
||||
{
|
||||
if( projects[i].contains(resourceFile) )
|
||||
return projects[i].getName();
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
|
|||
*/
|
||||
public class SelectionParseAction extends Action {
|
||||
private static final String OPERATOR = "operator"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE = "CSearchOperation.tooManyNames.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE = "CSearchOperation.noNamesSelected.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE = "CSearchOperation.operationUnavailable.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_NO_DEFINITION_MESSAGE = "CSearchOperation.noDefinitionFound.message"; //$NON-NLS-1$
|
||||
|
|
Loading…
Add table
Reference in a new issue