Open halildurmus opened 1 year ago
I don't know what kind of highlighting this is. I usually keep a possibly related setting disabled.
But even when it is enable, highlighting looks correct to me.
Maybe some plugin does it?
I tested on IntelliJ Build #IC-232.9921.47, built on September 12, 2023
.
And Dart SDK version: 3.2.0-edge.0ac6f0846afe9a9da72fdbb0a595ac70ec06758b (be) (Mon Sep 11 15:30:02 2023 +0000) on "macos_arm64"
.
I don't know what kind of highlighting this is.
It's called Occurrences Highlight
in VSCode:
... But even when it is enable, highlighting looks correct to me.
Shouldn't the key
identifier in Ln 4 also be highlighted?
@DanTup for VS Code question. @jwren for IntelliJ occurrences implementation.
I don't know for sure why key
is not highlighted in print(key)
.
It depends on the way it is implemented in the IDE and VS Code.
Theoretically when you say final MapEntry(:key)
, the word key
means both, the getters name, and the name of the declared local variable. And we do have navigation from :key
to the getter, and from print(key)
to the :key
.
I think there are two issues here:
:key
is both a variable declaration and a getter reference) and only return the first group that contains an occurrence at the required offsetIt's possible that IntelliJ also has some variation of 2 though.. It's not clear if the legacy protocol is intended to handle two Occurrences
that overlap.
Possibly fixes at https://dart-review.googlesource.com/c/sdk/+/326220, but not certain whether the overlapping Occurrences is the right thing for IntelliJ.
I'm attempting to answer that question now.
Looking into Dart plugin for IntelliJ source code, I think that it does not use analysis.occurrences
at all.
It might be using https://github.com/JetBrains/intellij-plugins/blob/21daa3f44caf2b74a0a3b0e2c5fa49375103ea57/Dart/src/com/jetbrains/lang/dart/resolve/DartResolver.java#L28 indirectly, maybe based on navigation information, but I'm not sure. Maybe @jwren knows.
Looking into Dart plugin for IntelliJ source code, I think that it does not use analysis.occurrences at all.
Ah yes, this was noted at https://github.com/Dart-Code/Dart-Code/issues/4454#issuecomment-1494176327
Looking through the Dart IJ plugin, NotificationAnalysisOccurrencesProcessor
processes the analysis.occurences
, but I don't see any Occurrences
references that plug into the IJ platform for this kind of highlighting.
IIRC, these highlighting are done with a simple local dart resolver for local instances. @alexander-doroshko will know
IntelliJ Dart plugin doesn't use org.dartlang.analysis.server.protocol.Occurrences, but it doesn't use its own resolver either :). Occurrences highlighting is based on navigation regions, which come from the server. IDE looks for the word occurrences in the file and checks which of them have the same navigation target. Is there any similar strange behavior in IntelliJ?
https://github.com/dart-lang/sdk/commit/23e968139222fb4331eac1a20dfaa7c1d95c7f28 should fix this issue for the server occurrences and LSP/VS Code, but I'm not sure if there's still outstanding work for IntelliJ here if it's not using that.
Given the code above, when I place the cursor inside the
key
variable, the highlight offset seems incorrect (:ke
is highlighted instead ofkey
), and thekey
identifier is not highlighted as expected. However, highlighting works correctly if the cursor is placed at the end of thekey
variable or inside thekey
identifier:Another issue is observed when placing the cursor inside the
key
variable; the highlight offset for thekey
variable declaration inside theif-case
statement appears to be inaccurate (:fi
is highlighted instead ofkey
):Dart version: