Skip to content

Commit

Permalink
rebase и восстановил работоспособность костылем
Browse files Browse the repository at this point in the history
  • Loading branch information
theshadowco committed Dec 26, 2023
1 parent 5e33760 commit 7992f30
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

import static com.github._1c_syntax.bsl.languageserver.providers.DiagnosticProvider.SOURCE;


@Component
public class DisableDiagnosticTriggeringSupplier implements CodeActionSupplier {

Expand Down Expand Up @@ -83,7 +82,7 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
.stream()
.filter(token -> token.getLine() == selectedLineNumber)
.max(Comparator.comparingInt(Token::getCharPositionInLine))
.ifPresent(token -> {
.ifPresent((Token token) -> {
if (params.getRange().getStart().getLine() == params.getRange().getEnd().getLine()) {
result.addAll(getDisableActionForLine(params, documentContext, token));
} else {
Expand Down Expand Up @@ -176,13 +175,13 @@ private List<CodeAction> actionDisableDiagnostic(Function<String, CodeAction> fu
private List<TextEdit> createInRegionTextEdits(String diagnosticName, Token last, CodeActionParams params) {
List<TextEdit> edits = new ArrayList<>();

Range disableRange = Ranges.create(
var disableRange = Ranges.create(
params.getRange().getStart().getLine(),
0,
params.getRange().getStart().getLine(),
0
);
TextEdit disableTextEdit = new TextEdit(disableRange, String.format("// BSLLS%s-off%n", diagnosticName));
var disableTextEdit = new TextEdit(disableRange, String.format("// BSLLS%s-off%n", diagnosticName));
edits.add(disableTextEdit);

Range enableRange = Ranges.create(
Expand All @@ -191,13 +190,13 @@ private List<TextEdit> createInRegionTextEdits(String diagnosticName, Token last
params.getRange().getEnd().getLine(),
last.getCharPositionInLine() + last.getText().length()
);
TextEdit enableTextEdit = new TextEdit(enableRange, String.format("%n// BSLLS%s-on%n", diagnosticName));
var enableTextEdit = new TextEdit(enableRange, String.format("%n// BSLLS%s-on%n", diagnosticName));
edits.add(enableTextEdit);
return edits;
}

private List<TextEdit> createInFileTextEdits(String diagnosticName) {
TextEdit textEdit = new TextEdit(
var textEdit = new TextEdit(
Ranges.create(0, 0, 0, 0),
String.format("// BSLLS%s-off%n", diagnosticName)
);
Expand All @@ -206,10 +205,10 @@ private List<TextEdit> createInFileTextEdits(String diagnosticName) {

private CodeAction createCodeAction(String title, List<TextEdit> edits, DocumentContext documentContext) {
Map<String, List<TextEdit>> changes = Map.of(documentContext.getUri().toString(), edits);
WorkspaceEdit edit = new WorkspaceEdit();
var edit = new WorkspaceEdit();
edit.setChanges(changes);

CodeAction codeAction = new CodeAction(title);
var codeAction = new CodeAction(title);
codeAction.setDiagnostics(new ArrayList<>());
codeAction.setKind(CodeActionKind.Refactor);
codeAction.setEdit(edit);
Expand All @@ -225,15 +224,14 @@ private String getMessage(String key, Object... args) {
}

private static List<TextEdit> createInLineTextEdits(String diagnosticName, Token last, CodeActionParams params) {
Range range = Ranges.create(
var range = Ranges.create(
params.getRange().getStart().getLine(),
last.getCharPositionInLine() + last.getText().length(),
params.getRange().getStart().getLine(),
last.getCharPositionInLine() + last.getText().length()
);

TextEdit textEdit = new TextEdit(range, String.format(" // BSLLS%s-off", diagnosticName));
var textEdit = new TextEdit(range, String.format(" // BSLLS%s-off", diagnosticName));
return Collections.singletonList(textEdit);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree;
import com.github._1c_syntax.bsl.languageserver.utils.Trees;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.Module;
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
import com.github._1c_syntax.bsl.parser.BSLLexer;
import com.github._1c_syntax.bsl.parser.BSLParser;
Expand Down Expand Up @@ -72,7 +71,6 @@
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;
import static org.antlr.v4.runtime.Token.DEFAULT_CHANNEL;
Expand Down Expand Up @@ -161,13 +159,13 @@ public List<Token> getTokens() {
}

public List<Token> getTokensFromDefaultChannel() {
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).collect(Collectors.toList());
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).toList();
}

public List<Token> getComments() {
return getTokens().stream()
.filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
.collect(Collectors.toList());
.toList();
}

public String getText(Range range) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ModuleType computeModuleType() {

private ModuleType computeBSL() {
var type = documentContext.getServerContext()
.getConfiguration().getModuleType(documentContext.getUri());
.getConfiguration().getModuleTypeByURI(documentContext.getUri());
return ModuleType.valueOf(type.name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public abstract class AbstractVariableSymbol implements VariableSymbol {
*/
Optional<VariableDescription> description;

/**
* Тип переменной
*/
String type;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void checkAllPathsHaveReturns(BSLParser.FunctionContext ctx) {
.map(graph::getEdgeSource)
.map(vertex -> nonExplicitReturnNode(vertex, graph))
.flatMap(Optional::stream)
.collect(Collectors.toList());
.toList();

if (incomingVertices.isEmpty()) {
return;
Expand All @@ -136,12 +136,12 @@ private void checkAllPathsHaveReturns(BSLParser.FunctionContext ctx) {
}

private Optional<BSLParserRuleContext> nonExplicitReturnNode(CfgVertex v, ControlFlowGraph graph) {
if (v instanceof BasicBlockVertex) {
return checkBasicBlockExitingNode((BasicBlockVertex) v);
} else if (v instanceof LoopVertex) {
return checkLoopExitingNode((LoopVertex) v);
} else if (v instanceof ConditionalVertex) {
return checkElseIfClauseExitingNode((ConditionalVertex) v, graph);
if (v instanceof BasicBlockVertex basicBlockVertex) {
return checkBasicBlockExitingNode(basicBlockVertex);
} else if (v instanceof LoopVertex loopVertex) {
return checkLoopExitingNode(loopVertex);
} else if (v instanceof ConditionalVertex conditionalVertex) {
return checkElseIfClauseExitingNode(conditionalVertex, graph);
}

return v.getAst();
Expand Down Expand Up @@ -178,22 +178,19 @@ private Optional<BSLParserRuleContext> checkBasicBlockExitingNode(BasicBlockVert
}

private Optional<BSLParserRuleContext> checkLoopExitingNode(LoopVertex v) {
if (v instanceof WhileLoopVertex) {
var whileLoop = (WhileLoopVertex) v;
if (isEndlessLoop(whileLoop)) {
return Optional.empty();
}
if (v instanceof WhileLoopVertex whileLoop && isEndlessLoop(whileLoop)) {
return Optional.empty();
}

if (loopsExecutedAtLeastOnce) {
// из цикла в exit может придти только falseBranch или пустое тело цикла
// из цикла в exit может прийти только falseBranch или пустое тело цикла
// и то и другое не нужно нам в рамках диагностики
return Optional.empty();
}
return v.getAst();
}

private boolean isEndlessLoop(WhileLoopVertex whileLoop) {
private static boolean isEndlessLoop(WhileLoopVertex whileLoop) {
var expression = whileLoop.getExpression();
return expression.getChildCount() == 1
&& expression.member(0).constValue() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public class OscriptReferenceFinder implements ReferenceFinder {
public Optional<Reference> findReference(URI uri, Position position) {

DocumentContext document = serverContext.getDocument(uri);
if (document == null
// || document.isComputedDataFrozen()
) {
if (document == null) {
return Optional.empty();
}

if(document.isComputedDataFrozen()) {
document.unfreezeComputedData();
serverContext.rebuildDocument(document);
}

var node = SelectionRangeProvider.findNodeContainsPosition(document.getAst(), position);

if (node.isEmpty()) {
Expand Down Expand Up @@ -86,7 +89,5 @@ private boolean filterByType(Optional<TerminalNode> node, ModuleType moduleType)
return (node.get().getParent() instanceof BSLParser.ComplexIdentifierContext)
&& moduleType == ModuleType.OScriptModule;
}

}

}

0 comments on commit 7992f30

Please sign in to comment.