Skip to content

Commit 5df4864

Browse files
committed
Подключен spring cache. Добавлено кэширование результатов применимости линз на файл.
1 parent 5bfc959 commit 5df4864

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
// spring
7575
api("org.springframework.boot:spring-boot-starter")
7676
api("org.springframework.boot:spring-boot-starter-websocket")
77+
api("org.springframework.boot:spring-boot-starter-cache")
7778
api("info.picocli:picocli-spring-boot-starter:4.7.6")
7879

7980
// lsp4j core

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/AbstractRunTestsCodeLensSupplier.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
package com.github._1c_syntax.bsl.languageserver.codelenses;
2323

2424
import 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;
2626
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2727
import com.github._1c_syntax.bsl.languageserver.context.FileType;
2828
import com.github._1c_syntax.bsl.languageserver.events.LanguageServerInitializeRequestReceivedEvent;
2929
import com.github._1c_syntax.utils.Absolute;
3030
import lombok.RequiredArgsConstructor;
3131
import org.eclipse.lsp4j.ClientInfo;
3232
import 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;
3336
import org.springframework.context.event.EventListener;
3437

3538
import java.net.URI;
@@ -39,6 +42,7 @@
3942
import java.util.stream.Collectors;
4043

4144
@RequiredArgsConstructor
45+
@CacheConfig(cacheNames = "testIds")
4246
public 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) {

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/RunAllTestsCodeLensSupplier.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2727
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
2828
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
29-
import lombok.RequiredArgsConstructor;
3029
import lombok.extern.slf4j.Slf4j;
3130
import org.eclipse.lsp4j.CodeLens;
3231
import org.eclipse.lsp4j.Command;

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/RunTestCodeLensSupplier.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
2929
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
3030
import lombok.EqualsAndHashCode;
31-
import lombok.RequiredArgsConstructor;
3231
import lombok.ToString;
3332
import lombok.Value;
3433
import lombok.extern.slf4j.Slf4j;
@@ -43,7 +42,6 @@
4342
import java.util.List;
4443
import java.util.Map;
4544
import java.util.Optional;
46-
import java.util.stream.Collectors;
4745

4846
/**
4947
* Поставщик линз для запуска теста по конкретному тестовому методу.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2025
5+
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.infrastructure;
23+
24+
import org.springframework.cache.annotation.EnableCaching;
25+
import org.springframework.context.annotation.Configuration;
26+
27+
@Configuration
28+
@EnableCaching
29+
public class CacheConfiguration {
30+
}

0 commit comments

Comments
 (0)