-
Notifications
You must be signed in to change notification settings - Fork 31
Don't re-trigger twice Java validation when a Java file is saved. #500
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,6 @@ | |
| import org.eclipse.lsp4mp.ls.commons.TextDocument; | ||
| import org.eclipse.lsp4mp.ls.commons.ValidatorDelayer; | ||
| import org.eclipse.lsp4mp.ls.commons.client.CommandKind; | ||
| import org.eclipse.lsp4mp.ls.commons.client.ExtendedCompletionCapabilities; | ||
| import org.eclipse.lsp4mp.ls.java.JavaTextDocuments.JavaTextDocument; | ||
| import org.eclipse.lsp4mp.ls.properties.IPropertiesModelProvider; | ||
| import org.eclipse.lsp4mp.model.Node; | ||
|
|
@@ -93,7 +92,8 @@ public class JavaFileTextDocumentService extends AbstractTextDocumentService { | |
| private ValidatorDelayer<JavaTextDocument> validatorDelayer; | ||
|
|
||
| public JavaFileTextDocumentService(MicroProfileLanguageServer microprofileLanguageServer, | ||
| IPropertiesModelProvider propertiesModelProvider, SharedSettings sharedSettings, JavaTextDocuments javaTextDocuments) { | ||
| IPropertiesModelProvider propertiesModelProvider, SharedSettings sharedSettings, | ||
| JavaTextDocuments javaTextDocuments) { | ||
| super(microprofileLanguageServer, sharedSettings); | ||
| this.propertiesModelProvider = propertiesModelProvider; | ||
| this.documents = javaTextDocuments; | ||
|
|
@@ -125,8 +125,17 @@ public void didClose(DidCloseTextDocumentParams params) { | |
|
|
||
| @Override | ||
| public void didSave(DidSaveTextDocumentParams params) { | ||
| // Do nothing.. | ||
|
|
||
| // Since the beginning of the MP LS project, | ||
| // saving a Java file triggers validation for all open Java files, | ||
| // which can negatively impact performance. | ||
| // As there's no comment explaining the reason for this behavior, | ||
| // we are disabling this feature. | ||
|
|
||
| // validate all opened java files which belong to a MicroProfile project | ||
| triggerValidationForAll(null); | ||
| // triggerValidationForAll(null); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this breaks the following behaviour. You have a Java source file that defines configuration properties used in the configuration file. If those are added/removed, it affects some diagnostics : Without this change Screencast.From.2025-05-16.12-36-34.mp4With this change Screencast.From.2025-05-16.12-43-30.mp4The diagnostics will not update when saving the config file, but they do update when continuing to type in the source file, or re-opening it. Are we ok with that ? vscode-java does have a setting that causes this exact behaviour by default (ie. don't update opened document diagnostics when another source file being modified affects it). Mainly for performance gains.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember that I had the similar problem with IJ Quarkus. I am pretty sure that if you save your application.properties a second time, it will work. If it that it is because we load in cache properties (for checking validation on Java file) from the /target/application.properties and not from src/main/resources/application.properties. I think we should load cache from src/main/resources/application.properties. We will loose the computed variable from maven for instance declared in teh properties file, but I have never seen this usecase.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saving a second time will not fix this. Validation isn't triggered. You either need to type, or re-open the file.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's strange it is working for me?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you making changes and then saving or just hitting "Save" on an unchanged file ? Making changes will update the diagnostics but saving doesn't. Where would the validation come from when
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Type a space and szve it twice. I need to investigate more a proper fix.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typing a space in the Java source file even without saving the file will update the diagnostics. Look at the video under "With this change" above! You can see just typing updates the diagnostics so that's fine. What I mean is that saving a file that has no changes doesn't update the diagnostics.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I mean tyep a space and save application.properried and do that twice. It should update java diagnostics correctly, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it does work. Interesting. Update: I mean for the first save, the MP LS responds with no diagnostics, but on the second save it returns the diagnostic(s). I guess it can't save + return the updates diagnostics at the same time ? I guess that's fine for now. @angelozerr all that's left is to address my comment at #500 (review) |
||
|
|
||
| } | ||
|
|
||
| // ------------------------------ Completion ------------------------------ | ||
|
|
@@ -167,8 +176,9 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio | |
| JavaCursorContextResult cursorContext = completionResult.getCursorContext(); | ||
|
|
||
| // calculate the snippet completion items based on the context | ||
| List<CompletionItem> snippetCompletionItems = documents.getSnippetRegistry().getCompletionItems(document, finalizedCompletionOffset, | ||
| canSupportMarkdown, snippetsSupported, (context, model) -> { | ||
| List<CompletionItem> snippetCompletionItems = documents.getSnippetRegistry().getCompletionItems( | ||
| document, finalizedCompletionOffset, canSupportMarkdown, snippetsSupported, | ||
| (context, model) -> { | ||
| if (context != null && context instanceof SnippetContextForJava) { | ||
| return ((SnippetContextForJava) context) | ||
| .isMatch(new JavaSnippetCompletionContext(projectInfo, cursorContext)); | ||
|
|
@@ -339,7 +349,7 @@ private void validate(JavaTextDocument javaTextDocument, boolean delay) { | |
| /** | ||
| * Validate the given opened Java file. | ||
| * | ||
| * @param document the opened Java file. | ||
| * @param document the opened Java file. | ||
| */ | ||
| private void triggerValidationFor(JavaTextDocument document) { | ||
| document.executeIfInMicroProfileProject((projectinfo, cancelChecker) -> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 isn't the full path.
You could compute the path relative to the workspace, in which case I don't think you need
outputFullPath. you can dooutputLocation.isPrefixOf(resourcePath).If you want the absolute path on the filesystem, why not do something like
javaProject.getProject().getLocation().append(outputLocation)which should be the absolute path. I've seen it used in some other places.