Skip to content

Commit

Permalink
Merge pull request #1364 from 1c-syntax/develop
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
nixel2007 authored Sep 18, 2020
2 parents 1bacc56 + f8146b6 commit a795230
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.context.ServerContext;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo;
import lombok.AccessLevel;
import lombok.Getter;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.io.DefaultResourceLoader;

Expand All @@ -40,16 +42,27 @@
@ComponentScan("com.github._1c_syntax.bsl.languageserver")
public class BSLLSBinding {

@Getter(lazy = true)
private static final ApplicationContext applicationContext = createContext();
@Getter(lazy = true, value = AccessLevel.PRIVATE)
private static final SpringApplication application = createApplication();
@Getter(lazy = true, value = AccessLevel.PRIVATE)
private static final ConfigurableApplicationContext context = createContext();

public BSLLSBinding() {
// public constructor is needed for spring initialization
}

public static ConfigurableApplicationContext getApplicationContext() {
var context = getContext();
if (!context.isActive()) {
context = createContext();
}

return context;
}

@SuppressWarnings("unchecked")
public static Collection<DiagnosticInfo> getDiagnosticInfos() {
return (Collection<DiagnosticInfo>) getApplicationContext().getBean("diagnosticInfos", Collection.class);
return getApplicationContext().getBean("diagnosticInfos", Collection.class);
}

public static LanguageServerConfiguration getLanguageServerConfiguration() {
Expand All @@ -60,7 +73,7 @@ public static ServerContext getServerContext() {
return getApplicationContext().getBean(ServerContext.class);
}

private static ApplicationContext createContext() {
private static SpringApplication createApplication() {
return new SpringApplicationBuilder(BSLLSBinding.class)
.bannerMode(Banner.Mode.OFF)
.web(WebApplicationType.NONE)
Expand All @@ -71,7 +84,10 @@ private static ApplicationContext createContext() {
"app.command.line.runner.enabled", "false",
"app.scheduling.enabled", "false"
))
.build()
.run();
.build();
}

private static ConfigurableApplicationContext createContext() {
return getApplication().run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
import com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo;
import com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo;
import lombok.Getter;
Expand All @@ -42,6 +43,13 @@

public class GenericIssueReport {

private static final Map<DiagnosticType, RuleType> diagnosticTypeRuleTypeMap = Map.of(
DiagnosticType.ERROR, RuleType.BUG,
DiagnosticType.CODE_SMELL, RuleType.CODE_SMELL,
DiagnosticType.SECURITY_HOTSPOT, RuleType.SECURITY_HOTSPOT,
DiagnosticType.VULNERABILITY, RuleType.VULNERABILITY
);

@Getter
@JsonProperty("issues")
private final List<GenericIssueEntry> issues;
Expand Down Expand Up @@ -72,7 +80,7 @@ static class GenericIssueEntry {
String engineId;
String ruleId;
String severity;
String type;
RuleType type;
Location primaryLocation;
int effortMinutes;
List<Location> secondaryLocations;
Expand All @@ -81,7 +89,7 @@ public GenericIssueEntry(
@JsonProperty("engineId") String engineId,
@JsonProperty("ruleId") String ruleId,
@JsonProperty("severity") String severity,
@JsonProperty("type") String type,
@JsonProperty("type") RuleType type,
@JsonProperty("primaryLocation") Location primaryLocation,
@JsonProperty("effortMinutes") int effortMinutes,
@JsonProperty("secondaryLocations") List<Location> secondaryLocations
Expand All @@ -99,7 +107,7 @@ public GenericIssueEntry(String fileName, Diagnostic diagnostic, DiagnosticInfo
engineId = diagnostic.getSource();
ruleId = diagnosticInfo.getCode().getStringValue();
severity = diagnosticInfo.getSeverity().name();
type = diagnosticInfo.getType().name();
type = diagnosticTypeRuleTypeMap.get(diagnosticInfo.getType());
primaryLocation = new Location(fileName, diagnostic);
effortMinutes = diagnosticInfo.getMinutesToFix();

Expand Down Expand Up @@ -176,4 +184,10 @@ public TextRange(Range range) {

}

enum RuleType {
BUG,
CODE_SMELL,
SECURITY_HOTSPOT,
VULNERABILITY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
package com.github._1c_syntax.bsl.languageserver;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
class BSLLSBindingTest {

@Test
Expand All @@ -37,4 +35,35 @@ void testGetServerContext() {
// then
assertThat(serverContext).isNotNull();
}

@Test
void testGetDiagnosticInfos() {
// when
var diagnosticInfos = BSLLSBinding.getDiagnosticInfos();

// then
assertThat(diagnosticInfos).isNotNull();
}

@Test
void testGetLanguageServerConfiguration() {
// when
var languageServerConfiguration = BSLLSBinding.getLanguageServerConfiguration();

// then
assertThat(languageServerConfiguration).isNotNull();
}

@Test
void testReactivateContext() {
// given
var applicationContext = BSLLSBinding.getApplicationContext();
applicationContext.close();

// when
applicationContext = BSLLSBinding.getApplicationContext();

// then
assertThat(applicationContext.isActive()).isTrue();
}
}

0 comments on commit a795230

Please sign in to comment.