Skip to content

Commit ef33a77

Browse files
committed
Merge branch 'develop' into WriteLogEvent-1714
# Conflicts: # src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/UsageWriteLogEventDiagnostic.java # src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/UsageWriteLogEventDiagnosticTest.java
2 parents c37d4b1 + faf2f16 commit ef33a77

24 files changed

+302
-54
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
# Initializes the CodeQL tools for scanning.
3939
- name: Initialize CodeQL
40-
uses: github/codeql-action/init@v1
40+
uses: github/codeql-action/init@v2
4141
# Override language selection by uncommenting this and choosing your languages
4242
with:
4343
languages: java
@@ -52,4 +52,4 @@ jobs:
5252
- run: ./gradlew jar
5353

5454
- name: Perform CodeQL Analysis
55-
uses: github/codeql-action/analyze@v1
55+
uses: github/codeql-action/analyze@v2

.github/workflows/pre-qa.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Pre-QA
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- "translations_*"
7+
pull_request:
8+
9+
jobs:
10+
gatekeeper:
11+
runs-on: ubuntu-latest
12+
if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'translations_') == false || github.event_name == 'push'
13+
steps:
14+
- run: echo 'Open the Golden Gate'
15+
build:
16+
needs: gatekeeper
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Save PR number to file
20+
if: github.event_name == 'pull_request'
21+
run: echo ${{ github.event.number }} > PR_NUMBER.txt
22+
- name: Archive PR number
23+
if: github.event_name == 'pull_request'
24+
uses: actions/upload-artifact@v3
25+
with:
26+
name: PR_NUMBER
27+
path: PR_NUMBER.txt

.github/workflows/qa.yml

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,66 @@
11
name: QA
22

33
on:
4-
push:
5-
branches: [develop, master]
6-
7-
pull_request:
4+
workflow_run:
5+
workflows: [Pre-QA]
6+
types: [completed]
87

98
jobs:
10-
gatekeeper:
11-
runs-on: ubuntu-latest
12-
if: github.event_name == 'pull_request' && (!startsWith(github.head_ref, 'translations_') == false || github.event.pull_request.user.login != 'dependabot[bot]') || github.event_name == 'push'
13-
steps:
14-
- run: echo 'Open the Golden Gate'
159

