Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes & bumps #3233

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ dependencies {
exclude("org.antlr", "antlr-runtime")
}
api("com.github.1c-syntax", "utils", "0.5.2")
api("io.github.1c-syntax", "mdclasses", "0.12.0")
api("io.github.1c-syntax", "bsl-common-library", "0.5.0")
api("io.github.1c-syntax", "supportconf", "0.12.1")
api("io.github.1c-syntax", "mdclasses", "0.13.0-rc.1")
api("io.github.1c-syntax", "bsl-common-library", "0.5.1")
api("io.github.1c-syntax", "supportconf", "0.13.1")
api("io.github.1c-syntax", "bsl-parser-core", "0.1.0")

// JLanguageTool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class CfgBuildingParseTreeVisitor extends BSLParserBaseVisitor<ParseTree> {

Expand Down Expand Up @@ -148,12 +147,12 @@ public ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) {

while (!currentLevelBlock.getBuildParts().isEmpty()) {
var blockTail = currentLevelBlock.getBuildParts().pop();
if (hasNoSignificantEdges(blockTail) && blockTail instanceof BasicBlockVertex) {
// это мертвый код. Он может быть пустым блоком
// тогда он не нужен сам по себе
var basicBlock = (BasicBlockVertex) blockTail;
if (basicBlock.statements().isEmpty())
continue;
// это мертвый код. Он может быть пустым блоком
// тогда он не нужен сам по себе
if (hasNoSignificantEdges(blockTail)
&& blockTail instanceof BasicBlockVertex basicBlock
&& basicBlock.statements().isEmpty()) {
continue;
}
graph.addEdge(blockTail, upperBlock.end());
}
Expand All @@ -163,7 +162,9 @@ public ParseTree visitIfStatement(BSLParser.IfStatementContext ctx) {

private boolean hasNoSignificantEdges(CfgVertex blockTail) {
var edges = graph.incomingEdgesOf(blockTail);
return edges.isEmpty() || (adjacentDeadCodeEnabled && edges.stream().allMatch(x -> x.getType() == CfgEdgeType.ADJACENT_CODE));
return edges.isEmpty()
|| (adjacentDeadCodeEnabled
&& edges.stream().allMatch(x -> x.getType() == CfgEdgeType.ADJACENT_CODE));
theshadowco marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down Expand Up @@ -372,8 +373,9 @@ public ParseTree visitPreproc_if(BSLParser.Preproc_ifContext ctx) {
return ctx;
}

if (!isStatementLevelPreproc(ctx))
if (!isStatementLevelPreproc(ctx)) {
return super.visitPreproc_if(ctx);
}

var node = new PreprocessorConditionVertex(ctx);
graph.addVertex(node);
Expand Down Expand Up @@ -477,14 +479,15 @@ public ParseTree visitPreproc_endif(BSLParser.Preproc_endifContext ctx) {
// присоединяем все прямые выходы из тел условий
while (!mainIf.getBuildParts().isEmpty()) {
var blockTail = mainIf.getBuildParts().pop();
if (hasNoSignificantEdges(blockTail) && blockTail instanceof BasicBlockVertex) {
// это мертвый код. Он может быть пустым блоком
// тогда он не нужен сам по себе
var basicBlock = (BasicBlockVertex) blockTail;
if (basicBlock.statements().isEmpty()) {
graph.removeVertex(basicBlock);
continue;
}

// это мертвый код. Он может быть пустым блоком
// тогда он не нужен сам по себе
if (hasNoSignificantEdges(blockTail)
&& blockTail instanceof BasicBlockVertex basicBlock
&& basicBlock.statements().isEmpty()) {

graph.removeVertex(basicBlock);
continue;
}
graph.addVertex(blockTail);
graph.addEdge(blockTail, upperBlock.end());
Expand All @@ -493,15 +496,15 @@ public ParseTree visitPreproc_endif(BSLParser.Preproc_endifContext ctx) {
return ctx;
}

private boolean isStatementLevelPreproc(BSLParserRuleContext ctx) {
private static boolean isStatementLevelPreproc(BSLParserRuleContext ctx) {
return ctx.getParent().getParent().getRuleIndex() == BSLParser.RULE_statement;
}

private PreprocessorConditionVertex popPreprocCondition() {
var node = blocks.getCurrentBlock().getBuildParts().peek();
if (node instanceof PreprocessorConditionVertex) {
if (node instanceof PreprocessorConditionVertex preprocessorConditionVertex) {
blocks.getCurrentBlock().getBuildParts().pop();
return (PreprocessorConditionVertex) node;
return preprocessorConditionVertex;
}
return null;
}
Expand Down Expand Up @@ -545,12 +548,11 @@ private void buildLoopSubgraph(BSLParser.CodeBlockContext ctx, LoopVertex loopSt

private void connectGraphTail(StatementsBlockWriter.StatementsBlockRecord currentBlock, CfgVertex vertex) {

if (!(currentBlock.end() instanceof BasicBlockVertex)) {
if (!(currentBlock.end() instanceof BasicBlockVertex currentTail)) {
theshadowco marked this conversation as resolved.
Show resolved Hide resolved
graph.addEdge(currentBlock.end(), vertex);
return;
}

var currentTail = (BasicBlockVertex) currentBlock.end();
if (currentTail.statements().isEmpty()) {
// перевести все связи на новую вершину
var incoming = graph.incomingEdgesOf(currentTail);
Expand All @@ -575,17 +577,17 @@ private void connectGraphTail(StatementsBlockWriter.StatementsBlockRecord curren
private void removeOrphanedNodes() {
var orphans = graph.vertexSet().stream()
.filter(vertex -> !(vertex instanceof ExitVertex))
.filter(vertex -> {
.filter((CfgVertex vertex) -> {
var edges = new ArrayList<>(graph.edgesOf(vertex));

return edges.isEmpty() ||
adjacentDeadCodeEnabled &&
edges.size() == 1
&& edges.get(0).getType() == CfgEdgeType.ADJACENT_CODE
&& graph.getEdgeTarget(edges.get(0)) == vertex;
return edges.isEmpty()
|| (adjacentDeadCodeEnabled
&& edges.size() == 1
&& edges.get(0).getType() == CfgEdgeType.ADJACENT_CODE
&& graph.getEdgeTarget(edges.get(0)) == vertex);
theshadowco marked this conversation as resolved.
Show resolved Hide resolved

})
.collect(Collectors.toList());
.toList();

// в одном стриме бывает ConcurrentModificationException
// делаем через другую коллекцию
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import lombok.Setter;
import org.jgrapht.graph.DefaultDirectedGraph;

@Getter
public class ControlFlowGraph extends DefaultDirectedGraph<CfgVertex, CfgEdge> {

@Getter
@Setter
private CfgVertex entryPoint;

@Getter
private ExitVertex exitPoint;

ControlFlowGraph() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.github._1c_syntax.bsl.languageserver.cfg;

import com.github._1c_syntax.bsl.parser.BSLParserRuleContext;
import lombok.Getter;

import java.util.ArrayDeque;
import java.util.Deque;
Expand All @@ -42,6 +43,8 @@ static class StatementsBlockRecord {

private BasicBlockVertex statements = new BasicBlockVertex();
private final Deque<CfgVertex> buildStack = new ArrayDeque<>();

@Getter
private final JumpInformationRecord jumpContext;

public StatementsBlockRecord() {
Expand All @@ -62,10 +65,6 @@ public Deque<CfgVertex> getBuildParts() {
return buildStack;
}

public JumpInformationRecord getJumpContext() {
return jumpContext;
}

public void split() {
if (subgraphBegin instanceof BasicBlockVertex && subgraphBegin == subgraphEnd) {
subgraphBegin = statements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package com.github._1c_syntax.bsl.languageserver.cli;

import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.context.MetricStorage;
import com.github._1c_syntax.bsl.languageserver.context.ServerContext;
import com.github._1c_syntax.bsl.languageserver.reporters.ReportersAggregator;
import com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo;
Expand All @@ -37,7 +36,6 @@
import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
import org.apache.commons.io.FileUtils;
import org.eclipse.lsp4j.Diagnostic;
import org.springframework.stereotype.Component;
import picocli.CommandLine.Command;

Expand Down Expand Up @@ -132,7 +130,7 @@
paramLabel = "<keys>",
completionCandidates = ReportersKeys.class,
description = "Reporter key (${COMPLETION-CANDIDATES})")
private String[] reportersOptions = {};

Check warning on line 133 in src/main/java/com/github/_1c_syntax/bsl/languageserver/cli/AnalyzeCommand.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Mismatched read and write of array

Contents of array `reportersOptions` are read, but never written to

@Option(
names = {"-q", "--silent"},
Expand Down Expand Up @@ -205,8 +203,8 @@
context.rebuildDocument(documentContext);

var filePath = srcDir.relativize(Absolute.path(file));
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
var diagnostics = documentContext.getDiagnostics();
var metrics = documentContext.getMetrics();
var mdoRef = documentContext.getMdObject()
.map(MD::getMdoReference)
.map(MdoReference::getMdoRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.bsl.parser.BSLParserRuleContext;
import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionKind;
Expand All @@ -44,12 +43,10 @@
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -80,16 +77,14 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
return Collections.emptyList();
}

var doCall = maybeDoCall.get();

List<BSLParser.CallParamContext> parameters = maybeDoCall
var parameters = maybeDoCall
.map(BSLParser.DoCallContext::callParamList)
.map(callParamListContext -> callParamListContext.children)
.orElse(Collections.emptyList())
.stream()
.flatMap(Collection::stream)
.filter(Predicate.not(TerminalNode.class::isInstance))
.map(BSLParser.CallParamContext.class::cast)
.collect(Collectors.toList());
.toList();

if (parameters.isEmpty()) {
return Collections.emptyList();
Expand All @@ -105,6 +100,7 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
return Collections.emptyList();
}

var doCall = maybeDoCall.get();
theshadowco marked this conversation as resolved.
Show resolved Hide resolved
var assignment = (BSLParser.AssignmentContext) Trees.getAncestorByRuleIndex(doCall, BSLParser.RULE_assignment);
if (assignment == null || isParentAssignment(doCall, assignment)) {
return Collections.emptyList();
Expand All @@ -118,24 +114,24 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
var lValueName = lValue.getText();
var insert = Resources.getResourceString(configuration.getLanguage(), getClass(), "insert");

String[] keys = Strings.trimQuotes(firstToken.getText()).split(",");
var keys = Strings.trimQuotes(firstToken.getText()).split(",");
theshadowco marked this conversation as resolved.
Show resolved Hide resolved
var workspaceEdit = new WorkspaceEdit();
var changes = new ArrayList<TextEdit>();

var constructorEdit = new TextEdit(Ranges.create(doCall), "()");
changes.add(constructorEdit);

int intendSize = Ranges.create(lValue).getStart().getCharacter();
var indentSize = Ranges.create(lValue).getStart().getCharacter();

var rparenRange = Ranges.create(doCall.RPAREN());
var constructorLine = rparenRange.getEnd().getLine();
var position = new Position(constructorLine + 1, 0);
var range = new Range(position, position);

var indent = documentContext.getContentList()[constructorLine].substring(0, intendSize);
var indent = documentContext.getContentList()[constructorLine].substring(0, indentSize);

for (var i = 0; i < keys.length; i++) {
String key = keys[i].trim();
var key = keys[i].trim();
theshadowco marked this conversation as resolved.
Show resolved Hide resolved
var value = "";
var separator = "";
if (parameters.size() > i + 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@
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.context.symbol.MethodSymbol;
import com.github._1c_syntax.bsl.languageserver.events.LanguageServerInitializeRequestReceivedEvent;
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;
import org.eclipse.lsp4j.ClientInfo;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.InitializeParams;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.beans.ConstructorProperties;
theshadowco marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
package com.github._1c_syntax.bsl.languageserver.color;

import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.utils.bsl.Constructors;
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
import com.github._1c_syntax.bsl.languageserver.utils.Trees;
import com.github._1c_syntax.bsl.languageserver.utils.bsl.Constructors;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.utils.CaseInsensitivePattern;
import org.antlr.v4.runtime.Token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Язык для сообщений, ресурсов и прочих взаимодействий между
* BSL Language Server и пользователем.
*/
@Getter
public enum Language {

/**
Expand All @@ -49,13 +50,11 @@ public enum Language {
/**
* Код языка в соответствии с {@link java.util.Locale#getLanguage()}.
*/
@Getter
private final String languageCode;

/**
* Локаль языка.
*/
@Getter
private final Locale locale;

/**
Expand Down
Loading
Loading