use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class GenerateStandardRegionsSupplier method getRegionsLanguage.
private ScriptVariant getRegionsLanguage(DocumentContext documentContext, FileType fileType) {
ScriptVariant regionsLanguage;
Configuration configuration = documentContext.getServerContext().getConfiguration();
if (configuration.getConfigurationSource() == ConfigurationSource.EMPTY || fileType == FileType.OS) {
regionsLanguage = getScriptVariantFromConfigLanguage();
} else {
regionsLanguage = documentContext.getServerContext().getConfiguration().getScriptVariant();
}
return regionsLanguage;
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class QuickFixCodeActionSupplier method getCodeActionsByDiagnostic.
private List<CodeAction> getCodeActionsByDiagnostic(Diagnostic diagnostic, CodeActionParams params, DocumentContext documentContext) {
Optional<Class<? extends QuickFixProvider>> quickFixClass = quickFixSupplier.getQuickFixClass(diagnostic.getCode());
if (quickFixClass.isEmpty()) {
return Collections.emptyList();
}
Class<? extends QuickFixProvider> quickFixProviderClass = quickFixClass.get();
QuickFixProvider quickFixInstance = quickFixSupplier.getQuickFixInstance(quickFixProviderClass);
return quickFixInstance.getQuickFixes(Collections.singletonList(diagnostic), params, documentContext);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class DocumentContextLazyDataMeasurer method handleEvent.
/**
* Обработчик события {@link DocumentContextContentChangedEvent}. Вызывает основную логику выполнения замеров.
*
* @param event Событие
*/
@EventListener
@Order
@SneakyThrows
public void handleEvent(DocumentContextContentChangedEvent event) {
var documentContext = event.getSource();
LOGGER.debug("Take measurements for {}", documentContext.getUri());
measureCollector.measureIt(documentContext::getAst, "context: ast");
measureCollector.measureIt(documentContext::getQueries, "context: queries");
for (SDBLTokenizer sdblTokenizer : documentContext.getQueries()) {
measureCollector.measureIt(sdblTokenizer::getAst, "context: queryAst");
}
measureCollector.measureIt(documentContext::getSymbolTree, "context: symbolTree");
measureCollector.measureIt(documentContext::getDiagnosticIgnorance, "context: diagnosticIgnorance");
measureCollector.measureIt(documentContext::getCognitiveComplexityData, "context: cognitiveComplexity");
measureCollector.measureIt(documentContext::getCyclomaticComplexityData, "context: cyclomaticComplexity");
measureCollector.measureIt(documentContext::getMetrics, "context: metrics");
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project sonar-bsl-plugin-community by 1c-syntax.
the class BSLCoreSensor method processFile.
private void processFile(InputFile inputFile, ServerContext bslServerContext) {
URI uri = inputFile.uri();
String content;
try {
content = IOUtils.toString(inputFile.inputStream(), StandardCharsets.UTF_8);
} catch (IOException e) {
LOGGER.warn("Can't read content of file " + uri, e);
content = "";
}
DocumentContext documentContext = bslServerContext.addDocument(uri, content, 1);
if (langServerEnabled) {
documentContext.getDiagnostics().forEach(diagnostic -> issuesLoader.createIssue(inputFile, diagnostic));
}
saveCpd(inputFile, documentContext);
highlighter.saveHighlighting(inputFile, documentContext);
saveMeasures(inputFile, documentContext);
documentContext.clearSecondaryData();
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project sonar-bsl-plugin-community by 1c-syntax.
the class BSLHighlighter method saveHighlighting.
public void saveHighlighting(InputFile inputFile, DocumentContext documentContext) {
Set<HighlightingData> highlightingData = new HashSet<>(documentContext.getTokens().size());
// populate bsl highlight data
documentContext.getTokens().forEach(token -> highlightToken(token, highlightingData, getTypeOfTextBSL(token.getType())));
// compute and populate sdbl highlight data
Map<Integer, List<Token>> queryTokens = documentContext.getQueries().stream().map(Tokenizer::getTokens).flatMap(Collection::stream).collect(Collectors.groupingBy(Token::getLine));
Map<Integer, Set<HighlightingData>> highlightingDataSDBL = new HashMap<>(queryTokens.size());
queryTokens.values().stream().flatMap(Collection::stream).forEach(token -> highlightToken(token, highlightingDataSDBL.computeIfAbsent(token.getLine(), BSLHighlighter::newHashSet), getTypeOfTextSDBL(token.getType())));
// find bsl strings to check overlap with sdbl tokens
Set<HighlightingData> strings = highlightingData.stream().filter(data -> data.getType() == TypeOfText.STRING).collect(Collectors.toSet());
strings.forEach((HighlightingData string) -> {
Range stringRange = string.getRange();
// find overlapping tokens
Set<HighlightingData> dataOfCurrentLine = highlightingDataSDBL.get(stringRange.getStart().getLine());
if (Objects.isNull(dataOfCurrentLine)) {
return;
}
List<HighlightingData> currentTokens = dataOfCurrentLine.stream().filter(sdblData -> Ranges.containsRange(stringRange, sdblData.getRange())).sorted(Comparator.comparing(data -> data.getRange().getStart().getCharacter())).collect(Collectors.toList());
if (currentTokens.isEmpty()) {
return;
}
// disable current bsl token
string.setActive(false);
// split current bsl token to parts excluding sdbl tokens
Position start = stringRange.getStart();
int line = start.getLine();
int startChar;
int endChar = start.getCharacter();
for (HighlightingData currentToken : currentTokens) {
startChar = endChar;
endChar = currentToken.getRange().getStart().getCharacter();
TypeOfText typeOfText = string.getType();
if (startChar < endChar) {
// add string part
highlightingData.add(new HighlightingData(line, startChar, endChar, typeOfText));
}
endChar = currentToken.getRange().getEnd().getCharacter();
}
// add final string part
startChar = endChar;
endChar = string.getRange().getEnd().getCharacter();
TypeOfText typeOfText = string.getType();
if (startChar < endChar) {
highlightingData.add(new HighlightingData(line, startChar, endChar, typeOfText));
}
});
// merge collected bsl tokens with sdbl tokens
highlightingDataSDBL.values().forEach(highlightingData::addAll);
if (highlightingData.stream().filter(HighlightingData::isActive).findAny().isEmpty()) {
return;
}
// save only active tokens
NewHighlighting highlighting = context.newHighlighting().onFile(inputFile);
highlightingData.stream().filter(HighlightingData::isActive).forEach(data -> highlighting.highlight(data.getRange().getStart().getLine(), data.getRange().getStart().getCharacter(), data.getRange().getEnd().getLine(), data.getRange().getEnd().getCharacter(), data.getType()));
highlighting.save();
}
Aggregations