Skip to content

Fix IndexOutOfBounds from the highlight pass #2252

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

Merged
merged 8 commits into from
Sep 10, 2024
Merged

Conversation

mkondratek
Copy link
Contributor

@mkondratek mkondratek commented Sep 9, 2024

@mkondratek mkondratek self-assigned this Sep 9, 2024
@mkondratek mkondratek changed the title Fixes Fix multiple IndexOutOfBounds Sep 9, 2024
@mkondratek mkondratek changed the title Fix multiple IndexOutOfBounds Fix IndexOutOfBounds from the highlight pass Sep 9, 2024
startOffset > this.textLength ||
endOffset > this.textLength ||
startOffset > endOffset) {
throw IllegalArgumentException(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I wanted to bound the values here. But maybe we should not do that? We should be aware of what arguments we pass here.

@@ -97,6 +101,12 @@ class CodyFixHighlightPass(val file: PsiFile, val editor: Editor) :
null
}
}
.toList()

if (protocolDiagnostics.isEmpty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was possible that we have been sending an empty list 😅 that was completely redundant

Comment on lines +39 to +40
val endOffset = max(cursor, range.startOffset + completionText.length)
codeStyleManager.reformatText(psiFile, cursor, endOffset)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to highlight pass but I managed to get it once

ProtocolLocation(
uri = protocolTextDocument.uri,
range = document.codyRange(highlight.startOffset, highlight.endOffset))
val location = ProtocolLocation(uri = protocolTextDocument.uri, range = range)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can get rid of that whole protocolTextDocument?
It seems we need it only for uri, and we can get is using ProtocolTextDocument::uriFor.
It is not marked as requiring EDT so there is a good chance we will also not need that future, etc..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, doCollectInformation is called from the background thread by IntelliJ

image
(we are extending HighlightPass and collectInformation calls doCollectInformation)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point about the URI - fixing!

@@ -106,15 +116,18 @@ class CodyFixHighlightPass(val file: PsiFile, val editor: Editor) :
if (progress.isCanceled) {
break
}
if (highlight.startOffset > document.textLength ||
Copy link
Contributor

Choose a reason for hiding this comment

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

We are now reading document in outside of the EDT.
Your check probably highly decreases chance of the issue, but I doubt it eliminates it as state can change even between this and the next instruction.
I think document.codyRange should be called on EDT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

highlight.startOffset > highlight.endOffset) {
break
}

val range = document.codyRange(highlight.startOffset, highlight.endOffset)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that running in the EDT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It runs in EDT. I added @RequiresEdt on it.

Copy link
Contributor

@pkukielka pkukielka left a comment

Choose a reason for hiding this comment

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

LGTM

@mkondratek mkondratek merged commit 1e2c35b into main Sep 10, 2024
6 of 7 checks passed
@mkondratek mkondratek deleted the mkondratek/fix/ioob branch September 10, 2024 08:13
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