use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class AbstractDiagnosticTest method getQuickFixes.
protected List<CodeAction> getQuickFixes(Range range) {
DocumentContext documentContext = getDocumentContext();
List<Diagnostic> diagnostics = this.diagnosticInstance.getDiagnostics(documentContext);
return getQuickFixes(documentContext, diagnostics, range);
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class ConsecutiveEmptyLinesDiagnosticTest method checkQuickFixes.
private void checkQuickFixes(String module, boolean haveFix) {
final DocumentContext documentContext = TestUtils.getDocumentContext(module);
List<Diagnostic> diagnostics = getDiagnostics(documentContext);
diagnostics.forEach(diagnostic -> checkFix(documentContext, diagnostic, haveFix));
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class DeprecatedTypeManagedFormDiagnosticTest method testQuickFix.
@Test
void testQuickFix() {
final DocumentContext documentContext = getDocumentContext();
List<Diagnostic> diagnostics = getDiagnostics();
final Diagnostic ruDiagnostic = diagnostics.get(0);
List<CodeAction> quickFixes = getQuickFixes(ruDiagnostic);
assertThat(quickFixes).hasSize(1);
final CodeAction quickFix = quickFixes.get(0);
assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(ruDiagnostic);
assertThat(quickFix).in(documentContext).hasChanges(1).hasNewText("\"ФормаКлиентскогоПриложения\"");
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.
the class AnalyzeCommand method getFileInfoFromFile.
private FileInfo getFileInfoFromFile(Path srcDir, File file) {
String textDocumentContent;
try {
textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
DocumentContext documentContext = context.addDocument(file.toURI(), textDocumentContent, 1);
Path filePath = srcDir.relativize(Absolute.path(file));
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
String mdoRef = "";
Optional<AbstractMDObjectBase> mdObjectBase = documentContext.getMdObject();
if (mdObjectBase.isPresent()) {
mdoRef = mdObjectBase.get().getMdoReference().getMdoRef();
}
FileInfo fileInfo = new FileInfo(filePath, mdoRef, diagnostics, metrics);
// clean up AST after diagnostic computing to free up RAM.
documentContext.clearSecondaryData();
return fileInfo;
}
use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics 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;
}
Aggregations