Skip to content

perf(inlayhints): убрать квадратичный обход AST в SourceDefinedMethodCallInlayHintSupplier#4107

Merged
nixel2007 merged 1 commit into
developfrom
claude/inlayhint-perf-docall-index
Jun 14, 2026
Merged

perf(inlayhints): убрать квадратичный обход AST в SourceDefinedMethodCallInlayHintSupplier#4107
nixel2007 merged 1 commit into
developfrom
claude/inlayhint-perf-docall-index

Conversation

@nixel2007

@nixel2007 nixel2007 commented Jun 14, 2026

Copy link
Copy Markdown
Member

Что

Устранён квадратичный обход AST в SourceDefinedMethodCallInlayHintSupplier.

Как

  • Раньше для каждой ссылки выполнялся Trees.findAllRuleNodes по всему AST.
  • Теперь — один проход, результат складывается в новый класс DoCallRangeIndex, ключом служит Range вызова / имени типа, совпадающий с Reference#selectionRange().
  • Поиск по индексу — O(1).

Поведение не изменилось; добавлен новый класс DoCallRangeIndex.

Выделено из #4077 (часть 2 из 2).

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced parameter inlay hints for method calls, with improved handling of default values and skipped arguments in call parameters.
  • Refactoring

    • Optimized performance of inlay hint generation by reducing unnecessary full AST traversals when processing method references.
  • Tests

    • Added comprehensive test coverage for method call inlay hints, including edge cases with empty and skipped arguments.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 885e5b07-89ec-4905-92ca-805674fe2afb

📥 Commits

Reviewing files that changed from the base of the PR and between 3c41a89 and b1d8059.

📒 Files selected for processing (3)
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/DoCallRangeIndex.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplier.java
  • src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java

📝 Walkthrough

Walkthrough

Introduces DoCallRangeIndex, a package-private class that pre-indexes all doCall AST nodes in a DocumentContext by their method-name or constructor-type selection range. SourceDefinedMethodCallInlayHintSupplier is refactored to resolve references through this index instead of walking the full AST per reference, removing the isRightMethod helper. New test cases cover multi-callsite, empty-argument, fewer-arguments, empty-range, and skipped-argument scenarios.

Changes

DoCallRangeIndex and InlayHint Supplier Refactor

Layer / File(s) Summary
DoCallRangeIndex: build and lookup
src/main/java/.../inlayhints/DoCallRangeIndex.java
New class with of(DocumentContext) factory that traverses all doCall nodes, extracts the method-name or constructor-type range via methodNameRange(ParserRuleContext), and stores the first DoCallContext per "startLine:startChar:endLine:endChar" key. doCallFor(Reference) converts reference.selectionRange() to the same key and returns the matching context as Optional.
Supplier refactor and new tests
src/main/java/.../inlayhints/SourceDefinedMethodCallInlayHintSupplier.java, src/test/java/.../inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java
getInlayHints now builds a DoCallRangeIndex once per call and resolves each method reference to a DoCallContext directly, replacing the prior stream+full-AST-walk approach. toInlayHints is updated to accept (Reference, DoCallContext) and reads callParamList() from the resolved context. isRightMethod is removed. Tests add coverage for multi-callsite hints, empty-argument default values, fewer-args-than-params truncation, empty-range returning no hints, and skipped-argument default-value display.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Supplier as SourceDefinedMethodCallInlayHintSupplier
  participant Index as DoCallRangeIndex
  participant Doc as DocumentContext

  Client->>Supplier: getInlayHints(documentContext, range)
  Supplier->>Index: of(documentContext)
  Index->>Doc: traverse all doCall nodes
  Doc-->>Index: doCall list with name ranges
  Index-->>Supplier: DoCallRangeIndex

  loop each method reference in range
    Supplier->>Index: doCallFor(reference)
    Index-->>Supplier: Optional DoCallContext
    Supplier->>Supplier: toInlayHints(reference, doCall)
  end

  Supplier-->>Client: List of InlayHint
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A rabbit once indexed a call-tree with care,
No more walking the AST branch by branch there.
A map of name-ranges, quick look-up for free,
Now hints pop up swiftly wherever they be.
With tests for the skipped and the empty in place,
The inlay hints hop with remarkable grace! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: removing quadratic AST traversal in SourceDefinedMethodCallInlayHintSupplier, which aligns with the core optimization objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/inlayhint-perf-docall-index

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nixel2007
nixel2007 merged commit 0b326db into develop Jun 14, 2026
33 checks passed
@nixel2007
nixel2007 deleted the claude/inlayhint-perf-docall-index branch June 14, 2026 10:27
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant