Skip to content

Вариант языка проекта считается в одном месте - #4365

Merged
nixel2007 merged 1 commit into
developfrom
fix/script-variant-single-source
Aug 2, 2026
Merged

Вариант языка проекта считается в одном месте#4365
nixel2007 merged 1 commit into
developfrom
fix/script-variant-single-source

Conversation

@sfaqer

@sfaqer sfaqer commented Aug 2, 2026

Copy link
Copy Markdown
Member

По замечанию ревьюера в #4347: «кажется, этот расчёт уже где-то есть». Есть — и даже дважды.

DocumentContext.getScriptVariantLanguage() отвечает ровно на этот вопрос: на каком языке писать в код пользователя. Им уже пользуются сворачивание областей (RegionFoldingRangeSupplier — буквально слово Область/Region), CodeBlockFoldingRangeSupplier, автодополнение и quick fix EventHandlerInvalidSignatureDiagnostic.

Рядом с ним жили две копии того же правила:

место что было
GenerateStandardRegionsSupplier.getRegionsLanguage своя реализация, до этих правок
EventHandlerOutsideEventRegionDiagnostic.scriptVariantOf третья копия, добавлена в #4347

Обе удалены, оба места зовут канонический метод.

Побочно закрытая дыра

У копий не было отступного пути на ScriptVariant.UNKNOWN, который есть у getScriptVariantLanguage(). MultiName.get(ScriptVariant) трактует всё, кроме ENGLISH, как русский, поэтому в конфигурации с неопознанным вариантом языка области назывались по-русски независимо от языка проекта. Теперь там язык интерфейса сервера — как и задумано.

Мелочи

ScriptVariant остался нужен GenerateStandardRegionsSupplier: его требует API Regions. На месте вызова это одна строка-переходник ScriptVariant.valueByName(...getLanguageCode()) — приведение типа, а не расчёт правила.

Из диагностики вместе с расчётом ушла зависимость от LanguageServerConfiguration: она была нужна только ради него.

Итог: −46 строк, +17.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved language detection for standard region generation and event-handler diagnostics.
    • Region names and generated directives now use the document’s actual language, providing more accurate localized results.
    • Quick fixes for event handlers outside their expected regions now generate language-appropriate region names and directives.
    • Removed reliance on separate language configuration for these code actions and diagnostics.

`DocumentContext.getScriptVariantLanguage()` уже отвечает на вопрос «на каком языке
писать в код пользователя» и используется для этого сворачиванием областей,
автодополнением и quick fix'ом `EventHandlerInvalidSignature`. Рядом жили две копии
того же расчёта: `GenerateStandardRegionsSupplier.getRegionsLanguage` и
`EventHandlerOutsideEventRegionDiagnostic.scriptVariantOf`. Обе удалены.

Побочно закрыта дыра: у копий не было отступного пути на `ScriptVariant.UNKNOWN`,
который есть у канонического метода, — в неопознанной конфигурации области назывались
по-русски независимо от языка проекта.

Из диагностики вместе с расчётом ушла зависимость от `LanguageServerConfiguration`.

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

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The changes replace configuration-based script-variant selection with document-derived language selection for standard regions and event-handler diagnostics. Region lookup now accepts Language, and the diagnostic constructor no longer accepts configuration.

Changes

Document-derived region language

Layer / File(s) Summary
Language-based region selection
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/EventHandlerTargetRegion.java, src/main/java/com/github/_1c_syntax/bsl/languageserver/codeactions/GenerateStandardRegionsSupplier.java
Region lookup now accepts Language. Standard region generation derives the language from the document’s script-variant language code.
Diagnostic language integration
src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/EventHandlerOutsideEventRegionDiagnostic.java
The diagnostic removes configuration state and uses the document language for region names, quick-fix targets, and region directives.

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

Possibly related PRs

Suggested reviewers: claude, nixel2007

🚥 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: centralizing project language variant calculation in one place.
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 fix/script-variant-single-source

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/java/com/github/_1c_syntax/bsl/languageserver/codeactions/GenerateStandardRegionsSupplier.java (1)

83-86: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for both language consumers.

Test a project language that differs from the server UI language and test ScriptVariant.UNKNOWN. Assert generated region names and #Region/#EndRegion directives. Also assert that EventHandlerOutsideEventRegionDiagnostic messages and quick fixes use the same language.

The supplied GenerateStandardRegionsSupplierTest asserts only the action title. It does not protect this changed output.

As per coding guidelines, always run tests before submitting changes and maintain or improve test coverage using appropriate test frameworks.
Based on the supplied test context, the visible assertion covers only the code-action title.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/github/_1c_syntax/bsl/languageserver/codeactions/GenerateStandardRegionsSupplier.java`
around lines 83 - 86, Add regression tests in
GenerateStandardRegionsSupplierTest for a project language differing from the
server UI language and for ScriptVariant.UNKNOWN. Assert generated region names
and `#Region/`#EndRegion directives, and verify
EventHandlerOutsideEventRegionDiagnostic messages and quick fixes use that same
language, not just the action title; run the relevant tests before submission.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/main/java/com/github/_1c_syntax/bsl/languageserver/codeactions/GenerateStandardRegionsSupplier.java`:
- Around line 83-86: Add regression tests in GenerateStandardRegionsSupplierTest
for a project language differing from the server UI language and for
ScriptVariant.UNKNOWN. Assert generated region names and `#Region/`#EndRegion
directives, and verify EventHandlerOutsideEventRegionDiagnostic messages and
quick fixes use that same language, not just the action title; run the relevant
tests before submission.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fa09135b-cd4d-43e5-b107-677ec30d1c35

📥 Commits

Reviewing files that changed from the base of the PR and between 50d66d6 and 3f1469f.

📒 Files selected for processing (3)
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/codeactions/GenerateStandardRegionsSupplier.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/EventHandlerOutsideEventRegionDiagnostic.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/EventHandlerTargetRegion.java

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Test Results

 3 936 files  ±0   3 936 suites  ±0   1h 5m 40s ⏱️ +12s
 4 053 tests ±0   3 987 ✅ ±0   66 💤 ±0  0 ❌ ±0 
24 318 runs  ±0  23 918 ✅ ±0  400 💤 ±0  0 ❌ ±0 

Results for commit 3f1469f. ± Comparison against base commit 50d66d6.

♻️ This comment has been updated with latest results.

@sfaqer
sfaqer requested a review from nixel2007 August 2, 2026 02:42
@nixel2007
nixel2007 merged commit 5a6e8c1 into develop Aug 2, 2026
45 of 46 checks passed
@nixel2007
nixel2007 deleted the fix/script-variant-single-source branch August 2, 2026 06:13
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