Skip to content

Commit

Permalink
Подключен spring cache. Добавлено кэширование результатов применимост…
Browse files Browse the repository at this point in the history
…и линз на файл.
  • Loading branch information
nixel2007 committed Jan 19, 2025
1 parent 5bfc959 commit 5df4864
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
// spring
api("org.springframework.boot:spring-boot-starter")
api("org.springframework.boot:spring-boot-starter-websocket")
api("org.springframework.boot:spring-boot-starter-cache")
api("info.picocli:picocli-spring-boot-starter:4.7.6")

// lsp4j core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
package com.github._1c_syntax.bsl.languageserver.codelenses;

import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.configuration.codelens.TestRunnerAdapterOptions;
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.FileType;
import com.github._1c_syntax.bsl.languageserver.events.LanguageServerInitializeRequestReceivedEvent;
import com.github._1c_syntax.utils.Absolute;
import lombok.RequiredArgsConstructor;
import org.eclipse.lsp4j.ClientInfo;
import org.eclipse.lsp4j.InitializeParams;
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 java.net.URI;
Expand All @@ -39,6 +42,7 @@
import java.util.stream.Collectors;

@RequiredArgsConstructor
@CacheConfig(cacheNames = "testIds")
public abstract class AbstractRunTestsCodeLensSupplier<T extends CodeLensData>
implements CodeLensSupplier<T> {

Expand All @@ -54,6 +58,7 @@ public abstract class AbstractRunTestsCodeLensSupplier<T extends CodeLensData>
* @param event Событие
*/
@EventListener
@CacheEvict(allEntries = true)
public void handleEvent(LanguageServerInitializeRequestReceivedEvent event) {
var clientName = Optional.of(event)
.map(LanguageServerInitializeRequestReceivedEvent::getParams)
Expand All @@ -63,25 +68,35 @@ public void handleEvent(LanguageServerInitializeRequestReceivedEvent event) {
clientIsSupported = "Visual Studio Code".equals(clientName);
}

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

/**
* {@inheritDoc}
*/
@Override
@Cacheable
public boolean isApplicable(DocumentContext documentContext) {
var uri = documentContext.getUri();
var testSources = getTestSources(documentContext);

return documentContext.getFileType() == FileType.OS
&& testSources.stream().anyMatch(testSource -> isInside(uri, testSource))
&& clientIsSupported;
}

public Set<URI> getTestSources(DocumentContext documentContext) {
var configurationRoot = Optional.ofNullable(documentContext.getServerContext().getConfigurationRoot())
.map(Path::toString)
.orElse("");
var uri = documentContext.getUri();

var testSources = configuration.getCodeLensOptions().getTestRunnerAdapterOptions().getTestSources()
return configuration.getCodeLensOptions().getTestRunnerAdapterOptions().getTestSources()
.stream()
.map(testDir -> Path.of(configurationRoot, testDir))
.map(path -> Absolute.path(path).toUri())
.collect(Collectors.toSet());

return documentContext.getFileType() == FileType.OS
&& testSources.stream().anyMatch(testSource -> isInside(uri, testSource))
&& clientIsSupported;
}

private static boolean isInside(URI childURI, URI parentURI) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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.utils.Resources;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -43,7 +42,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Поставщик линз для запуска теста по конкретному тестовому методу.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2025
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* BSL Language Server is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* BSL Language Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BSL Language Server.
*/
package com.github._1c_syntax.bsl.languageserver.infrastructure;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class CacheConfiguration {
}

0 comments on commit 5df4864

Please sign in to comment.