Skip to content

feat(inlayhints): составной тип «Тип, Неопределено» показывается как «Тип?» - #4407

Merged
nixel2007 merged 2 commits into
developfrom
feat/inlayhints-nullable-type
Aug 5, 2026
Merged

nixel2007 merged 2 commits into
developfrom
feat/inlayhints-nullable-type

Conversation

@sfaqer

@sfaqer sfaqer commented Aug 5, 2026

Copy link
Copy Markdown
Member

Проблема

Подсказка типа переменной строилась только когда выведенный тип ровно один. При union'е
она молча не появлялась — и Число, Неопределено не показывалось никогда.

Между тем это самый частый union: так выглядит всё, чего может не оказаться — ключ структуры,
поиск по имени, ветвление с Неопределено в одной из ветвей. Значимый тип там всё равно один.

Решение

Значение: Число? = ...     // Число, Неопределено
Итог: Массив = ...         // один тип — как и раньше
                            // Число, Строка — подсказки по-прежнему нет

Знак вопроса говорит «значения может не быть» короче, чем вторая половина перечисления.

Правило узкое намеренно: два значимых типа знаком вопроса не выразить, а перечислять их
подсказкой шумно — там ничего не изменилось.

Попутно TypeRef.UNDEFINED встал рядом с ANY и UNKNOWN: константа была продублирована
в четырёх местах, и это стало бы пятым.

Проверка

Два теста: пара с Неопределено даёт : Число?, два значимых типа — по-прежнему пусто.
Оба построены на обычном ветвлении Если/Иначе, без завязки на другие ветки в работе.

Полный check зелёный.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Variable type hints now display nullable types with a ? suffix, such as Число?, when a value may also be Неопределено.
    • Hints are shown when one specific type is identified, including nullable types.
  • Bug Fixes

    • Improved handling of inferred variable types involving Неопределено.
    • Hints remain hidden for ambiguous combinations containing multiple significant types.
  • Tests

    • Added coverage for nullable types and ambiguous type combinations.

…«Тип?»

Подсказка типа строилась только когда выведенный тип ровно один, а при union'е молча
не появлялась. Между тем `Тип, Неопределено` — самый частый union: так выглядит всё,
чего может не оказаться (ключ структуры, поиск по имени, ветка с `Неопределено`).
Значимый тип там всё равно один, и знак вопроса говорит это короче, чем вторая
половина перечисления.

Правило узкое намеренно: два значимых типа знаком вопроса не выразить, а перечислять
их подсказкой шумно — там поведение прежнее, хинта нет.

Попутно `TypeRef.UNDEFINED` встал рядом с `ANY` и `UNKNOWN`: константа была
продублирована в четырёх местах, и это стало бы пятым.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 5, 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 Plus

Run ID: f3284660-6a4b-4a0e-84bb-7a573c244eb5

📥 Commits

Reviewing files that changed from the base of the PR and between 7611353 and aad0c2e.

📒 Files selected for processing (1)
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/VariableTypeInlayHintSupplier.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/VariableTypeInlayHintSupplier.java

📝 Walkthrough

Walkthrough

Variable type inference accepts one significant type with optional Неопределено nullability. Nullable hints use a ? suffix. Ambiguous, trivial, ANY, and UNKNOWN results remain suppressed.

Changes

Nullable variable type hints

Layer / File(s) Summary
Nullable inference contract
src/main/java/com/github/_1c_syntax/bsl/languageserver/types/model/TypeRef.java, src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/VariableTypeInlayHintSupplier.java
TypeRef.UNDEFINED represents Неопределено. Inference retains one significant type and nullability separately.
Nullable hint rendering and validation
src/main/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/VariableTypeInlayHintSupplier.java, src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/VariableTypeInlayHintSupplierTest.java
Hint labels append ? for nullable types. Tests cover Число, Неопределено and suppress unions such as Число, Строка.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: displaying a single significant type with «Неопределено» as «Тип?».
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 feat/inlayhints-nullable-type

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.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Test Results

 3 996 files  ± 0   3 996 suites  ±0   57m 26s ⏱️ +54s
 4 144 tests + 2   4 073 ✅ + 2   71 💤 ±0  0 ❌ ±0 
24 864 runs  +12  24 434 ✅ +12  430 💤 ±0  0 ❌ ±0 

Results for commit aad0c2e. ± Comparison against base commit a86d262.

♻️ This comment has been updated with latest results.

- скобки в тернарнике со склейкой строк (java:S864);
- объявление метки перенесено к месту использования (java:S1941);
- размер union'а вынесен в именованную константу (java:S109).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sfaqer

sfaqer commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Замечания Sonar разобраны.

Исправлено: скобки в тернарнике со склейкой строк (S864), объявление метки перенесено к месту использования (S1941), размер union'а вынесен в именованную константу (S109).

Оставлено осознанно — java:S5976, «замените эти три теста одним параметризованным».

Три теста — testNoHintForUnionOfSignificantTypes (новый), testNoHintWhenVariableNameContainsTypeName и testNoHintWhenTypeIsNotInferred. Форма у них общая, но проверяют они три разных правила подавления подсказки: два значимых типа, имя переменной уже содержит имя типа, тип вообще не выведен. Имена и есть документация — в параметризованном тесте они схлопнутся в одно родовое плюс данные, и станет непонятно, какое правило сломалось.

Правило сработало только потому, что мой тест стал третьим по счёту: два других лежат в develop.

Гейт зелёный.

🤖 Generated with Claude Code

@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@nixel2007
nixel2007 merged commit 6b788a8 into develop Aug 5, 2026
36 of 37 checks passed
@nixel2007
nixel2007 deleted the feat/inlayhints-nullable-type branch August 5, 2026 11:09
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