-
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
fix: process element usages under ReadAction #714
fix: process element usages under ReadAction #714
Conversation
@SCWells72 please review the PR. As @jansorg have again a problem, I created this PR which process element usages in a ReadAction. The process element usages is not done whene there are a Dumb (to improve performance). |
@jansorg if you want to test the PR now, please read |
@jansorg, I'm curious about the difference between your IDE environment and ours. I've tried to reproduce these read exceptions on multiple versions of the IDE, multiple IDEs, and multiple OSes. I wouldn't expect the threading model to be different across OSes or IDEs at the same version, but as we all know all too well, it can change across versions. Unfortunately without being able to reproduce these locally at all, it makes it difficult to know when it's properly resolved short of enclosing everything in a read action which has its own issues. Can you please describe the host OS, IDE product name and version, any additional/non-standard JVM args you're using (i.e., are you running it in dev mode which can be more strict about the threading model?), and what exact steps you're taking when these issues happen? |
@SCWells72 I'm on Linux, IntelliJ Ultimate 2024.3.1, using Kotlin in K2 mode (happens without K2 too, I think) The only possible cause I can think of is The exception happens when I invoke a normal "find usages" popup via keyboard. It's really nothing out of the ordinary.
|
Okay. All of my dev IDE instances are also run with that flag, but I'll confirm that again as well.
To be clear as there are multiple "find usages" actions and I've seen behavioral differences between them in the past, is this happening with the one that shows the results in a tool window (Find Usages / Alt+Shift+7), the one that shows results in a pop-up menu (Show Usages / Ctrl+Alt+7), or both? |
@SCWells72 you have more skills than me about IJ, but the thing that I have seen in IJ community base code is that it opens one read action and do some work instead of opening several on some each code part. It is very hard to know xhich code call can throw ReadAction exception. I understand that your last fix was to open ReadAction for some line code to avoid some block, but this code is very hard to maintain. I think opening one readaction should be enough. |
@angelozerr, yeah, I'm fine with that. My concern is that @jansorg is seeing issues that we're not. The most recent one he's seeing has nothing to do with the external references support that I added. It's occurring in the first line of that method when getting the element's containing file. That should happen consistently, or it shouldn't happen consistently. I don't like that he's seeing it and we're not. That inconsistency makes finding these types of threading issues during dev/test very difficult, and we definitely don't want to go the route of adding coarse-grained read (or worse, write) actions as de facto to defend against such inconsistency. That's why I'm trying to understand and isolate these differences so that I can figure out how we can see (and address) the corresponding issues during dev/test. |
@SCWells72 I'm invoking Ctrl+B (Navigate > Declaration or Usages) |
Ah, okay. You're doing that on the declaration itself, correct? |
I usually invoke use this action anywhere. |
Okay. Interestingly Ctrl/Cmd+B doesn't even trigger So obviously adding a read action around the entire implementation of |
private static Position getPosition(@NotNull PsiElement element, @NotNull PsiFile psiFile) { | ||
if (ApplicationManager.getApplication().isReadAccessAllowed()) { | ||
return doGetPosition(element, psiFile); | ||
private static void processElementUsagesUnderReadAction(@NotNull ThrowableComputable<CodeVisionState, Throwable> computable, |
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.
Everything in this change makes sense to me except for the addition of this method. Why was this added instead of just wrapping the entire body of processElementUsages()
in ReadAction.compute()
?
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.
The main reason is because when dumb is processed we need to skip this search. And when we are in non EDT it should be cancellable.
I find this logic code in UJ ultimate repo.
174442e
to
d485d53
Compare
d485d53
to
54caf44
Compare
Thanks @SCWells72 @jansorg for your reviews. |
Again @jansorg once https://github.com/redhat-developer/lsp4ij/actions/runs/12399426259 will be finished please install nighty and give us feedback. |
@angelozerr With the latest build, I did not see this exception again. Thanks! |
fix: process element usages under ReadAction
Fixes #708