Commit 2117ee20 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Fixed marker hovering in ttcn3 editor


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 0923cb20
......@@ -62,7 +62,7 @@ public class PeekSource {
try {
RandomAccessFile f2 = new RandomAccessFile(fileToLoad.getLocation().toString(), "r");
final int size = codeLoc.getEndOffset() - codeLoc.getOffset();
byte[] buffer = new byte[size + 1];
byte[] buffer = new byte[size];
f2.seek(codeLoc.getOffset());
f2.read(buffer, 0, size);
codeText = new String(buffer);
......
......@@ -120,18 +120,18 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
if (input instanceof Ttcn3HoverContent) {
content = (Ttcn3HoverContent)input;
if (content.hasText(actualType)) {
viewer.setText(content.getText(actualType));
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
}
setHoverContentToActual();
}
}
}
private void setHoverContentToActual() {
viewer.setText(content.getText(actualType));
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
final String text = content.getText(actualType);
if (text != null) {
viewer.setText(text);
for (StyleRange style : content.getRanges(actualType)) {
viewer.setStyleRange(style);
}
}
}
}
......@@ -7,6 +7,9 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.ttcn3editor;
import java.util.Iterator;
import org.eclipse.core.internal.resources.MarkerInfo;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
......@@ -15,8 +18,11 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.Reference;
......@@ -25,6 +31,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.IHoverContent;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
......@@ -34,6 +41,7 @@ import org.eclipse.titan.designer.parsers.ProjectSourceParser;
import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReferenceAnalyzer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.MarkerAnnotation;
/**
* @author Kristof Szabados
......@@ -92,6 +100,35 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
} else {
return "";
}
final IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
if (annotationModel != null) {
final Iterator<?> iterator = annotationModel.getAnnotationIterator();
Ttcn3HoverContent markerInfo = null;
while (iterator.hasNext()) {
final Object o = iterator.next();
if (o instanceof MarkerAnnotation) {
final MarkerAnnotation actualMarker = (MarkerAnnotation) o;
final Position markerPosition = annotationModel.getPosition(actualMarker);
if (markerPosition.getOffset() <= hoverRegion.getOffset()
&& markerPosition.getOffset() + markerPosition.getLength() >= hoverRegion.getOffset()) {
String message = actualMarker.getText();
if (message == null) {
ErrorReporter.INTERNAL_ERROR("The marker at " + markerPosition.getOffset() + " does not seem to have any text");
}
if (markerInfo == null) {
markerInfo = new Ttcn3HoverContent();
}
markerInfo.addText(message);
}
}
if (markerInfo != null) {
markerInfo.addContent(HoverContentType.INFO);
return markerInfo;
}
}
}
if (ref != null) {
Assignment assignment = scope.getAssBySRef(timestamp, ref);
Ttcn3HoverContent info = null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment