Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Hyperlinks in Strings/Comments
Hyperlinks in Strings/Comments [message #558337] Sat, 11 September 2010 10:34 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
I have the need to provide hyperlinks in comments (as an example
recognize a URL in a comment and making it clickable).

Grateful if someone could suggest how to implement something like that.

Regards
- henrik
Re: Hyperlinks in Strings/Comments [message #558342 is a reply to message #558337] Sat, 11 September 2010 11:46 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

there are a couple of threads in the forum dealing with similar problems, an approach is contained in the MWE2 grammar project.

One possibility is changing the grammar, making strings and comments not being single terminals but rather composed elements that can contain elements of type link. You'd still have to adapt the linking though. Also this would make the grammar quite complicated and if you don't want to use the comments or strings otherwise (just allow navigation for the user), this might be an overkill.

My first suggestion would be to implement your own HyperlinkHelper "extending" the createHyperlinkByOffset method. The difficult part will be (if you don't change the grammar for comments) "manually" parsing the comment node, checking whether there actually is a URL under the current cursor position. You can then create your own I/Abstract/XtextHyperlink associating whatever you want with the open-method.

Alex
Re: Hyperlinks in Strings/Comments [message #558607 is a reply to message #558342] Mon, 13 September 2010 16:08 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Thanks,
Splitting up the text into fine grained grammar opens up a very large
can of worms, and I was thinking of finding the links in the data type
conversion. I currently use a String for the documentation data, but
could just as well have a type that contains more information.

Or, is there some other place where it is convenient to introduce
"additional parsing" ? I can imagine computing offsets on demand and
storing in an adapter for instance.

Regards
- henrik

On 9/11/10 1:46 PM, Alexander Nittka wrote:
> Hi,
>
> there are a couple of threads in the forum dealing with similar
> problems, an approach is contained in the MWE2 grammar project.
>
> One possibility is changing the grammar, making strings and comments not
> being single terminals but rather composed elements that can contain
> elements of type link. You'd still have to adapt the linking though.
> Also this would make the grammar quite complicated and if you don't want
> to use the comments or strings otherwise (just allow navigation for the
> user), this might be an overkill.
>
> My first suggestion would be to implement your own HyperlinkHelper
> "extending" the createHyperlinkByOffset method. The difficult part will
> be (if you don't change the grammar for comments) "manually" parsing the
> comment node, checking whether there actually is a URL under the current
> cursor position. You can then create your own I/Abstract/XtextHyperlink
> associating whatever you want with the open-method.
>
> Alex
Re: Hyperlinks in Strings/Comments [message #558655 is a reply to message #558607] Mon, 13 September 2010 20:01 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I fear I am the wrong one to ask for best practice. But my feeling is that if you "evaluate" the links in comments etc. only for user triggered navigation (F3), it may be an overkill to pre-calculate everything during parsing (or value conversion). It will suffice to check whether there is a hyperlink on demand in the said method.

Alex
Re: Hyperlinks in Strings/Comments [message #558662 is a reply to message #558337] Mon, 13 September 2010 20:07 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 9/11/10 12:34 PM, schrieb Henrik Lindberg:
> Hi,
> I have the need to provide hyperlinks in comments (as an example
> recognize a URL in a comment and making it clickable).
>
> Grateful if someone could suggest how to implement something like that.
>
> Regards
> - henrik

You could override the binding in
org.eclipse.xtext.ui.DefaultUiModule.bindIHyperlinkDetector( )

and add an implementation which delegates to
org.eclipse.jface.text.hyperlink.URLHyperlinkDetector
in addition to the default behavior.

Sven



--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Hyperlinks in Strings/Comments [message #558759 is a reply to message #558342] Tue, 14 September 2010 11:08 Go to previous messageGo to next message
Florian Philipp is currently offline Florian PhilippFriend
Messages: 43
Registered: February 2010
Member
Alexander Nittka wrote on Sat, 11 September 2010 07:46
Hi,

The difficult part will be (if you don't change the grammar for comments) "manually" parsing the comment node, checking whether there actually is a URL under the current cursor position. You can then create your own I/Abstract/XtextHyperlink associating whatever you want with the open-method.

Alex


I think the cleanest solution (but probably overkill) would be to introduce a second grammar for parsing the comments. I guess that's how Javadoc etc. gets parsed.

It is pretty easy to call that parser on demand and it allows you to create syntax highlighting (just call it in your AntlrTokenToAttributeIdMapper), content proposal and all sorts of stuff.

Performance could suffer, though.
Re: Hyperlinks in Strings/Comments [message #558775 is a reply to message #558662] Tue, 14 September 2010 11:19 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Sven, hi Henrik,

the URLHyperlinkeDetector is registered as well. The bound detector is
added to the default list of hyperlinke detectors in the
XtextSourceViewerConfiguration.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 13.09.10 22:07, schrieb Sven Efftinge:
> Am 9/11/10 12:34 PM, schrieb Henrik Lindberg:
>> Hi,
>> I have the need to provide hyperlinks in comments (as an example
>> recognize a URL in a comment and making it clickable).
>>
>> Grateful if someone could suggest how to implement something like that.
>>
>> Regards
>> - henrik
>
> You could override the binding in
> org.eclipse.xtext.ui.DefaultUiModule.bindIHyperlinkDetector( )
>
> and add an implementation which delegates to
> org.eclipse.jface.text.hyperlink.URLHyperlinkDetector
> in addition to the default behavior.
>
> Sven
>
>
>
Previous Topic:Narrowing content assist choices
Next Topic:Problem with unordered groups
Goto Forum:
  


Current Time: Thu Sep 26 19:28:31 GMT 2024

Powered by FUDForum. Page generated in 0.04264 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top