Repository navigation
Description
Split out of #2281, as it needs an API deprecation, not a late 0.30.2 change.
What
DocumentSymbolData.equals (DocumentSymbolData.java:120-137) is true for another DocumentSymbolData with an equal symbol, and also for any PsiElement that LSPDocumentSymbolFeature.matchesPsiElement accepts. hashCode uses only the symbol. So equals isn't symmetric, and an object equal to a symbol can have another hash code.
Why the PsiElement branch is no longer needed
Checked in the bytecode of IntelliJ 2024.2 (IC 242.20224.300) and 2026.3 (IU 263.7307.200):
-
The editor element is always a symbol. Since fix: Always Select Opened Element should select parent DocumentSymbol #1531 (0.20.0),
findAcceptableElementreturns the containingDocumentSymbolData. SoTextEditorBasedStructureViewModel.getCurrentEditorElement()gives aDocumentSymbolDataor null. -
Every selection path compares a symbol with a symbol: the structure view's Always Select Opened Element (
StructureViewComponent.visitPathForElementSelection,Comparing.equal(value, element)), Select In → Structure, the File Structure popup, and the 2026.3 popup backend (StructureViewNodeKey). -
The branch from fix: In Structure tool window, Always Select Opened Element did not work #1381 is still reached only when a symbol is compared with the file's
PsiFile:- in the
PsiTreeUtil.isAncestorwalk, with the same result either way; - in
StructureViewComponent.MyNodeWrapper.equals; - in the old popup's speed search.
It is true there only for a symbol whose selection range is the whole file, such as a File or Module symbol, where it is a spurious match.
- in the
-
Hash-based collections are safe: none lets the asymmetry decide anything, since
synchronizeChildrenkeys on tree elements whoseequalschecks the class, and 2026.3'sStructureViewNodeKeyincludes the element class. -
No other uses: breadcrumbs and sticky lines compare symbols only, and LSP4IJ registers no navigation bar extension.
-
matchesPsiElement: it is public and documented indocs/LSPApi.md, but thisequalsis its only caller. No client on GitHub overrides it. -
Dead code: LSP4IJ's
getSuitableClassesoverride from fix: In Structure tool window, Always Select Opened Element did not work #1381 is unused, since its only user is the defaultfindAcceptableElement, which LSP4IJ replaces.
Plan
- 0.30.2: deprecate
LSPDocumentSymbolFeature.matchesPsiElementfor removal, with no behaviour change (refactor: deprecate LSPDocumentSymbolFeature.matchesPsiElement, which the Structure view no longer needs #2288).equalsstill calls it, so a client that overrides it gets a release of warning.
For 0.31.0
- Compare symbols only in
equals, which makes it symmetric and consistent withhashCode. - Remove the dead
getSuitableClassesoverride;matchesPsiElementis no longer called, and can be removed in a later release. - First add tests that pin the structure view's selection: the caret, the containing symbol, nested symbols, and two symbols of the same name. They should pass before and after. They need a
StructureViewComponentwith a mock language server.
Activity
refactor: deprecate LSPDocumentSymbolFeature.matchesPsiElement, which…
refactor: replace the deprecated APIs whose replacements IntelliJ 202…
refactor: replace the deprecated APIs whose replacements IntelliJ 202…