use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo in project bsl-language-server by 1c-syntax.
the class CodeActionProviderTest method testOnly.
@Test
void testOnly() {
// given
CodeActionParams params = new CodeActionParams();
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(CanonicalSpellingKeywordsDiagnostic.class, configuration);
DiagnosticCode diagnosticCode = diagnosticInfo.getCode();
List<Diagnostic> diagnostics = documentContext.getDiagnostics().stream().filter(diagnostic -> diagnostic.getCode().equals(diagnosticCode)).collect(Collectors.toList());
CodeActionContext codeActionContext = new CodeActionContext();
codeActionContext.setOnly(List.of(CodeActionKind.Refactor));
codeActionContext.setDiagnostics(diagnostics);
params.setRange(new Range());
params.setTextDocument(textDocumentIdentifier);
params.setContext(codeActionContext);
// when
List<Either<Command, CodeAction>> codeActions = codeActionProvider.getCodeActions(params, documentContext);
// then
assertThat(codeActions).extracting(Either::getRight).extracting(CodeAction::getKind).containsOnly(CodeActionKind.Refactor);
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo in project sonar-bsl-plugin-community by 1c-syntax.
the class BSLCoreSensor method getLanguageServerConfiguration.
private LanguageServerConfiguration getLanguageServerConfiguration() {
boolean overrideConfiguration = context.config().get(BSLCommunityProperties.LANG_SERVER_OVERRIDE_CONFIGURATION_KEY).map(Boolean::parseBoolean).orElse(BSLCommunityProperties.LANG_SERVER_OVERRIDE_CONFIGURATION_DEFAULT_VALUE);
var configuration = BSLLSBinding.getLanguageServerConfiguration();
if (overrideConfiguration) {
String configurationPath = context.config().get(BSLCommunityProperties.LANG_SERVER_CONFIGURATION_PATH_KEY).orElse(BSLCommunityProperties.LANG_SERVER_CONFIGURATION_PATH_DEFAULT_VALUE);
File configurationFile = new File(configurationPath);
if (configurationFile.exists()) {
LOGGER.info("BSL LS configuration file exists. Overriding SonarQube rules' settings...");
configuration.update(configurationFile);
return configuration;
} else {
LOGGER.error("Can't find bsl configuration file {}. Using SonarQube config instead.", configurationPath);
}
}
String diagnosticLanguageCode = context.config().get(BSLCommunityProperties.LANG_SERVER_DIAGNOSTIC_LANGUAGE_KEY).orElse(BSLCommunityProperties.LANG_SERVER_DIAGNOSTIC_LANGUAGE_DEFAULT_VALUE);
configuration.setLanguage(Language.valueOf(diagnosticLanguageCode.toUpperCase(Locale.ENGLISH)));
SkipSupport skipSupport = context.config().get(BSLCommunityProperties.LANG_SERVER_COMPUTE_DIAGNOSTICS_SKIP_SUPPORT_KEY).map(value -> value.toUpperCase(Locale.ENGLISH).replace(" ", "_")).map(SkipSupport::valueOf).orElse(SkipSupport.valueOf(BSLCommunityProperties.LANG_SERVER_COMPUTE_DIAGNOSTICS_SKIP_SUPPORT_DEFAULT_VALUE.toUpperCase(Locale.ENGLISH)));
configuration.getDiagnosticsOptions().setSkipSupport(skipSupport);
ActiveRules activeRules = context.activeRules();
Map<String, Either<Boolean, Map<String, Object>>> diagnostics = new HashMap<>();
Collection<DiagnosticInfo> diagnosticInfos = BSLLSBinding.getDiagnosticInfos();
for (DiagnosticInfo diagnosticInfo : diagnosticInfos) {
String diagnosticCode = diagnosticInfo.getCode().getStringValue();
ActiveRule activeRule = activeRules.find(RuleKey.of(BSLLanguageServerRuleDefinition.REPOSITORY_KEY, diagnosticCode));
if (activeRule == null) {
diagnostics.put(diagnosticCode, Either.forLeft(false));
} else {
Map<String, String> params = activeRule.params();
List<DiagnosticParameterInfo> diagnosticParameters = diagnosticInfo.getParameters();
Map<String, Object> diagnosticConfiguration = new HashMap<>(diagnosticParameters.size());
params.forEach((String key, String value) -> diagnosticInfo.getParameter(key).ifPresent(diagnosticParameterInfo -> diagnosticConfiguration.put(key, castDiagnosticParameterValue(value, diagnosticParameterInfo.getType()))));
diagnostics.put(diagnosticCode, Either.forRight(diagnosticConfiguration));
}
}
configuration.getDiagnosticsOptions().setParameters(diagnostics);
return configuration;
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo in project bsl-language-server by 1c-syntax.
the class DiagnosticsConfiguration method diagnostics.
@Bean
@Scope("prototype")
public List<BSLDiagnostic> diagnostics(DocumentContext documentContext) {
Collection<DiagnosticInfo> diagnosticInfos = diagnosticInfos();
DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
if (needToComputeDiagnostics(documentContext, diagnosticsOptions)) {
FileType fileType = documentContext.getFileType();
CompatibilityMode compatibilityMode = documentContext.getServerContext().getConfiguration().getCompatibilityMode();
ModuleType moduleType = documentContext.getModuleType();
return diagnosticInfos.stream().filter(diagnosticInfo -> isEnabled(diagnosticInfo, diagnosticsOptions)).filter(info -> inScope(info, fileType)).filter(info -> correctModuleType(info, moduleType, fileType)).filter(info -> passedCompatibilityMode(info, compatibilityMode)).map(DiagnosticInfo::getDiagnosticClass).map(diagnosticObjectProvider::get).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo in project bsl-language-server by 1c-syntax.
the class DiagnosticsConfiguration method inScope.
private static boolean inScope(DiagnosticInfo diagnosticInfo, FileType fileType) {
DiagnosticScope scope = diagnosticInfo.getScope();
DiagnosticScope fileScope;
if (fileType == FileType.OS) {
fileScope = DiagnosticScope.OS;
} else {
fileScope = DiagnosticScope.BSL;
}
return scope == DiagnosticScope.ALL || scope == fileScope;
}
use of com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo in project bsl-language-server by 1c-syntax.
the class DiagnosticsConfiguration method correctModuleType.
private static boolean correctModuleType(DiagnosticInfo diagnosticInfo, ModuleType moduletype, FileType fileType) {
if (fileType == FileType.OS) {
return true;
}
ModuleType[] diagnosticModules = diagnosticInfo.getModules();
if (diagnosticModules.length == 0) {
return true;
}
boolean contain = false;
for (ModuleType module : diagnosticModules) {
if (module == moduletype) {
contain = true;
break;
}
}
return contain;
}
Aggregations