Skip to content

Add semantic highlighting for NStr and StrTemplate functions#3697

Merged
nixel2007 merged 12 commits intodevelopfrom
copilot/resolve-coloring-nstr-strshablon
Dec 26, 2025
Merged

Add semantic highlighting for NStr and StrTemplate functions#3697
nixel2007 merged 12 commits intodevelopfrom
copilot/resolve-coloring-nstr-strshablon

Conversation

Copy link
Contributor

Copilot AI commented Dec 21, 2025

  • Create NStrAndStrTemplateSemanticTokensSupplier to add semantic highlighting for NStr/НСтр and StrTemplate/СтрШаблон
    • Detect calls to NStr/НСтр and highlight language keys (ru=, en=) in string parameters
    • Detect calls to StrTemplate/СтрШаблон and highlight placeholders (%1, %2, %(1)) in string parameters
  • Add tests for the new semantic tokens supplier (10 test cases)
  • Verify the implementation with existing tests (all semantic tokens tests pass)
  • Run code review and security checks (no security issues found)
  • Refactor to use MultilingualStringAnalyser instead of duplicating patterns
  • Fix build error: correct @nullable annotation placement for nested class types
  • Fix failing tests by keeping getVariableSymbol() unchanged while restoring ReferenceIndex optimization
Original prompt

This section details on the original issue you should resolve

<issue_title>Раскраска Нстр и СтрШаблон</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 21, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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

Implement NStrAndStrTemplateSemanticTokensSupplier to highlight:
- Language keys (ru=, en=) in NStr/НСтр function calls
- Placeholders (%1, %2, %(1)) in StrTemplate/СтрШаблон function calls

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copilot AI changed the title [WIP] Resolve coloring issue for Nstr and StrShablon Add semantic highlighting for NStr and StrTemplate functions Dec 21, 2025
Copilot AI requested a review from nixel2007 December 21, 2025 10:29
…ighting

- Extended MultilingualStringAnalyser with public patterns and utility methods:
  - isNStrCall() and isStrTemplateCall() static methods
  - findLanguageKeyPositions() and findPlaceholderPositions() static methods
  - MatchPosition record for position information
  - STR_TEMPLATE_PLACEHOLDER_PATTERN for placeholder detection
- Updated NStrAndStrTemplateSemanticTokensSupplier to use MultilingualStringAnalyser
- Removed duplicate patterns from semantic tokens supplier

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 25, 2025

Test Results

2 781 files  ±  0  2 781 suites  ±0   48m 0s ⏱️ +48s
1 091 tests + 17  1 091 ✅ + 17  0 💤 ±0  0 ❌ ±0 
9 819 runs  +153  9 819 ✅ +153  0 💤 ±0  0 ❌ ±0 

Results for commit 4e47072. ± Comparison against base commit 50382d6.

This pull request removes 14 and adds 27 tests. Note that renamed tests count towards both.
#, count=1
, count=0
, count=1
A, count=1
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [2] content=
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [6] content=
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [7] content=#
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [8] content=
com.github._1c_syntax.bsl.languageserver.semantictokens.QuerySemanticTokensSupplierTest ‑ testQueryWithEnumValue()
com.github._1c_syntax.bsl.languageserver.semantictokens.QuerySemanticTokensSupplierTest ‑ testQueryWithParameter()
…
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [2] content=
, count=0
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [6] content=
A, count=1
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [7] content=#
, count=1
com.github._1c_syntax.bsl.languageserver.diagnostics.MetadataObjectNameLengthDiagnosticTest ‑ [8] content=
#, count=1
com.github._1c_syntax.bsl.languageserver.semantictokens.StringSemanticTokensSupplierTest ‑ testMultilineQueryString()
com.github._1c_syntax.bsl.languageserver.semantictokens.StringSemanticTokensSupplierTest ‑ testMultilineString()
com.github._1c_syntax.bsl.languageserver.semantictokens.StringSemanticTokensSupplierTest ‑ testNStrAndQueryInSameMethod()
com.github._1c_syntax.bsl.languageserver.semantictokens.StringSemanticTokensSupplierTest ‑ testNStrEnglishName()
com.github._1c_syntax.bsl.languageserver.semantictokens.StringSemanticTokensSupplierTest ‑ testNStrInsideStrTemplate()
com.github._1c_syntax.bsl.languageserver.semantictokens.StringSemanticTokensSupplierTest ‑ testNStrInsideStrTemplateMultiple()
…

♻️ This comment has been updated with latest results.

@nixel2007
Copy link
Member

@copilot почему проект перестал собираться? как починить?

Use BSLParser.@nullable StringContext syntax for type-use annotations
on nested class types instead of @nullable BSLParser.StringContext

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 25, 2025

