Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code minings drawn more consistently always via drawAsLeftOf1stCharacter #2243

Conversation

tobiasmelcher
Copy link
Contributor

@tobiasmelcher tobiasmelcher commented Sep 5, 2024

this improves the selection behavior for the scenario where the selection end offset contains a LineContentAnnotation. Selection is no longer extended with the code mining.

The selection behavior before this change always included the code mining text which is located at the end selection offset. The following screenshot shows the behavior. By including the last character "o" of "echo" in the selection, the selection is extended with the code mining text next to the "o" character.
code_mining_draw_right_to_the_previous_character

This is no longer the case with this change. The code mining text is no longer added to the selection when "echo" is selected.
code_mining_draw_at_current_character

Is the current behavior of drawing the code mining texts intended? Is this behavior needed for a feature (which I am not aware of)?

Let me try to explain why I request this change.
In the ABAP Development Tools in Eclipse we use the code minings to show inline keyword completions while the user is typing a keyword. If a matching keyword is available, it is shown as code mining and user can take over the text by pressing the tab key. Here a screencast showing the scenario when the user is typing the keyword "definition".

cursor_jumps.mp4

It works quite well. Users don't like the way how the cursor always jumps to the end of the code mining showing the rest of the keyword "definition". The cursor jumps to the end of the code mining because method drawAsRightOfPreviousCharacter is used to render the code mining.

The cursor does not jump to the end of the code mining with this pull request by using method drawAsLeftOf1stCharacter to render the code mining.

cursor_does_not_jump.mp4

The question now is if we would break any existing functionality regarding rendering of code minings by always using method drawAsLeftOf1stCharacter?
An alternative approach would be to provide an API with which the user can decide how to draw the code mining. What would be your preferred solution? Could you please give any guidance?

Thanks a lot,
Tobias

Copy link
Contributor

github-actions bot commented Sep 5, 2024

Test Results

 1 815 files  ±0   1 815 suites  ±0   1h 39m 32s ⏱️ + 5m 21s
 7 702 tests +2   7 461 ✅ +1  228 💤 ±0  2 ❌ +1  11 🔥 ±0 
24 267 runs  +6  23 507 ✅ +5  747 💤 ±0  2 ❌ +1  11 🔥 ±0 

For more details on these failures and errors, see this check.

Results for commit 8c67165. ± Comparison against base commit f9b743f.

♻️ This comment has been updated with latest results.

@BeckerWdf
Copy link
Contributor

"pr-head" says:
Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:4.0.8:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.jface.text: Only qualifier changed for (org.eclipse.jface.text/3.25.200.v20240905-1304). Expected to have bigger x.y.z than what is available in baseline (3.25.200.v20240816-1151)

Pls add a second mitt that increases the version of org.eclipse.jface-text to "3.25.300". This should fix this issue.

@tobiasmelcher tobiasmelcher force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch 3 times, most recently from 371ac78 to 5f67aff Compare September 6, 2024 06:13
@BeckerWdf
Copy link
Contributor

There seems to be an infrastructure issue:

