Bug 552331 - [13] Use semantic highlighting to mark the relevant region of a TextBlock
Summary: [13] Use semantic highlighting to mark the relevant region of a TextBlock
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.13   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Kalyan Prasad Tatavarthi CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 574042 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-10-22 14:18 EDT by Stephan Herrmann CLA
Modified: 2023-10-17 05:02 EDT (History)
8 users (show)

See Also:


Attachments
Screenshot from Xtend (38.18 KB, image/png)
2019-10-25 07:45 EDT, Sebastian Zarnekow CLA
no flags Details
Template string with empedded control structure (16.62 KB, image/png)
2019-10-25 07:48 EDT, Sebastian Zarnekow CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2019-10-22 14:18:35 EDT
Java TextBlocks apply non-trivial rules to determine which white space in the editor is part of that String.

It would be cool if the region determined by this algorithm be marked with a different background color.
Comment 1 Stephan Herrmann CLA 2019-10-22 14:20:30 EDT
Cc'ing Sebastian, who may have some hints from a corresponding implementation in the Xtend editor.
Comment 2 Noopur Gupta CLA 2019-10-23 20:07:18 EDT
Stephan/Sebastian, could you please attach a screenshot of the Xtend editor for reference?
Comment 3 Sebastian Zarnekow CLA 2019-10-25 07:45:49 EDT
Created attachment 280419 [details]
Screenshot from Xtend

Please find the screenshot of the Xtend highlighting attached.

With the default configuration, we do not highlight whitespace, that does not have any semantics. Relevant whitespace has a grey background.
Comment 4 Sebastian Zarnekow CLA 2019-10-25 07:48:26 EDT
Created attachment 280420 [details]
Template string with empedded control structure

The second screenshot shows the highlighting when it comes to more interesting templates, e.g. with embedded conditions where a user wants to have a proper nesting the template as well as the output.
Comment 5 Stephan Herrmann CLA 2019-10-25 08:13:42 EDT
(In reply to Sebastian Zarnekow from comment #4)
> Created attachment 280420 [details]
> Template string with empedded control structure
> 
> The second screenshot shows the highlighting when it comes to more
> interesting templates, e.g. with embedded conditions where a user wants to
> have a proper nesting the template as well as the output.

... which is great for Xtend, but does not apply to Java TextBlocks :)
Comment 6 Sebastian Zarnekow CLA 2019-10-25 09:42:48 EDT
(In reply to Stephan Herrmann from comment #5)
> (In reply to Sebastian Zarnekow from comment #4)
> > Created attachment 280420 [details]
> > Template string with empedded control structure
> > 
> > The second screenshot shows the highlighting when it comes to more
> > interesting templates, e.g. with embedded conditions where a user wants to
> > have a proper nesting the template as well as the output.
> 
> ... which is great for Xtend, but does not apply to Java TextBlocks :)

At leat not yet ;)
I posted this one to illustrate the benefit of highlighting the active whitespace rather than the dropped prefix. Could be implemented vice versa for Java.
Comment 7 Stephan Herrmann CLA 2019-10-26 17:32:10 EDT
I had a quick look at what JDT/Core already offers in this regard.

The internal Scanner has a method getCurrentTextBlock() which could easily be mirrored to PublicScanner, if that is useful for this RFE.

Alternatively, I wonder if DOM's TextBlock.resolveConstantExpressionValue() is already sufficient for this task, which return the relevant string.

This would still need to be matched against the document to find start and end position of the relevant part of each line.

References:
https://docs.oracle.com/javase/specs/jls/se13/preview/text-blocks.html
https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/String.html#stripIndent()

In addition to identifying "incidental whitespace", finding the relevant region may also require to map between escaped and unescaped versions of the string.

In the worst case clients might need new API to explicitly query start and end positions for each line of the Text Block, s.t. like
   int[] getStartPositionsOfRelevantText()
   int[] getLengthsOfRelevantText()

I don't think JDT/Core has this information as of yet, but perhaps during scanning this information is easier to obtain than after the fact.
Comment 8 Noopur Gupta CLA 2019-11-12 03:25:05 EST
Targeting for 4.15.
Comment 9 Andrey Loskutov CLA 2021-06-15 15:14:22 EDT
*** Bug 574042 has been marked as a duplicate of this bug. ***