1 package org.simantics.scl.ui.editor.completion;
\r
3 import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
\r
4 import org.eclipse.jface.text.BadLocationException;
\r
5 import org.eclipse.jface.text.DefaultInformationControl;
\r
6 import org.eclipse.jface.text.IDocument;
\r
7 import org.eclipse.jface.text.IInformationControl;
\r
8 import org.eclipse.jface.text.IInformationControlCreator;
\r
9 import org.eclipse.jface.text.IRegion;
\r
10 import org.eclipse.jface.text.ITextHover;
\r
11 import org.eclipse.jface.text.ITextHoverExtension;
\r
12 import org.eclipse.jface.text.ITextHoverExtension2;
\r
13 import org.eclipse.jface.text.ITextViewer;
\r
14 import org.eclipse.jface.text.Region;
\r
15 import org.eclipse.jface.text.source.ISourceViewer;
\r
16 import org.eclipse.swt.widgets.Shell;
\r
18 public class SCLEditorTextHover implements ITextHover, ITextHoverExtension, ITextHoverExtension2 {
\r
20 private SCLTextEditorEnvironment sclTextEditorEnvironment;
\r
22 public SCLEditorTextHover(ISourceViewer sourceViewer, SCLTextEditorEnvironment sclTextEditorEnvironment) {
\r
23 this.sclTextEditorEnvironment = sclTextEditorEnvironment;
\r
27 public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
\r
32 public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
\r
33 return findWord(textViewer.getDocument(), offset);
\r
36 private static IRegion findWord(IDocument document, int offset) {
\r
46 c= document.getChar(pos);
\r
47 if (!Character.isUnicodeIdentifierPart(c))
\r
55 int length= document.getLength();
\r
57 while (pos < length) {
\r
58 c= document.getChar(pos);
\r
59 if (!Character.isUnicodeIdentifierPart(c))
\r
66 } catch (BadLocationException x) {
\r
69 if (start >= -1 && end > -1) {
\r
70 if (start == offset && end == offset)
\r
71 return new Region(offset, 0);
\r
72 else if (start == offset)
\r
73 return new Region(start, end - start);
\r
75 return new Region(start + 1, end - start - 1);
\r
82 public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
\r
85 IDocument document = textViewer.getDocument();
\r
86 String text = document.get(hoverRegion.getOffset(), hoverRegion.getLength());
\r
87 sclTextEditorEnvironment.updateEnvironment(document);
\r
88 info = sclTextEditorEnvironment.getHoverInfo(text);
\r
89 } catch (BadLocationException e) {
\r
96 public IInformationControlCreator getHoverControlCreator() {
\r
97 AbstractReusableInformationControlCreator creator = new AbstractReusableInformationControlCreator() {
\r
100 protected IInformationControl doCreateInformationControl(Shell parent) {
\r
101 return new DefaultInformationControl(parent);
\r