2222package com .github ._1c_syntax .bsl .languageserver .providers ;
2323
2424import com .github ._1c_syntax .bsl .languageserver .context .DocumentContext ;
25+ import com .github ._1c_syntax .bsl .languageserver .context .ServerContext ;
2526import com .github ._1c_syntax .bsl .languageserver .references .ReferenceIndexFiller ;
2627import com .github ._1c_syntax .bsl .languageserver .util .CleanupContextBeforeClassAndAfterEachTestMethod ;
2728import com .github ._1c_syntax .bsl .languageserver .util .TestUtils ;
29+ import com .github ._1c_syntax .utils .Absolute ;
30+ import org .apache .commons .io .FileUtils ;
2831import org .eclipse .lsp4j .Position ;
2932import org .eclipse .lsp4j .Range ;
3033import org .eclipse .lsp4j .SemanticTokenModifiers ;
3942import org .springframework .beans .factory .annotation .Autowired ;
4043import org .springframework .boot .test .context .SpringBootTest ;
4144
45+ import java .io .File ;
46+ import java .io .IOException ;
4247import java .net .URI ;
48+ import java .nio .charset .StandardCharsets ;
4349import java .util .ArrayList ;
4450import java .util .List ;
4551import java .util .Set ;
@@ -59,6 +65,9 @@ class SemanticTokensProviderTest {
5965 @ Autowired
6066 private ReferenceIndexFiller referenceIndexFiller ;
6167
68+ @ Autowired
69+ private ServerContext serverContext ;
70+
6271 // region Helper types and methods
6372
6473 /**
@@ -1661,5 +1670,59 @@ void rangeTokens_withSdblQuery() {
16611670 }
16621671
16631672 // endregion
1673+
1674+ // region Common module namespace tests
1675+
1676+ @ Test
1677+ void variableWithCommonModuleNotHighlightedAsNamespace () throws IOException {
1678+ // given - code with variable that holds reference to common module via ОбщегоНазначения.ОбщийМодуль
1679+ // The variable itself should NOT be highlighted as namespace
1680+ // Pattern: Модуль = ОбщегоНазначения.ОбщийМодуль("..."); Модуль.Метод();
1681+ var path = Absolute .path ("src/test/resources/metadata/designer" );
1682+ serverContext .setConfigurationRoot (path );
1683+
1684+ // Load the common module
1685+ var file = new File ("src/test/resources/metadata/designer" ,
1686+ "CommonModules/ПервыйОбщийМодуль/Ext/Module.bsl" );
1687+ var uri = Absolute .uri (file );
1688+ TestUtils .getDocumentContext (
1689+ uri ,
1690+ FileUtils .readFileToString (file , StandardCharsets .UTF_8 ),
1691+ serverContext
1692+ );
1693+
1694+ // Load a document with the pattern
1695+ var documentContext = TestUtils .getDocumentContextFromFile (
1696+ "./src/test/resources/references/ReferenceIndexCommonModuleVariable.bsl"
1697+ );
1698+ referenceIndexFiller .fill (documentContext );
1699+
1700+ // when
1701+ TextDocumentIdentifier textDocumentIdentifier = TestUtils .getTextDocumentIdentifier (documentContext .getUri ());
1702+ SemanticTokens tokens = provider .getSemanticTokensFull (documentContext , new SemanticTokensParams (textDocumentIdentifier ));
1703+ var decoded = decode (tokens .getData ());
1704+
1705+ // then
1706+ int namespaceTypeIdx = legend .getTokenTypes ().indexOf (SemanticTokenTypes .Namespace );
1707+
1708+ // Find all namespace tokens
1709+ var namespaceTokens = decoded .stream ()
1710+ .filter (t -> t .type () == namespaceTypeIdx )
1711+ .toList ();
1712+
1713+ // Variable "МодульУправлениеДоступом" should NOT be highlighted as namespace
1714+ // It appears on lines 6, 7, 10, 13 (0-indexed) in ReferenceIndexCommonModuleVariable.bsl
1715+ // Lines 7, 10, 13 are where the variable is used for method calls
1716+ for (var token : namespaceTokens ) {
1717+ // Namespace tokens should not be at position 4 (start of "МодульУправлениеДоступом") on variable usage lines
1718+ if (token .line () == 7 || token .line () == 10 || token .line () == 13 ) {
1719+ assertThat (token .start ())
1720+ .as ("Variable 'МодульУправлениеДоступом' at line %d should not be namespace" , token .line ())
1721+ .isNotEqualTo (4 );
1722+ }
1723+ }
1724+ }
1725+
1726+ // endregion
16641727}
16651728
0 commit comments