Skip to content

Commit

Permalink
Убран самопальный кэш. Добавлена очистка кэша при смене конфигурации
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Jan 19, 2025
1 parent db12e51 commit c05d94c
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.github._1c_syntax.bsl.languageserver.codelenses.testrunner;

import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.configuration.events.LanguageServerConfigurationChangedEvent;
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
import com.github._1c_syntax.bsl.languageserver.context.symbol.annotations.Annotation;
Expand All @@ -34,7 +35,10 @@
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand All @@ -44,8 +48,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -56,26 +58,26 @@
@Component
@RequiredArgsConstructor
@Slf4j
@CacheConfig(cacheNames = "testIds")
public class TestRunnerAdapter {

private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\r?\n");
private static final Map<Pair<DocumentContext, Integer>, List<String>> CACHE = new WeakHashMap<>();

private final LanguageServerConfiguration configuration;

@EventListener
@CacheEvict(allEntries = true)
public void handleEvent(LanguageServerConfigurationChangedEvent event) {
}

/**
* Получить идентификаторы тестов, содержащихся в файле.
*
* @param documentContext Контекст документа с тестами.
* @return Список идентификаторов тестов.
*/
@Cacheable
public List<String> getTestIds(DocumentContext documentContext) {
var cacheKey = Pair.of(documentContext, documentContext.getVersion());

return CACHE.computeIfAbsent(cacheKey, pair -> computeTestIds(documentContext));
}

private List<String> computeTestIds(DocumentContext documentContext) {
var options = configuration.getCodeLensOptions().getTestRunnerAdapterOptions();

if (options.isGetTestsByTestRunner()) {
Expand Down Expand Up @@ -137,7 +139,7 @@ private List<String> computeTestIdsByTestRunner(DocumentContext documentContext)
.toList();
}

private List<String> computeTestIdsByLanguageServer(DocumentContext documentContext) {
private static List<String> computeTestIdsByLanguageServer(DocumentContext documentContext) {
return documentContext.getSymbolTree()
.getMethods()
.stream()
Expand Down

0 comments on commit c05d94c

Please sign in to comment.