2222package com .github ._1c_syntax .bsl .languageserver .codelenses ;
2323
2424import com .github ._1c_syntax .bsl .languageserver .configuration .LanguageServerConfiguration ;
25- import com .github ._1c_syntax .bsl .languageserver .configuration .codelens . TestRunnerAdapterOptions ;
25+ import com .github ._1c_syntax .bsl .languageserver .configuration .events . LanguageServerConfigurationChangedEvent ;
2626import com .github ._1c_syntax .bsl .languageserver .context .DocumentContext ;
2727import com .github ._1c_syntax .bsl .languageserver .context .FileType ;
2828import com .github ._1c_syntax .bsl .languageserver .events .LanguageServerInitializeRequestReceivedEvent ;
2929import com .github ._1c_syntax .utils .Absolute ;
3030import lombok .RequiredArgsConstructor ;
3131import org .eclipse .lsp4j .ClientInfo ;
3232import org .eclipse .lsp4j .InitializeParams ;
33+ import org .springframework .cache .annotation .CacheConfig ;
34+ import org .springframework .cache .annotation .CacheEvict ;
35+ import org .springframework .cache .annotation .Cacheable ;
3336import org .springframework .context .event .EventListener ;
3437
3538import java .net .URI ;
3942import java .util .stream .Collectors ;
4043
4144@ RequiredArgsConstructor
45+ @ CacheConfig (cacheNames = "testIds" )
4246public abstract class AbstractRunTestsCodeLensSupplier <T extends CodeLensData >
4347 implements CodeLensSupplier <T > {
4448
@@ -54,6 +58,7 @@ public abstract class AbstractRunTestsCodeLensSupplier<T extends CodeLensData>
5458 * @param event Событие
5559 */
5660 @ EventListener
61+ @ CacheEvict (allEntries = true )
5762 public void handleEvent (LanguageServerInitializeRequestReceivedEvent event ) {
5863 var clientName = Optional .of (event )
5964 .map (LanguageServerInitializeRequestReceivedEvent ::getParams )
@@ -63,25 +68,35 @@ public void handleEvent(LanguageServerInitializeRequestReceivedEvent event) {
6368 clientIsSupported = "Visual Studio Code" .equals (clientName );
6469 }
6570
71+ @ EventListener
72+ @ CacheEvict (allEntries = true )
73+ public void handleLanguageServerConfigurationChange (LanguageServerConfigurationChangedEvent event ) {
74+ }
75+
6676 /**
6777 * {@inheritDoc}
6878 */
6979 @ Override
80+ @ Cacheable
7081 public boolean isApplicable (DocumentContext documentContext ) {
82+ var uri = documentContext .getUri ();
83+ var testSources = getTestSources (documentContext );
84+
85+ return documentContext .getFileType () == FileType .OS
86+ && testSources .stream ().anyMatch (testSource -> isInside (uri , testSource ))
87+ && clientIsSupported ;
88+ }
89+
90+ public Set <URI > getTestSources (DocumentContext documentContext ) {
7191 var configurationRoot = Optional .ofNullable (documentContext .getServerContext ().getConfigurationRoot ())
7292 .map (Path ::toString )
7393 .orElse ("" );
74- var uri = documentContext .getUri ();
7594
76- var testSources = configuration .getCodeLensOptions ().getTestRunnerAdapterOptions ().getTestSources ()
95+ return configuration .getCodeLensOptions ().getTestRunnerAdapterOptions ().getTestSources ()
7796 .stream ()
7897 .map (testDir -> Path .of (configurationRoot , testDir ))
7998 .map (path -> Absolute .path (path ).toUri ())
8099 .collect (Collectors .toSet ());
81-
82- return documentContext .getFileType () == FileType .OS
83- && testSources .stream ().anyMatch (testSource -> isInside (uri , testSource ))
84- && clientIsSupported ;
85100 }
86101
87102 private static boolean isInside (URI childURI , URI parentURI ) {
0 commit comments