mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix for 185221 by Ed Swartz, show errors when navigation fails.
This commit is contained in:
parent
b98e65a84c
commit
c44c95ce01
5 changed files with 77 additions and 13 deletions
|
@ -147,3 +147,7 @@ PDOMSearch.query.defs.label = Find definitions of
|
||||||
PDOMSearch.query.decls.label = Find declarations of
|
PDOMSearch.query.decls.label = Find declarations of
|
||||||
PDOMSearchPatternQuery.PatternQuery_labelPatternInScope={0} {1} in {2}
|
PDOMSearchPatternQuery.PatternQuery_labelPatternInScope={0} {1} in {2}
|
||||||
PDOMSearch.query.pattern.error = Illegal Search String
|
PDOMSearch.query.pattern.error = Illegal Search String
|
||||||
|
SelectionParseAction.FileOpenFailure.format=Could not open file ''{0}'', verify index is up-to-date
|
||||||
|
SelectionParseAction.SelectedTextNotSymbol.message=Selected text cannot be mapped to a symbol name
|
||||||
|
SelectionParseAction.SymbolNotFoundInIndex.format=Could not find symbol ''{0}'' in index
|
||||||
|
SelectionParseAction.IncludeNotFound.format=Could not find include file ''{0}'' on include paths
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchElementQuery;
|
import org.eclipse.cdt.internal.ui.search.PDOMSearchElementQuery;
|
||||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery;
|
import org.eclipse.cdt.internal.ui.search.PDOMSearchTextSelectionQuery;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
@ -57,7 +58,7 @@ public abstract class FindAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchJob == null) {
|
if (searchJob == null) {
|
||||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
showStatusLineMessage(CSearchMessages.getString(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
|
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
|
clearStatusLine();
|
||||||
|
|
||||||
int selectionStart = selNode.getOffset();
|
int selectionStart = selNode.getOffset();
|
||||||
int selectionLength = selNode.getLength();
|
int selectionLength = selNode.getLength();
|
||||||
|
|
||||||
|
@ -80,6 +82,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IASTTranslationUnit ast=
|
IASTTranslationUnit ast=
|
||||||
ASTProvider.getASTProvider().getAST(
|
ASTProvider.getASTProvider().getAST(
|
||||||
|
@ -87,6 +90,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
||||||
|
|
||||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||||
|
boolean found = false;
|
||||||
IASTName searchName = selectedNames[0];
|
IASTName searchName = selectedNames[0];
|
||||||
boolean isDefinition= searchName.isDefinition();
|
boolean isDefinition= searchName.isDefinition();
|
||||||
IBinding binding = searchName.resolveBinding();
|
IBinding binding = searchName.resolveBinding();
|
||||||
|
@ -105,6 +109,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
for (int i = 0; i < declNames.length; i++) {
|
for (int i = 0; i < declNames.length; i++) {
|
||||||
IASTFileLocation fileloc = declNames[i].getFileLocation();
|
IASTFileLocation fileloc = declNames[i].getFileLocation();
|
||||||
if (fileloc != null) {
|
if (fileloc != null) {
|
||||||
|
found = true;
|
||||||
|
|
||||||
final IPath path = new Path(fileloc.getFileName());
|
final IPath path = new Path(fileloc.getFileName());
|
||||||
final int offset = fileloc.getNodeOffset();
|
final int offset = fileloc.getNodeOffset();
|
||||||
final int length = fileloc.getNodeLength();
|
final int length = fileloc.getNodeLength();
|
||||||
|
@ -122,22 +128,29 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found) {
|
||||||
|
reportSymbolLookupFailure(new String(searchName.toCharArray()));
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Check if we're in an include statement
|
// Check if we're in an include statement
|
||||||
IASTPreprocessorStatement[] preprocs = ast.getAllPreprocessorStatements();
|
IASTPreprocessorStatement[] preprocs = ast.getAllPreprocessorStatements();
|
||||||
|
boolean foundInInclude = false;
|
||||||
for (int i = 0; i < preprocs.length; ++i) {
|
for (int i = 0; i < preprocs.length; ++i) {
|
||||||
if (!(preprocs[i] instanceof IASTPreprocessorIncludeStatement))
|
if (!(preprocs[i] instanceof IASTPreprocessorIncludeStatement))
|
||||||
continue;
|
continue;
|
||||||
IASTPreprocessorIncludeStatement incStmt = (IASTPreprocessorIncludeStatement)preprocs[i];
|
IASTPreprocessorIncludeStatement incStmt = (IASTPreprocessorIncludeStatement)preprocs[i];
|
||||||
if (!incStmt.isResolved())
|
|
||||||
continue;
|
|
||||||
IASTFileLocation loc = preprocs[i].getFileLocation();
|
IASTFileLocation loc = preprocs[i].getFileLocation();
|
||||||
if (loc != null
|
if (loc != null
|
||||||
&& loc.getFileName().equals(ast.getFilePath())
|
&& loc.getFileName().equals(ast.getFilePath())
|
||||||
&& loc.getNodeOffset() < selectionStart
|
&& loc.getNodeOffset() < selectionStart
|
||||||
&& loc.getNodeOffset() + loc.getNodeLength() > selectionStart) {
|
&& loc.getNodeOffset() + loc.getNodeLength() > selectionStart) {
|
||||||
// Got it
|
// Got it
|
||||||
String name = incStmt.getPath();
|
foundInInclude = true;
|
||||||
|
String name = null;
|
||||||
|
if (incStmt.isResolved())
|
||||||
|
name = incStmt.getPath();
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
final IPath path = new Path(name);
|
final IPath path = new Path(name);
|
||||||
runInUIThread(new Runnable() {
|
runInUIThread(new Runnable() {
|
||||||
|
@ -149,9 +162,15 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
reportIncludeLookupFailure(new String(incStmt.getName().toCharArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!foundInInclude) {
|
||||||
|
reportSelectionMatchFailure();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -65,6 +65,8 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
|
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
|
clearStatusLine();
|
||||||
|
|
||||||
int selectionStart = selNode.getOffset();
|
int selectionStart = selNode.getOffset();
|
||||||
int selectionLength = selNode.getLength();
|
int selectionLength = selNode.getLength();
|
||||||
|
|
||||||
|
@ -83,6 +85,7 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
||||||
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||||
IASTName searchName = selectedNames[0];
|
IASTName searchName = selectedNames[0];
|
||||||
|
|
||||||
|
@ -91,8 +94,9 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
final IName[] declNames = ast.getDefinitions(binding);
|
final IName[] declNames = ast.getDefinitions(binding);
|
||||||
for (int i = 0; i < declNames.length; i++) {
|
for (int i = 0; i < declNames.length; i++) {
|
||||||
IASTFileLocation fileloc = declNames[i].getFileLocation();
|
IASTFileLocation fileloc = declNames[i].getFileLocation();
|
||||||
// no source location - TODO spit out an error in the status bar
|
|
||||||
if (fileloc != null) {
|
if (fileloc != null) {
|
||||||
|
found = true;
|
||||||
|
|
||||||
final IPath path = new Path(fileloc.getFileName());
|
final IPath path = new Path(fileloc.getFileName());
|
||||||
final int offset = fileloc.getNodeOffset();
|
final int offset = fileloc.getNodeOffset();
|
||||||
final int length = fileloc.getNodeLength();
|
final int length = fileloc.getNodeLength();
|
||||||
|
@ -110,12 +114,18 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found) {
|
||||||
|
reportSymbolLookupFailure(new String(searchName.toCharArray()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reportSelectionMatchFailure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
index.releaseReadLock();
|
index.releaseReadLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getStatus();
|
return e.getStatus();
|
||||||
|
|
|
@ -8,10 +8,13 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corp. - Rational Software - initial implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Ed Swartz (Nokia)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search.actions;
|
package org.eclipse.cdt.internal.ui.search.actions;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
@ -70,7 +73,7 @@ public class SelectionParseAction extends Action {
|
||||||
return fSite;
|
return fSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void operationNotAvailable(final String message) {
|
protected void showStatusLineMessage(final String message) {
|
||||||
// run the code to update the status line on the Display thread
|
// run the code to update the status line on the Display thread
|
||||||
// this way any other thread can invoke operationNotAvailable(String)
|
// this way any other thread can invoke operationNotAvailable(String)
|
||||||
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
|
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
|
||||||
|
@ -86,7 +89,7 @@ public class SelectionParseAction extends Action {
|
||||||
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
|
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
|
||||||
}
|
}
|
||||||
if( statusManager != null )
|
if( statusManager != null )
|
||||||
statusManager.setErrorMessage(CSearchMessages.getString(message));
|
statusManager.setErrorMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -226,10 +229,13 @@ public class SelectionParseAction extends Action {
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
protected void open(IName name) throws CoreException {
|
protected void open(IName name) throws CoreException {
|
||||||
|
clearStatusLine();
|
||||||
|
|
||||||
IASTFileLocation fileloc = name.getFileLocation();
|
IASTFileLocation fileloc = name.getFileLocation();
|
||||||
if (fileloc == null)
|
if (fileloc == null) {
|
||||||
// no source location - TODO spit out an error in the status bar
|
reportSymbolLookupFailure(new String(name.toCharArray()));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IPath path = new Path(fileloc.getFileName());
|
IPath path = new Path(fileloc.getFileName());
|
||||||
int currentOffset = fileloc.getNodeOffset();
|
int currentOffset = fileloc.getNodeOffset();
|
||||||
|
@ -239,12 +245,14 @@ public class SelectionParseAction extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void open(IPath path, int currentOffset, int currentLength) throws CoreException {
|
protected void open(IPath path, int currentOffset, int currentLength) throws CoreException {
|
||||||
|
clearStatusLine();
|
||||||
|
|
||||||
IEditorPart editor = EditorUtility.openInEditor(path, fEditor.getInputCElement());
|
IEditorPart editor = EditorUtility.openInEditor(path, fEditor.getInputCElement());
|
||||||
if (editor instanceof ITextEditor) {
|
if (editor instanceof ITextEditor) {
|
||||||
ITextEditor textEditor = (ITextEditor)editor;
|
ITextEditor textEditor = (ITextEditor)editor;
|
||||||
textEditor.selectAndReveal(currentOffset, currentLength);
|
textEditor.selectAndReveal(currentOffset, currentLength);
|
||||||
} else {
|
} else {
|
||||||
// TODO: report error
|
reportSourceFileOpenFailure(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,4 +260,26 @@ public class SelectionParseAction extends Action {
|
||||||
setEnabled(getSelectedStringFromEditor() != null);
|
setEnabled(getSelectedStringFromEditor() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void reportSourceFileOpenFailure(IPath path) {
|
||||||
|
showStatusLineMessage(MessageFormat.format(
|
||||||
|
CSearchMessages.getString("SelectionParseAction.FileOpenFailure.format"), //$NON-NLS-1$
|
||||||
|
new String[] { path.toOSString() }));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void reportSelectionMatchFailure() {
|
||||||
|
showStatusLineMessage(CSearchMessages.getString("SelectionParseAction.SelectedTextNotSymbol.message")); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void reportSymbolLookupFailure(String symbol) {
|
||||||
|
showStatusLineMessage(MessageFormat.format(
|
||||||
|
CSearchMessages.getString("SelectionParseAction.SymbolNotFoundInIndex.format"), //$NON-NLS-1$
|
||||||
|
new String[] { symbol }));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void reportIncludeLookupFailure(String filename) {
|
||||||
|
showStatusLineMessage(MessageFormat.format(
|
||||||
|
CSearchMessages.getString("SelectionParseAction.IncludeNotFound.format"), //$NON-NLS-1$
|
||||||
|
new String[] { filename }));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue