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

feat: Validate preferences in lsp console #222

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MituuZ
Copy link
Contributor

@MituuZ MituuZ commented Apr 17, 2024

Set up common validation style for LSP console and new LS dialog for text fields and text areas.

Use similar validation for LSP console and new LS dialog. Prevent saving/creating if validations fail.

@MituuZ
Copy link
Contributor Author

MituuZ commented Apr 17, 2024

Fixes #210

Basic working implementation, but still needs some cleanup and docs

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 63 lines in your changes are missing coverage. Please review.

Project coverage is 18.03%. Comparing base (69e8ef5) to head (80a1f95).

Files Patch % Lines
...vtools/lsp4ij/settings/ui/LanguageServerPanel.java 0.00% 22 Missing ⚠️
...devtools/lsp4ij/settings/ui/CommandLineWidget.java 0.00% 13 Missing ⚠️
.../devtools/lsp4ij/settings/ui/ServerNameWidget.java 0.00% 13 Missing ⚠️
...devtools/lsp4ij/settings/ui/ValidatableDialog.java 0.00% 5 Missing ⚠️
...t/devtools/lsp4ij/settings/LanguageServerView.java 0.00% 4 Missing ⚠️
...s/lsp4ij/settings/ui/ValidatableConsoleWidget.java 0.00% 4 Missing ⚠️
...s/lsp4ij/launching/ui/NewLanguageServerDialog.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #222      +/-   ##
==========================================
- Coverage   18.47%   18.03%   -0.44%     
==========================================
  Files         235      238       +3     
  Lines        8260     8461     +201     
  Branches     1561     1610      +49     
==========================================
  Hits         1526     1526              
- Misses       6451     6652     +201     
  Partials      283      283              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MituuZ MituuZ marked this pull request as ready for review April 19, 2024 03:21
@angelozerr
Copy link
Contributor

@MituuZ it should be nice to see all errors when you open dialog or change a field value.

As New dialog, preferences and LSP console detail uses the same componet LanguageServerPanel, I think you should delegate validation in languageServerPanel.doValidateAll()

I have tried to start quickly the idea https://github.com/redhat-developer/lsp4ij/compare/main...angelozerr:lsp4ij:poc_error?expand=1 so I think we should work just with ValidationInfo and not have an isValid method.

@MituuZ
Copy link
Contributor Author

MituuZ commented Apr 20, 2024

I'll take a look and re-implement the validation according to that

@angelozerr
Copy link
Contributor

I did that quickly so dont hesitate to my code.

It should be very nice to see all errors or when you fix an error (ex server name) it should be nice to see the error in command.

As we use tabs, I wonder if we could se et the tab in red which contains error.

@MituuZ MituuZ marked this pull request as draft April 21, 2024 17:53
@MituuZ MituuZ force-pushed the validate-preferences-in-lsp-console branch from f112d35 to 49ccd6c Compare April 21, 2024 17:54
@MituuZ MituuZ force-pushed the validate-preferences-in-lsp-console branch from c4b2799 to 80a1f95 Compare April 24, 2024 02:58
@MituuZ
Copy link
Contributor Author

MituuZ commented Apr 24, 2024

@angelozerr Should I continue with the tab validations for the LSP console on this or should that be a new issue?

@MituuZ MituuZ marked this pull request as ready for review April 24, 2024 03:02
@angelozerr
Copy link
Contributor

Let is do that in an annoter pr. I wanted just to share with you an idea that I had had

