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

New Bracket support #1718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Dinesh0723
Copy link
Contributor

Introduced a new Bracket support.

Fixes:#865

Copy link
Contributor

github-actions bot commented Feb 26, 2024

Test Results

0 files   -    918  0 suites   - 918   0s ⏱️ - 49m 28s
0 tests  -  7 452  0 ✅  -  7 298  0 💤  - 151  0 ❌  - 3 
0 runs   - 23 505  0 ✅  - 22 995  0 💤  - 505  0 ❌  - 5 

Results for commit 6dcad12. ± Comparison against base commit 7572bd4.

♻️ This comment has been updated with latest results.

@jukzi jukzi force-pushed the Enhancement/865_Bracket_Support branch from 8c41fb9 to 6dcad12 Compare March 8, 2024 12:53
package org.eclipse.jface.text;

/**
* @since 3.25
Copy link
Contributor

Choose a reason for hiding this comment

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

@Dinesh0723 in principle the code and feature looks good. But i would not add new API for these otherwise unused constants. Please inline them

{ SpecialCharacterConstants.closeParentheses, SpecialCharacterConstants.closeSquareBracket, SpecialCharacterConstants.closeCurlyBracket,
SpecialCharacterConstants.closeAngleBracket, SpecialCharacterConstants.singleQuote, SpecialCharacterConstants.doubleQuotes }
};
boolean containsSpecialBrackets= Arrays.asList(bracketTypes[0]).contains(text);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can store this List as constant "private final static", please. Hint: better useList.of(...)

/**
* @since 3.25
*/
public class SpecialCharacterConstants {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public class SpecialCharacterConstants {
class SpecialCharacterConstants {

should work as well....

@jukzi jukzi added enhancement New feature or request noteworthy Noteworthy feature labels Mar 8, 2024
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.

We don't want to hardcode such feature into JFace, we want JFace to make such feature possible but not to be the host of the edition smartness. And this is usually done by the IAutoEditStrategies registered by the editor on the viewer.
Editors such as the Java one or the Generic Editor already host some smartness regarding finding or inserting matching brackets. We should stay one the same layer instead of hardcoding it into JFace.
Concretely, this feature could be implemented in some IAutoEditStrategy that would be added to the viewer via the SourceViewerConfiguration. JDT already has some CompilationUnitEditor.getPeerCharacter() to reuse; and the other case would be mostly the generic editor, where the "autoEdits" are usually provided by TM4E. So TM4E could be improved to turn "replace foo by (" into replace fooby(foo)`" according to the defined character matching rules.

* ETAS GmbH - initial API and implementation
*******************************************************************************/

package org.eclipse.jface.text;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move it to org.eclipse.jface.text.source package, which already hosts some related feature such as ICharacterPairMatcher.

/**
* @since 3.25
*/
public class SpecialCharacterConstants {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please keep non-API, and better call it "DefaultCharacterPairs" here and host also the pairs in that class.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mickaelistria As per my understanding, a non-API does not include public classes. If we move the class to the org.eclipse.jface.text.source package, it will not be possible to access the constants from DefaultDocumentAdapter.java, which is located in the org.eclipse.jface.text package.

Therefore, Is it better to inline them in DefaultDocumentAdapter.java as
String[][] bracketTypes = {
{ "(", "[", "{", "<", "'", """ },
{ ")", "]", "}", ">", "'", """ }
};

Please correct me if I have misunderstood.

@lathapatil
Copy link
Contributor

lathapatil commented May 10, 2024

Editors such as the Java one or the Generic Editor already host some smartness regarding finding or inserting matching brackets. We should stay one the same layer instead of hardcoding it into JFace.

@mickaelistria I will explore on this further if the approach provided in the PR is not acceptable

@mickaelistria
Copy link
Contributor

@mickaelistria I will explore on this further if the approach provided in the PR is not acceptable

Yes please, I think it would be better.
Also, I would recommend that you start by implementing an automated test that describes the scenario you wish to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request noteworthy Noteworthy feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants