Skip to content

fix(semanticTokens): подсвечивать вложенные типы в описаниях методов#4184

Merged
nixel2007 merged 1 commit into
developfrom
claude/collection-type-highlighting-kxwwas
Jun 22, 2026
Merged

fix(semanticTokens): подсвечивать вложенные типы в описаниях методов#4184
nixel2007 merged 1 commit into
developfrom
claude/collection-type-highlighting-kxwwas

Conversation

@nixel2007

@nixel2007 nixel2007 commented Jun 21, 2026

Copy link
Copy Markdown
Member

Проблема

В описаниях методов (// Возвращаемое значение: / // Параметры:) тип-значение коллекции не подсвечивался. Например, для

// Возвращаемое значение:
//  Массив из Число - Массив тестовых чисел.
Функция ТестовыеЧисла() Экспорт
КонецФункции

подсвечивался только тип-голова Массив, а Число оставалось серым комментарием (см. #4179, скриншот ховера).

Причина

Подсветка типов в описаниях опиралась исключительно на TYPE_NAME-элементы парсера из SourceDefinedSymbolDescription.getElements(). Для описаний методов парсер отдаёт отдельным TYPE_NAME-элементом только тип-голову коллекции (Массив) — тип-значение (Число) в getElements() не попадает. Поскольку для методов резолв-гвард отключён (validateTypeResolution = false), подсветка целиком зависела от getElements() и теряла вложенные типы.

(Для висячих комментариев переменных getElements() отдаёт оба токена, поэтому там проблема не проявлялась.)

Решение

Вложенные типы (типы-значения коллекций Массив из ЧислоЧисло и типы полей структур) теперь подсвечиваются напрямую из структурных аксессоров DescriptionTypes.typesOf по их element().range(), с пропуском уже покрытых через getElements() голов (по совпадению диапазона). Для описаний переменных применяется тот же гвард резолва, что и для основной подсветки, — чтобы свободный текст висячего комментария не красился как тип.

Затрагивается только подсветка (BslDocSemanticTokensSupplier). Document links на вложенные типы уже работали — они строятся из typesOf напрямую. На вывод типа для автокомплита влияния нет.

Проверка

  • Новый регресс-тест testMethodReturnCollectionTypeHighlightingМассив, и ЧислоType).
  • Зелёные: BslDocSemanticTokensSupplierTest, documentlink.*, spotless.

🤖 Generated with Claude Code


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • Improved semantic highlighting for BSL documentation type references, producing more accurate Type tokens—particularly for nested types like collection heads and element types—while avoiding duplicate emissions.
  • Tests

    • Added coverage for documenting a function return as a collection type in BSL comments, verifying that both the collection name and the contained element type are highlighted as documentation Type tokens.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

BslDocSemanticTokensSupplier refactors type token emission by removing direct TYPE_NAME element handling and introducing a new private addTypeTokens helper that derives semantic Type tokens from DescriptionTypes.typesOf with optional TypeService resolution filtering. A new test verifies that a "Массив из Число" return-value documentation comment produces tokens for both the collection head and element type.

Changes

Type semantic token emission refactor for BSL doc comments

Layer / File(s) Summary
Type token extraction refactor and new addTypeTokens helper
src/main/java/.../semantictokens/BslDocSemanticTokensSupplier.java
Updates imports to include required type utilities; removes TYPE_NAME element handling from addBslDocDescriptionTokens loop; adds call to new addTypeTokens helper that derives type ranges from DescriptionTypes.typesOf, optionally filters to TypeService-resolvable types via isResolvable predicate, deduplicates ranges, and emits SemanticTokenTypes.Type + SemanticTokenModifiers.Documentation tokens.
Collection return type highlighting test
src/test/java/.../semantictokens/BslDocSemanticTokensSupplierTest.java
Adds testMethodReturnCollectionTypeHighlighting that validates semantic tokenization of a function return documentation comment with collection type, asserting both "Массив" (head) and "Число" (element) are emitted as Type/Documentation tokens.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • 1c-syntax/bsl-language-server#4165: Modifies the same BslDocSemanticTokensSupplier with validateTypeResolution and TypeService-based filtering, which is directly referenced by the new addTypeTokens helper.
  • 1c-syntax/bsl-language-server#4172: Extends DescriptionTypes.typesOf to include nested collection type values (e.g., "Число" inside "Массив из Число"), directly enabling the element-type highlighting that the new test covers.

Suggested reviewers

  • theshadowco

Poem

🐇 A rabbit hops through types both old and new,
addTypeTokens now reveals what parser never knew!
From Массив to Число, each token shines so bright,
The semantic tokens flow in perfect structural light.
No TYPE_NAME shortcut—truth through typesOf we find! ✨

🚥 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 pull request title accurately describes the main change: fixing semantic token highlighting for nested types in method descriptions.
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/collection-type-highlighting-kxwwas

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.

@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Test Results

 3 522 files  ±0   3 522 suites  ±0   1h 32m 37s ⏱️ - 5m 26s
 3 458 tests +1   3 440 ✅ +1   18 💤 ±0  0 ❌ ±0 
20 748 runs  +6  20 636 ✅ +6  112 💤 ±0  0 ❌ ±0 

Results for commit 7deb4c1. ± Comparison against base commit a538ec8.

♻️ This comment has been updated with latest results.

@nixel2007
nixel2007 force-pushed the claude/collection-type-highlighting-kxwwas branch from 7deb4c1 to c3dd3f5 Compare June 22, 2026 05:42
В описаниях методов («Возвращаемое значение: Массив из Число») подсвечивался
только тип-голова коллекции (Массив): подсветка типов опиралась на TYPE_NAME-элементы
парсера из getElements(), а они для описаний методов отдают лишь голову — тип-значение
коллекции (Число) и типы полей структур в getElements() не попадают.

Теперь все типы описания подсвечиваются из структурных аксессоров
DescriptionTypes.typesOf по их element().range() (включая типы-значения коллекций и
типы полей структур). На корпусе описаний typesOf — надмножество TYPE_NAME-элементов
getElements(), поэтому проход по TYPE_NAME убран, а getElements() остаётся источником
токенов имён параметров и ключевых слов. Для переменных сохранён резолв-гард, чтобы
свободный текст висячего комментария не красился как тип.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016DL8j9ZCc6WCiKeL4uMBFs
@nixel2007
nixel2007 force-pushed the claude/collection-type-highlighting-kxwwas branch from c3dd3f5 to a2ca8ac Compare June 22, 2026 05:58
@nixel2007
nixel2007 merged commit 1833bdb into develop Jun 22, 2026
30 of 32 checks passed
@nixel2007
nixel2007 deleted the claude/collection-type-highlighting-kxwwas branch June 22, 2026 06:02
@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.

2 participants