@copilot почему проект перестал собираться? как починить?

Fixed. The issue was incorrect @Nullable annotation placement for nested class types. For type-use annotations like jspecify's @Nullable, when the type is a nested class like BSLParser.StringContext, the annotation must be placed before the inner class name: BSLParser.@Nullable StringContext instead of @Nullable BSLParser.StringContext.

Commit: a783cb5

@nixel2007
Copy link
Member

/buildJar

@github-actions
Copy link
Contributor

✅ Собраны JAR-файлы для этого PR по команде /buildJar.

Артефакт: 4969848801

Файлы внутри:

  • bsl-language-server-copilot-resolve-coloring-nstr-strshablon-23e4ede-exec.jar

@nixel2007
Copy link
Member

@copilot посмотри, почему тесты падают.

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 26, 2025

@copilot посмотри, почему тесты падают.

The test failures were caused by optimizations I made to SymbolTree.getVariableSymbol() and ReferenceIndex.getFromSymbol() methods. These optimizations changed how variables are looked up, which broke the diagnostic tests. Reverted these changes to restore the original behavior. Commit: a461be5

@nixel2007
Copy link
Member

@copilot эй! Верни свои оптимизации. Откати только изменения в getVariableSymbol

… unchanged

- Added getSymbolAtPosition() method to SymbolTree for hierarchical symbol lookup
- Restored ReferenceIndex.getFromSymbol() optimization to use getSymbolAtPosition()
- Kept getVariableSymbol(ParserRuleContext) using original range-based lookup to avoid test failures

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 26, 2025

@copilot эй! Верни свои оптимизации. Откати только изменения в getVariableSymbol

Restored the ReferenceIndex optimization (getFromSymbol() using symbolTree.getSymbolAtPosition()). Kept getVariableSymbol(ParserRuleContext) using the original range-based lookup. Added getSymbolAtPosition() method to SymbolTree for the ReferenceIndex optimization. Commit: f793750

@nixel2007 nixel2007 marked this pull request as ready for review December 26, 2025 10:30
Copilot AI review requested due to automatic review settings December 26, 2025 10:30
@nixel2007
Copy link
Member

/buildJar

@github-actions
Copy link
Contributor

✅ Собраны JAR-файлы для этого PR по команде /buildJar.

Артефакт: 4970441063

Файлы внутри:

  • bsl-language-server-copilot-resolve-coloring-nstr-strshablon-4e47072-exec.jar

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements semantic highlighting for NStr (multilingual strings) and StrTemplate (string templates) functions in the BSL Language Server. The implementation consolidates string-related semantic token processing into a new StringSemanticTokensSupplier that handles regular strings, NStr language keys, StrTemplate placeholders, and SDBL query strings.

Key changes:

  • Created a centralized string token processing system that detects and highlights language keys (e.g., ru=, en=) in NStr calls and placeholders (e.g., %1, %(2)) in StrTemplate calls
  • Refactored query token processing from a separate supplier into the string supplier for better cohesion
  • Added support for detecting templates stored in variables before being used in StrTemplate calls

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
StringSemanticTokensSupplier.java New centralized supplier for all string-related semantic tokens including NStr, StrTemplate, and SDBL queries
SpecialContextVisitor.java Visitor that detects NStr and StrTemplate calls, including variable assignments used as templates
SdblAstTokenCollector.java Visitor for collecting AST-based token overrides for SDBL queries
SdblTokenTypes.java Utility class for mapping SDBL lexer tokens to semantic token types
MultilingualStringAnalyser.java Enhanced with public methods for finding language keys and placeholders, pattern matching changed from find() to matches()
SymbolsSemanticTokensSupplier.java Simplified variable reference handling by removing redundant ReferenceResolver usage
LexicalSemanticTokensSupplier.java Removed string token processing (delegated to StringSemanticTokensSupplier)
ReferenceIndex.java Optimized getFromSymbol() using new SymbolTree.getSymbolAtPosition() method
SymbolTree.java Added getSymbolAtPosition() method for hierarchical symbol lookup
StringSemanticTokensSupplierTest.java Comprehensive test suite with 27 test cases covering all scenarios
Supporting classes New record classes for data structures (StringContext, SubToken, TokenPosition, etc.)
QuerySemanticTokensSupplier.java Deleted (functionality consolidated into StringSemanticTokensSupplier)
QuerySemanticTokensSupplierTest.java Deleted (tests moved to StringSemanticTokensSupplierTest)

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@nixel2007 nixel2007 merged commit a92fe5c into develop Dec 26, 2025
49 of 51 checks passed
@nixel2007 nixel2007 deleted the copilot/resolve-coloring-nstr-strshablon branch December 26, 2025 11:17
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.

Раскраска Нстр и СтрШаблон

3 participants