* A shared interface meant to simplify creating validatable components used in
* NewLanguageServerDialog and LanguageServerView (LSP console)
*/
public interface ValidatableConsoleWidget {
Copy link
Contributor

Choose a reason for hiding this comment

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

@fbricon what do you think about the ValidatableConsoleWidget name?

Copy link
Contributor

Choose a reason for hiding this comment

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

fine by me

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @fbricon . I think it should be renamed with ValidatableWidget

* Set a common error border for the widget
* @param jComponent interface implementor (e.g. setErrorBorder(this);)
*/
default void setErrorBorder(JComponent jComponent) {
Copy link
Contributor

@angelozerr angelozerr Apr 24, 2024

Choose a reason for hiding this comment

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

setErrorBorder is more an utility class than an API.

Here some suggestion:

  • remove setErrorBorder method
  • add a new void updateUi(boolean hasError) method which is called after the call of validate (hasError must be computed by comparing the size of validations before/after the cal of validate.
  • add a new method initializeValidator(ValidateDialog) which adds the proper listener (which is done today in the addValidator)

widgetValidations.add(new ValidationInfo(errorMessage, this));
}

if (widgetValidations.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't do that here, move this code in the new updateUi(boolean hasErrors) method

}

private void addValidator(JTextComponent textComponent) {
textComponent.getDocument().addDocumentListener(new DocumentAdapter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't do that here but in the ValidableConsoleWidget impl in the initializeValidator(ValidatableDialog dialog) method

Copy link
Contributor

Choose a reason for hiding this comment

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

I think addValidator should just add in a list CommandLineWidget, ServerNameWidget (list of ValidatableConsoleWidget) and in doValidateAll should just iterate from this list.

private void addValidatableWidget(@Nullable ValidatableConsoleWidget validatableWidget) {
   if (validatableWidget == null) {
      return;
   }
   validatableWidget.initializeValidator(this);
   this.validatableWidgets.add(validatableWidget)
}

@@ -241,4 +256,25 @@ public ComboBox<ErrorReportingKind> getErrorReportingKindCombo() {
return errorReportingKindCombo;
}

public @NotNull List<ValidationInfo> doValidateAll() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should look like this:

List<ValidationInfo> validations = new ArrayList<>();
for(var widget : validatableWidgets) {
    int previousSize = validations.size();
    widget.validate(validations);
    boolean hasErrors = previousSize ! validations.size();
   widget.updateUi(hasErrors);
}
return validations;

@angelozerr
Copy link
Contributor

@MituuZ I did some suggestion to improve API. If you have no time to work on it, let's me know and I will do that.

@MituuZ
Copy link
Contributor Author

MituuZ commented Apr 24, 2024

@angelozerr

I can keep working on this if you'd like, most likely tomorrow morning. Though I do think you have a very clear vision on how this should be finished.

It might easier for you to finish this, and I can continue on #215 , which I started earlier today.

@angelozerr
Copy link
Contributor

It might easier for you to finish this

Ok I will take care of that.

@angelozerr
Copy link
Contributor

@MituuZ I have tried to work on this PR. At first using DialogWrapper is an excellent idea, thanks for that.

The thing which is bad in this PR is that we manage border (because JBTextArea doesn't manage border).. By managing border we loose some features like set a light red color when the JTectField is on error and loose the focus.

In otherwise, we must not manage border. I have tried to manage border only for JBTextArea, it starts working but when teh textarea is on error, the red border hide the cursor when cursor is on left of the textarea.

I need to investigate more this PR.

@MituuZ
Copy link
Contributor Author

MituuZ commented May 1, 2024

Yeah, I feel you.

Didn't want to handle the border manually either, but it seemed like the only way to get both fields working the same way and having the same styling for both. Didn't find what the default error borders are for the JBTextField so we could have copied them either.

@angelozerr
Copy link
Contributor

Here the awfull code that I'm using:

public CommandLineWidget() {
        super(5, 0);
        super.setLineWrap(true);
        super.setWrapStyleWord(true);
        super.setFont(new JBTextField().getFont());
        super.setBorder(new JBTextField().getBorder());
        super.setMargin(new JBTextField().getMargin());
    }

When I will have something which will work, I will push my work.

@MituuZ
Copy link
Contributor Author

MituuZ commented May 1, 2024

Checking this it suggests using red and light-red for highlight colors on validation errors. I believe I did try light red, but if recall correctly it was a different color than what the JBTextField had:

https://jetbrains.design/intellij/principles/validation_errors/#how-it-works-1

@angelozerr
Copy link
Contributor

https://jetbrains.design/intellij/principles/validation_errors/#how-it-works-1

Great links, thanks.

I need to study more the topic.

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.

3 participants