Skip to content

Conversation

@soul2zimate
Copy link
Collaborator

@soul2zimate soul2zimate commented Jul 10, 2025

This is an alternative fix for TC-1631.

Background: previous fix made in #161 reading PSI file cached document content from memory and copy it to temp folder for analysis to avoid inconsistent file content between memory and disk while user applies the quickfix and the analysis happens before changes is saved to disk.

However, it causes trouble when we implements some recent features:

e.g.

  • maven wrapper support, it's hard to identify maven wrapper files location as they're not copied to temp folder.
  • various JS package managers depends on lock files type, which are also missed in the temp folder.

Therefore, this is another proposed alternative that allows analysis waits maximum 5 seconds until the memory and disk are synchronized( 5 seconds is long enough as IntelliJ files are auto-saved after content change).

Therefore, this is another proposed alternative that explicitly synchronize PSI file cached document content and disk file content to avoid analysis happens before changes is saved to disk.

@soul2zimate soul2zimate requested a review from ruromero July 10, 2025 12:38
Copy link
Collaborator

@ruromero ruromero left a comment

Choose a reason for hiding this comment

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

The solution seems reasonable but I am worried about locking the threads. Please review my comments and let me know if you already considered the IntelliJ threading model
Also maybe it's better to check every 500ms instead of 200ms

private static void waitUntilMemoryAndDiskContentSynchronized(PsiFile file, String filePath) {
Document document = PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file);
if (document == null) {
LOG.warn("Document is not cached for file: " + file.getName());
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this need to be a warning or can be debug?


Path path = Path.of(filePath);
long timeoutMillis = 5000;
long intervalMillis = 200;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if looping every 200ms and blocking the current thread is a good idea. I'm afraid this could affect other extensions or the IDE itself.
Can you take a look at the Threading model docs?

…and disk file content to avoid analysis happens before changes is saved to disk.

Signed-off-by: Chao Wang <[email protected]>
@soul2zimate soul2zimate force-pushed the TC-1631_alternative_main branch from 46272e1 to d6956a7 Compare July 14, 2025 02:48
@sonarqubecloud
Copy link

@soul2zimate
Copy link
Collaborator Author

@ruromero I read some docs and realized that it should be able to explicitly save the document content from memory to disk. I updated the fix with this much simpler approach. Please review again. Thanks.l

Copy link
Collaborator

@ruromero ruromero left a comment

Choose a reason for hiding this comment

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

LGTM

@soul2zimate soul2zimate changed the title fix: TC-1631 alternative fix Wait until memory and disk content synchronized fix: TC-1631 Explicitly synchronize PSI file cached document content and disk file content to avoid analysis happens before changes is saved to disk. Jul 14, 2025
@soul2zimate soul2zimate merged commit ca87829 into redhat-developer:main Jul 14, 2025
10 checks passed
@soul2zimate soul2zimate deleted the TC-1631_alternative_main branch July 14, 2025 23:39
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.

2 participants