1610
QA:
17-
needs: gatekeeper
1811
runs-on: ubuntu-latest
19-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.event.repository.full_name
12+
if: github.event.workflow_run.conclusion == 'success'
2013
steps:
14+
- name: Download PR number artifact
15+
if: github.event.workflow_run.event == 'pull_request'
16+
uses: dawidd6/action-download-artifact@v2
17+
with:
18+
workflow: ${{ github.event.workflow_run.name }}
19+
run_id: ${{ github.event.workflow_run.id }}
20+
name: PR_NUMBER
21+
- name: Read PR_NUMBER.txt
22+
if: github.event.workflow_run.event == 'pull_request'
23+
id: pr_number
24+
uses: juliangruber/read-file-action@v1
25+
with:
26+
path: ./PR_NUMBER.txt
27+
- name: Request GitHub API for PR data
28+
if: github.event.workflow_run.event == 'pull_request'
29+
uses: octokit/request-action@v2.x
30+
id: get_pr_data
31+
with:
32+
route: GET /repos/{full_name}/pulls/{number}
33+
number: ${{ steps.pr_number.outputs.content }}
34+
full_name: ${{ github.event.repository.full_name }}
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2137
- uses: actions/checkout@v3
2238
with:
23-
fetch-depth: ''
24-
- run: |
25-
git fetch --prune --unshallow
39+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
40+
ref: ${{ github.event.workflow_run.head_branch }}
41+
fetch-depth: 0
42+
- name: Checkout base branch
43+
if: github.event.workflow_run.event == 'pull_request'
44+
run: |
45+
git remote add upstream ${{ github.event.repository.clone_url }}
46+
git fetch upstream
47+
git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
48+
git checkout ${{ github.event.workflow_run.head_branch }}
49+
git clean -ffdx && git reset --hard HEAD
2650
- name: Set up JDK 11
2751
uses: actions/setup-java@v3
2852
with:
2953
java-version: 11
3054
distribution: 'temurin'
31-
- name: SonarCloud Scan
32-
run: ./gradlew check sonarqube
55+
- name: SonarCloud Scan on PR
56+
if: github.event.workflow_run.event == 'pull_request'
57+
run: ./gradlew check sonarqube -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} -Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} -Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
58+
env:
59+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
- name: SonarCloud Scan on push
62+
if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name
63+
run: ./gradlew check sonarqube -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}
3364
env:
3465
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3566
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/qodana.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v3
2222
- name: 'Qodana Scan'
23-
uses: JetBrains/qodana-action@v4.2.5
23+
uses: JetBrains/qodana-action@v5.1.0
2424
with:
2525
linter: jetbrains/qodana-jvm-community
26-
- uses: github/codeql-action/upload-sarif@v1
26+
- uses: github/codeql-action/upload-sarif@v2
2727
with:
2828
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
2929
- name: Deploy to GitHub Pages

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
id("io.freefair.javadoc-utf-8") version "6.4.3"
1515
id("io.freefair.aspectj.post-compile-weaving") version "6.4.3"
1616
id("io.freefair.maven-central.validate-poms") version "6.4.3"
17-
id("me.qoomon.git-versioning") version "5.2.0"
17+
id("me.qoomon.git-versioning") version "6.1.1"
1818
id("com.github.ben-manes.versions") version "0.42.0"
1919
id("org.springframework.boot") version "2.6.7"
2020
id("io.spring.dependency-management") version "1.0.11.RELEASE"
@@ -63,7 +63,7 @@ dependencies {
6363
api("org.eclipse.lsp4j", "org.eclipse.lsp4j", "0.12.0")
6464

6565
// 1c-syntax
66-
api("com.github.1c-syntax", "bsl-parser", "0.20.3") {
66+
api("com.github.1c-syntax", "bsl-parser", "0.21.0") {
6767
exclude("com.tunnelvisionlabs", "antlr4-annotations")
6868
exclude("com.ibm.icu", "*")
6969
exclude("org.antlr", "ST4")

qodana.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version: "1.0"
22
profile:
33
name: qodana.starter
4+
include:
5+
- name: CheckDependencyLicenses
46
exclude:
57
- name: OptionalUsedAsFieldOrParameterType

src/main/java/com/github/_1c_syntax/bsl/languageserver/cli/FormatCommand.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
package com.github._1c_syntax.bsl.languageserver.cli;
2323

24-
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2524
import com.github._1c_syntax.bsl.languageserver.context.ServerContext;
2625
import com.github._1c_syntax.bsl.languageserver.providers.FormatProvider;
2726
import com.github._1c_syntax.utils.Absolute;
@@ -41,10 +40,10 @@
4140
import java.net.URI;
4241
import java.nio.charset.StandardCharsets;
4342
import java.nio.file.Path;
44-
import java.util.Collection;
45-
import java.util.Collections;
43+
import java.util.ArrayList;
4644
import java.util.List;
4745
import java.util.concurrent.Callable;
46+
import java.util.regex.Pattern;
4847

4948
import static picocli.CommandLine.Command;
5049
import static picocli.CommandLine.Option;
@@ -75,6 +74,7 @@
7574
@RequiredArgsConstructor
7675
public class FormatCommand implements Callable<Integer> {
7776

77+
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
7878
private final ServerContext serverContext;
7979
private final FormatProvider formatProvider;
8080

@@ -99,18 +99,12 @@ public class FormatCommand implements Callable<Integer> {
9999
public Integer call() {
100100
serverContext.clear();
101101

102-
Path srcDir = Absolute.path(srcDirOption);
103-
if (!srcDir.toFile().exists()) {
104-
LOGGER.error("Source dir `{}` is not exists", srcDir);
105-
return 1;
106-
}
102+
String[] filePaths = COMMA_PATTERN.split(srcDirOption);
107103

108-
Collection<File> files;
104+
List<File> files = findFilesForFormatting(filePaths);
109105

110-
if(srcDir.toFile().isDirectory()) {
111-
files = FileUtils.listFiles(srcDir.toFile(), new String[]{"bsl", "os"}, true);
112-
} else {
113-
files = Collections.singletonList(srcDir.toFile());
106+
if (files.isEmpty()) {
107+
return 1;
114108
}
115109

116110
if (silentMode) {
@@ -132,6 +126,25 @@ public Integer call() {
132126
return 0;
133127
}
134128

129+
private List<File> findFilesForFormatting(String[] filePaths) {
130+
List<File> files = new ArrayList<>();
131+
for (String filePath : filePaths) {
132+
Path srcDir = Absolute.path(filePath);
133+
if (!srcDir.toFile().exists()) {
134+
LOGGER.error("Source dir `{}` is not exists", srcDir);
135+
continue;
136+
}
137+
138+
if(srcDir.toFile().isDirectory()) {
139+
files.addAll(FileUtils.listFiles(srcDir.toFile(), new String[]{"bsl", "os"}, true));
140+
} else {
141+
files.add(srcDir.toFile());
142+
}
143+
}
144+
145+
return files;
146+
}
147+
135148
@SneakyThrows
136149
private void formatFile(File file) {
137150
String textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);

src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/AbstractSDBLVisitorDiagnostic.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2525
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo;
26+
import com.github._1c_syntax.bsl.languageserver.utils.Trees;
27+
import com.github._1c_syntax.bsl.parser.SDBLParser;
2628
import com.github._1c_syntax.bsl.parser.SDBLParserBaseVisitor;
2729
import lombok.Getter;
2830
import lombok.Setter;
@@ -49,4 +51,13 @@ public List<Diagnostic> getDiagnostics(DocumentContext documentContext) {
4951

5052
return diagnosticStorage.getDiagnostics();
5153
}
54+
55+
@Override
56+
public ParseTree visitQueryPackage(SDBLParser.QueryPackageContext ctx) {
57+
if (Trees.treeContainsErrors(ctx)) {
58+
return ctx;
59+
}
60+
return super.visitQueryPackage(ctx);
61+
}
62+
5263
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/CodeOutOfRegionDiagnostic.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
import java.util.ArrayList;
4646
import java.util.List;
47+
import java.util.Objects;
48+
import java.util.Optional;
4749
import java.util.stream.Collectors;
4850

4951
@DiagnosticMetadata(
@@ -145,7 +147,7 @@ public ParseTree visitModuleVar(BSLParser.ModuleVarContext ctx) {
145147
&& !(node instanceof TerminalNode))
146148
.findFirst()
147149
.ifPresent((Tree node) -> {
148-
Range ctxRange = Ranges.create((BSLParserRuleContext) node);
150+
var ctxRange = Ranges.create((BSLParserRuleContext) node);
149151
if (regionsRanges.stream().noneMatch(regionRange ->
150152
Ranges.containsRange(regionRange, ctxRange))) {
151153
diagnosticStorage.addDiagnostic(ctx);
@@ -182,14 +184,26 @@ private void addDiagnosticForFileCodeBlock(BSLParserRuleContext ctx) {
182184
.stream()
183185
.filter(node -> node.getParent().getParent() == ctx)
184186
.forEach((ParseTree child) -> {
185-
if (child.getChildCount() > 1
186-
|| !(child.getChild(0) instanceof BSLParser.PreprocessorContext)) {
187-
Range ctxRange = Ranges.create((BSLParser.StatementContext) child);
187+
if ((child.getChildCount() > 1
188+
|| !(child.getChild(0) instanceof BSLParser.PreprocessorContext))
189+
&& !isRaiseStatement(child)) {
190+
191+
var ctxRange = Ranges.create((BSLParser.StatementContext) child);
188192
if (regionsRanges.stream().noneMatch(regionRange ->
189193
Ranges.containsRange(regionRange, ctxRange))) {
190194
diagnosticStorage.addDiagnostic((BSLParser.StatementContext) child);
191195
}
192196
}
193197
});
194198
}
199+
200+
private static boolean isRaiseStatement(ParseTree child) {
201+
return Optional.of(child).stream()
202+
.filter(BSLParser.StatementContext.class::isInstance)
203+
.map(BSLParser.StatementContext.class::cast)
204+
.map(BSLParser.StatementContext::compoundStatement)
205+
.filter(Objects::nonNull)
206+
.map(BSLParser.CompoundStatementContext::raiseStatement)
207+
.anyMatch(Objects::nonNull);
208+
}
195209
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/FieldsFromJoinsWithoutIsNullDiagnostic.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public class FieldsFromJoinsWithoutIsNullDiagnostic extends AbstractSDBLVisitorD
6262
private static final Integer SELECT_ROOT = SDBLParser.RULE_selectedField;
6363
private static final Collection<Integer> SELECT_STATEMENTS = Set.of(SELECT_ROOT, SDBLParser.RULE_builtInFunctions);
6464

65-
private static final Integer WHERE_ROOT = SDBLParser.RULE_searchCondition;
65+
private static final Integer WHERE_ROOT = SDBLParser.RULE_predicate;
6666
private static final Collection<Integer> WHERE_STATEMENTS = Set.of(WHERE_ROOT, SDBLParser.RULE_builtInFunctions,
6767
SDBLParser.RULE_isNullPredicate);
6868

6969
private static final Integer JOIN_ROOT = SDBLParser.RULE_joinPart;
7070
private static final Collection<Integer> JOIN_STATEMENTS = Set.of(JOIN_ROOT, SDBLParser.RULE_builtInFunctions);
7171

72-
public static final Collection<Integer> RULES_OF_PARENT_FOR_SEARCH_CONDITION = Set.of(SDBLParser.RULE_searchCondition,
72+
public static final Collection<Integer> RULES_OF_PARENT_FOR_SEARCH_CONDITION = Set.of(SDBLParser.RULE_predicate,
7373
SDBLParser.RULE_query);
7474

7575
public static final int NOT_WITH_PARENS_EXPR_MEMBERS_COUNT = 4;
@@ -128,7 +128,7 @@ private void checkQuery(String joinedTableName, SDBLParser.JoinPartContext joinP
128128
});
129129
}
130130

131-
private static boolean haveExprNotIsNullInsideWhere(@Nullable SDBLParser.SearchConditionsContext whereCtx) {
131+
private static boolean haveExprNotIsNullInsideWhere(@Nullable SDBLParser.LogicalExpressionContext whereCtx) {
132132
return Optional.ofNullable(whereCtx)
133133
.stream().flatMap(ctx -> Trees.findAllRuleNodes(ctx, SDBLParser.RULE_isNullPredicate).stream())
134134
.map(SDBLParser.IsNullPredicateContext.class::cast)
@@ -142,7 +142,7 @@ private static boolean haveFirstIsThenNotThenNull(SDBLParser.IsNullPredicateCont
142142
}
143143

144144
private static boolean haveExprNotIsNullInsideWhere(SDBLParser.IsNullPredicateContext isNullPredicateCtx) {
145-
final var parent = (SDBLParser.SearchConditionContext) isNullPredicateCtx.getParent();
145+
final var parent = (SDBLParser.PredicateContext) isNullPredicateCtx.getParent();
146146
if (parent.getChildCount() == NOT_IS_NULL_EXPR_MEMBER_COUNT && parent.NOT() != null) {
147147
return true;
148148
}
@@ -153,7 +153,7 @@ private static boolean isTerminalNodeNOT(ParseTree node) {
153153
return node instanceof TerminalNode && ((TerminalNode) node).getSymbol().getType() == SDBLParser.NOT;
154154
}
155155

156-
private static boolean haveExprNotWithParens(SDBLParser.SearchConditionContext ctx) {
156+
private static boolean haveExprNotWithParens(SDBLParser.PredicateContext ctx) {
157157
final var rootCtx = Trees.getRootParent(ctx, RULES_OF_PARENT_FOR_SEARCH_CONDITION);
158158
if (rootCtx == null || rootCtx.getRuleIndex() == SDBLParser.RULE_query) {
159159
return false;
@@ -214,11 +214,10 @@ private static boolean haveIsNullFunction(BSLParserRuleContext ctx) {
214214
.filter(SDBLParser.BuiltInFunctionsContext.class::isInstance)
215215
.map(SDBLParser.BuiltInFunctionsContext.class::cast)
216216
.map(SDBLParser.BuiltInFunctionsContext::ISNULL)
217-
.filter(Objects::nonNull)
218217
.isPresent();
219218
}
220219

221-
private void checkWhere(String tableName, @Nullable SDBLParser.SearchConditionsContext where) {
220+
private void checkWhere(String tableName, @Nullable SDBLParser.LogicalExpressionContext where) {
222221
Optional.ofNullable(where)
223222
.stream().flatMap(searchConditionsContext -> searchConditionsContext.condidions.stream())
224223
.forEach(searchConditionContext -> checkStatements(tableName, searchConditionContext,
@@ -230,7 +229,7 @@ private void checkAllJoins(String tableName, SDBLParser.JoinPartContext currentJ
230229
.filter(SDBLParser.DataSourceContext.class::isInstance)
231230
.stream().flatMap(ctx -> ((SDBLParser.DataSourceContext) ctx).joinPart().stream())
232231
.filter(joinPartContext -> joinPartContext != currentJoinPart)
233-
.map(SDBLParser.JoinPartContext::searchConditions)
232+
.map(SDBLParser.JoinPartContext::logicalExpression)
234233
.forEach(searchConditionsContext -> checkStatements(tableName, searchConditionsContext,
235234
JOIN_STATEMENTS, JOIN_ROOT, false));
236235
}

0 commit comments

Comments
 (0)