06:14:56.854 [ERROR] Error executing Maven.
06:14:56.855 [ERROR] Extension org.eclipse.tycho:tycho-build:4.0.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.eclipse.tycho:tycho-build:jar:4.0.6
06:14:56.856 [ERROR] Caused by: Failed to read artifact descriptor for org.eclipse.tycho:tycho-build:jar:4.0.6
06:14:56.856 [ERROR] Caused by: Failed to read artifact descriptor for org.eclipse.tycho:tycho-build:jar:4.0.6
06:14:56.856 [ERROR] Caused by: The following artifacts could not be resolved: org.eclipse.tycho:tycho-build:pom:4.0.6 (absent): Could not transfer artifact org.eclipse.tycho:tycho-build:pom:4.0.6 from/to eclipse.maven.central.mirror (https://repo.eclipse.org/content/repositories/maven_central/): status code: 403, reason phrase: Forbidden (403)
06:14:56.856 [ERROR] Caused by: Could not transfer artifact org.eclipse.tycho:tycho-build:pom:4.0.6 from/to eclipse.maven.central.mirror (https://repo.eclipse.org/content/repositories/maven_central/): status code: 403, reason phrase: Forbidden (403)
06:14:56.857 [ERROR] Caused by: status code: 403, reason phrase: Forbidden (403)

@BeckerWdf BeckerWdf force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch from 5f67aff to 28f94ae Compare September 12, 2024 08:05
@BeckerWdf
Copy link
Contributor

@mickaelistria: What are your thoughts on this PR?

@BeckerWdf BeckerWdf force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch from 28f94ae to 8c61750 Compare September 13, 2024 06:31
@BeckerWdf
Copy link
Contributor

org.eclipse.jface.text.tests also needs a version bump:

Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:4.0.8:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.jface.text.tests: Only qualifier changed for (org.eclipse.jface.text.tests/3.13.600.v20240913-0631). Expected to have bigger x.y.z than what is available in baseline (3.13.600.v20240816-1151) -> [Help 1]

Can you pls. ammend your version change commit?

@BeckerWdf
Copy link
Contributor

Some of the code mining tests are failing:

org.eclipse.jface.text.tests.codemining.CodeMiningTest.testCodeMiningOnEmptyLine
org.eclipse.jface.text.tests.codemining.CodeMiningTest.testCodeMiningAtEndOfLine

@tobiasmelcher tobiasmelcher force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch 2 times, most recently from c0f3414 to 0b85447 Compare September 13, 2024 13:48
@BeckerWdf
Copy link
Contributor

org.eclipse.jface.text.tests also needs a version bump:

Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:4.0.8:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.jface.text.tests: Only qualifier changed for (org.eclipse.jface.text.tests/3.13.600.v20240913-0631). Expected to have bigger x.y.z than what is available in baseline (3.13.600.v20240816-1151) -> [Help 1]

Can you pls. ammend your version change commit?

Thanks

@mickaelistria
Copy link
Contributor

I didn't try this PR yet.
But the history here is that the main use-case for inline code minings in the Eclipse SDK are currently method parameter annotation. With those, user want for example System.arraycopy((src: array1, srcPos: |0, dest: array2, destPos: 0, n). If we change it the other way round, then we break this case, the cursor before 0 would be ~80 pixels to the left. Both this legacy use-case and the one you're sharing here seem antagonist. We most likely need some extra flag on codeMinings somewhere to declare whether it's a prefix or a suffix.

@tobiasmelcher
Copy link
Contributor Author

Thanks a lot for the feedback @mickaelistria. I fully agree. I just tested the java method parameter code minings with this change and selection behavior looks ugly.

Without this change, one can select the method parameter value 0 and the code mining text is not included.
java_method_param_before

With this change, this is no longer possible. Selecting 0 always includes the code mining which does not feel right.
java_method_param_after

I will make a proposal with an API enhancement so that the selection behavior of the code minings can be configured. For sure in a compatible way.

@BeckerWdf
Copy link
Contributor

I will make a proposal with an API enhancement so that the selection behavior of the code minings can be configured. For sure in a compatible way.

Yes. That's a good idea.

Copy link
Contributor

@mickaelistria mickaelistria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it, but the code looks already good.
Just a comment inline discussing whether a new CodeMining type is useful here.

* Line content code mining which is drawn right to the given position. Cursor and selection
* handling are not including the code mining.
*/
public abstract class SuffixLineContentCodeMining extends LineContentCodeMining {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather imagine a new flag on LineContentCodeMning than a whole new method here.
IMO, a new constructor LineContentCodeMining(Position, boolean afterPosition /* default being false in other constructors that don't have this arg */, provider) would be simpler to both consume and maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fast reply. I changed the API as requested and added a further constructor in LineContentCodeMining. I have put "boolean afterPosition" as last contructor argument for compatibility reasons. Do you think it is better to place it as second argument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For compatibility, you only need to keep the current constructors. You're free to design your new ones freely.
So yes, I think it's better to place it as 2nd argument if it's not conflicting with any other existing constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I added it as 2nd argument. Is it because first argument is "position" and next argument "afterPosition" is then influencing the position?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the position where the codemining is rendered is a function of those 2 arguments. Grouping them together makes things faster to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, understood. Makes absolutely sense.

@tobiasmelcher tobiasmelcher force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch from fdabddd to fbdbd21 Compare September 30, 2024 11:58
@tobiasmelcher tobiasmelcher force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch from fbdbd21 to 46e6ea3 Compare September 30, 2024 12:56
Copy link
Contributor

@mickaelistria mickaelistria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes about probable complaints from API tools about new API methods.

* @param afterPosition if true code mining is treated as suffix code mining where cursor and
* selection is not including the mining
*/
public LineContentCodeMining(Position position, boolean afterPosition, ICodeMiningProvider provider, Consumer<MouseEvent> action) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is new API, this will likely require some @since 3.26 and a version increase in the MANIFEST.

@@ -158,7 +158,7 @@ StyleRange updateStyle(StyleRange style, FontMetrics fontMetrics, ITextViewer vi
return style;
}

static boolean drawRightToPreviousChar(int widgetOffset, StyledText textWidget) {
protected boolean drawRightToPreviousChar(int widgetOffset, StyledText textWidget) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is new API, this will likely require some @since 3.26 and a version increase in the MANIFEST.
Or better if you can find a way to not make this method API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for the help. I tried to fix the API tools messages with 80b1736. I added an additional argument to package method LineContentAnnotation#updateStyle . Is this allowed? If not, I would need to introduce method "protected boolean drawRightToPreviousChar" as protected instance method.

@tobiasmelcher tobiasmelcher force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch from 46e6ea3 to 80b1736 Compare September 30, 2024 14:34
@mickaelistria
Copy link
Contributor

Is this allowed?

Yes, it is allowed because this method is package visible only (not API then).

*
* @since 3.26
*/
protected boolean afterPosition= false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is a getter, couldn't this one be private final too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully agree, thanks for the feedback.

which allows to render a code mining where the cursor selection does not
include the code mining at the given source position.
@tobiasmelcher tobiasmelcher force-pushed the codeMiningsAlwaysDrawnAsLeftOf1stCharacter branch from 80b1736 to 8c67165 Compare September 30, 2024 15:00
Copy link
Contributor

@mickaelistria mickaelistria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks very good and the use-case is pretty interesting. Let's merge it as soon as CI reports a successful build on Jenkins.

@BeckerWdf
Copy link
Contributor

failed test are unrelated to this PR

@BeckerWdf BeckerWdf added this to the 4.34 M2 milestone Oct 1, 2024
@mickaelistria mickaelistria merged commit 9b21618 into eclipse-platform:master Oct 1, 2024
14 of 17 checks passed
@mickaelistria
Copy link
Contributor

Thank you for this good code and for making the IDE capable of achieving 1 new use-case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants