-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
feat: Validate preferences in lsp console #222
Conversation
Fixes #210 Basic working implementation, but still needs some cleanup and docs |
Codecov ReportAttention: Patch coverage is
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. |
src/main/java/com/redhat/devtools/lsp4ij/console/actions/ApplyLanguageServerSettingsAction.java
Outdated
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableConsoleWidget.java
Show resolved
Hide resolved
@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. |
I'll take a look and re-implement the validation according to that |
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. |
f112d35
to
49ccd6c
Compare
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableConsoleWidget.java
Outdated
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java
Outdated
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java
Show resolved
Hide resolved
c4b2799
to
80a1f95
Compare
@angelozerr Should I continue with the tab validations for the LSP console on this or should that be a new issue? |
Let is do that in an annoter pr. I wanted just to share with you an idea that I had had |
src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableDialog.java
Show resolved
Hide resolved
* A shared interface meant to simplify creating validatable components used in | ||
* NewLanguageServerDialog and LanguageServerView (LSP console) | ||
*/ | ||
public interface ValidatableConsoleWidget { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine by me
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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;
@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. |
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. |
Ok I will take care of that. |
@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. |
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. |
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. |
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 |
Great links, thanks. I need to study more the topic. |
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.