mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Use the offset of the IMatch
This commit is contained in:
parent
241036375c
commit
a88eb122a2
1 changed files with 11 additions and 8 deletions
|
@ -79,15 +79,15 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
if (expression.length() == 0)
|
if (expression.length() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
String source = null;
|
||||||
|
|
||||||
ICElement curr = copy.getElement(expression);
|
ICElement curr = copy.getElement(expression);
|
||||||
if (curr == null) {
|
if (curr == null) {
|
||||||
// Try with the indexer
|
// Try with the indexer
|
||||||
curr = findMatches(expression);
|
source = findMatches(expression);
|
||||||
if (curr == null) {
|
} else {
|
||||||
return null;
|
source= ((ISourceReference) curr).getSource();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String source= ((ISourceReference) curr).getSource();
|
|
||||||
if (source == null || source.trim().length() == 0)
|
if (source == null || source.trim().length() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
return source.substring(i);
|
return source.substring(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICElement findMatches(String name) {
|
private String findMatches(String name) {
|
||||||
IEditorPart editor = getEditor();
|
IEditorPart editor = getEditor();
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
IEditorInput input= editor.getEditorInput();
|
IEditorInput input= editor.getEditorInput();
|
||||||
|
@ -189,8 +189,11 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
IResource resource = matches[0].getResource();
|
IResource resource = matches[0].getResource();
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
ICElement celement = CoreModel.getDefault().create(resource);
|
ICElement celement = CoreModel.getDefault().create(resource);
|
||||||
if (celement instanceof ITranslationUnit) {
|
if (celement instanceof ITranslationUnit) {
|
||||||
return ((ITranslationUnit)celement).getElement(name);
|
ITranslationUnit unit = (ITranslationUnit)celement;
|
||||||
|
int startOffset = matches[0].getStartOffset();
|
||||||
|
int length = matches[0].getEndOffset() - startOffset;
|
||||||
|
return unit.getBuffer().getText(startOffset, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue