Skip to content

Commit cdad5ad

Browse files
authored
Merge pull request #3686 from 1c-syntax/develop
0.25.2
2 parents 5b740cf + 406c099 commit cdad5ad

File tree

20 files changed

+1790
-645
lines changed

20 files changed

+1790
-645
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This is a Java-based language server that provides code analysis, diagnostics, c
1010
- Project site: https://1c-syntax.github.io/bsl-language-server
1111
- Documentation: [docs/index.md](../docs/index.md) (Russian), [docs/en/index.md](../docs/en/index.md) (English)
1212
- Contributor's Guide: [docs/en/contributing/index.md](../docs/en/contributing/index.md)
13+
- BSL grammar used in BSLParser: https://github.com/1c-syntax/bsl-parser/blob/develop/src/main/antlr/BSLParser.g4
14+
- SDBL grammar used in BSLParser: https://github.com/1c-syntax/bsl-parser/blob/develop/src/main/antlr/SDBLParser.g4
1315

1416
## Technology Stack
1517

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Dependabot auto-merge
2+
on:
3+
pull_request_target:
4+
types: [opened, synchronize]
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
jobs:
11+
dependabot:
12+
runs-on: ubuntu-latest
13+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == '1c-syntax/bsl-language-server'
14+
steps:
15+
- name: Dependabot metadata
16+
id: metadata
17+
uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b
18+
with:
19+
github-token: "${{ secrets.GITHUB_TOKEN }}"
20+
- name: Approve a PR
21+
run: gh pr review --approve "$PR_URL"
22+
env:
23+
PR_URL: ${{ github.event.pull_request.html_url }}
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Enable auto-merge for Dependabot PRs
26+
run: gh pr merge --auto --merge "$PR_URL"
27+
env:
28+
PR_URL: ${{ github.event.pull_request.html_url }}
29+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ plugins {
1515
id("io.freefair.aspectj.post-compile-weaving") version "9.1.0"
1616
// id("io.freefair.maven-central.validate-poms") version "9.0.0" // TODO: Re-enable when compatible with Gradle 9
1717
id("com.github.ben-manes.versions") version "0.53.0"
18-
id("org.springframework.boot") version "3.5.8"
18+
id("org.springframework.boot") version "3.5.9"
1919
id("io.spring.dependency-management") version "1.1.7"
2020
id("io.sentry.jvm.gradle") version "5.12.2"
2121
id("io.github.1c-syntax.bslls-dev-tools") version "0.8.1"
2222
id("ru.vyarus.pom") version "3.0.0"
2323
id("org.jreleaser") version "1.21.0"
24-
id("org.sonarqube") version "7.2.1.6560"
24+
id("org.sonarqube") version "7.2.2.6593"
2525
id("me.champeau.jmh") version "0.7.3"
2626
id("com.gorylenko.gradle-git-properties") version "2.5.4"
2727
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/CognitiveComplexityCodeLensSupplier.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
2626
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2727
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
28+
import org.springframework.core.annotation.Order;
2829
import org.springframework.stereotype.Component;
2930

3031
import java.util.Map;
@@ -33,6 +34,7 @@
3334
* Сапплаер линз, показывающий когнитивную сложность методов.
3435
*/
3536
@Component
37+
@Order(4)
3638
public class CognitiveComplexityCodeLensSupplier extends AbstractMethodComplexityCodeLensSupplier {
3739

3840
public CognitiveComplexityCodeLensSupplier(

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/CyclomaticComplexityCodeLensSupplier.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
2626
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
2727
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
28+
import org.springframework.core.annotation.Order;
2829
import org.springframework.stereotype.Component;
2930

3031
import java.util.Map;
3132

3233
/**
33-
* Сапплаер линз, показывающий когнитивную сложность методов.
34+
* Сапплаер линз, показывающий цикломатическую сложность методов.
3435
*/
3536
@Component
37+
@Order(5)
3638
public class CyclomaticComplexityCodeLensSupplier extends AbstractMethodComplexityCodeLensSupplier {
3739

3840
public CyclomaticComplexityCodeLensSupplier(
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2025
5+
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.codelenses;
23+
24+
import com.github._1c_syntax.bsl.languageserver.codelenses.testrunner.TestRunnerAdapter;
25+
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
26+
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
27+
import com.github._1c_syntax.bsl.languageserver.context.FileType;
28+
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
29+
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
30+
import lombok.EqualsAndHashCode;
31+
import lombok.Getter;
32+
import lombok.ToString;
33+
import lombok.Value;
34+
import lombok.extern.slf4j.Slf4j;
35+
import org.eclipse.lsp4j.CodeLens;
36+
import org.eclipse.lsp4j.Command;
37+
import org.springframework.beans.factory.annotation.Autowired;
38+
import org.springframework.context.annotation.Lazy;
39+
import org.springframework.core.annotation.Order;
40+
import org.springframework.stereotype.Component;
41+
42+
import java.beans.ConstructorProperties;
43+
import java.net.URI;
44+
import java.nio.file.Paths;
45+
import java.util.Collections;
46+
import java.util.List;
47+
import java.util.Map;
48+
import java.util.Optional;
49+
50+
@Component
51+
@Slf4j
52+
@Order(3)
53+
public class DebugTestCodeLensSupplier
54+
extends AbstractRunTestsCodeLensSupplier<DebugTestCodeLensSupplier.DebugTestCodeLensData> {
55+
56+
private static final String COMMAND_ID = "language-1c-bsl.languageServer.debugTest";
57+
58+
private final TestRunnerAdapter testRunnerAdapter;
59+
private final Resources resources;
60+
61+
// Self-injection для работы кэша в базовом классе.
62+
@Autowired
63+
@Lazy
64+
@Getter
65+
@SuppressWarnings("NullAway.Init")
66+
private DebugTestCodeLensSupplier self;
67+
68+
public DebugTestCodeLensSupplier(
69+
LanguageServerConfiguration configuration,
70+
TestRunnerAdapter testRunnerAdapter,
71+
Resources resources
72+
) {
73+
super(configuration);
74+
this.testRunnerAdapter = testRunnerAdapter;
75+
this.resources = resources;
76+
}
77+
78+
/**
79+
* {@inheritDoc}
80+
*/
81+
@Override
82+
public List<CodeLens> getCodeLenses(DocumentContext documentContext) {
83+
84+
if (documentContext.getFileType() == FileType.BSL) {
85+
return Collections.emptyList();
86+
}
87+
88+
var options = configuration.getCodeLensOptions().getTestRunnerAdapterOptions();
89+
90+
if (options.getDebugTestArguments().isEmpty()) {
91+
return Collections.emptyList();
92+
}
93+
94+
var testIds = testRunnerAdapter.getTestIds(documentContext);
95+
var symbolTree = documentContext.getSymbolTree();
96+
97+
return testIds.stream()
98+
.map(symbolTree::getMethodSymbol)
99+
.flatMap(Optional::stream)
100+
.map(methodSymbol -> toCodeLens(methodSymbol, documentContext))
101+
.toList();
102+
}
103+
104+
/**
105+
* {@inheritDoc}
106+
*/
107+
@Override
108+
public Class<DebugTestCodeLensSupplier.DebugTestCodeLensData> getCodeLensDataClass() {
109+
return DebugTestCodeLensSupplier.DebugTestCodeLensData.class;
110+
}
111+
112+
/**
113+
* {@inheritDoc}
114+
*/
115+
@Override
116+
public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, DebugTestCodeLensData data) {
117+
118+
var path = Paths.get(documentContext.getUri());
119+
var testId = data.getTestId();
120+
121+
var options = configuration.getCodeLensOptions().getTestRunnerAdapterOptions();
122+
var executable = options.getExecutableForCurrentOS();
123+
String runText = executable + " " + options.getDebugTestArguments();
124+
runText = String.format(runText, path, testId);
125+
126+
var command = new Command();
127+
command.setTitle(resources.getResourceString(getClass(), "title"));
128+
command.setCommand(COMMAND_ID);
129+
command.setArguments(List.of(Map.of("text", runText)));
130+
131+
unresolved.setCommand(command);
132+
133+
return unresolved;
134+
135+
}
136+
137+
private CodeLens toCodeLens(MethodSymbol method, DocumentContext documentContext) {
138+
var testId = method.getName();
139+
var codeLensData = new DebugTestCodeLensSupplier.DebugTestCodeLensData(documentContext.getUri(), getId(), testId);
140+
141+
var codeLens = new CodeLens(method.getSubNameRange());
142+
codeLens.setData(codeLensData);
143+
144+
return codeLens;
145+
}
146+
147+
/**
148+
* DTO для хранения данных линз для отладки теста.
149+
*/
150+
@Value
151+
@EqualsAndHashCode(callSuper = true)
152+
@ToString(callSuper = true)
153+
public static class DebugTestCodeLensData extends DefaultCodeLensData {
154+
/**
155+
* Имя метода.
156+
*/
157+
String testId;
158+
159+
/**
160+
* @param uri URI документа.
161+
* @param id Идентификатор линзы.
162+
* @param testId Идентификатор теста.
163+
*/
164+
@ConstructorProperties({"uri", "id", "testId"})
165+
public DebugTestCodeLensData(URI uri, String id, String testId) {
166+
super(uri, id);
167+
this.testId = testId;
168+
}
169+
}
170+
171+
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/RunAllTestsCodeLensSupplier.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.eclipse.lsp4j.Command;
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.context.annotation.Lazy;
35+
import org.springframework.core.annotation.Order;
3536
import org.springframework.stereotype.Component;
3637

3738
import java.nio.file.Paths;
@@ -44,6 +45,7 @@
4445
*/
4546
@Component
4647
@Slf4j
48+
@Order(1)
4749
public class RunAllTestsCodeLensSupplier
4850
extends AbstractRunTestsCodeLensSupplier<DefaultCodeLensData> {
4951

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/RunTestCodeLensSupplier.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.lsp4j.Command;
3737
import org.springframework.beans.factory.annotation.Autowired;
3838
import org.springframework.context.annotation.Lazy;
39+
import org.springframework.core.annotation.Order;
3940
import org.springframework.stereotype.Component;
4041

4142
import java.beans.ConstructorProperties;
@@ -51,6 +52,7 @@
5152
*/
5253
@Component
5354
@Slf4j
55+
@Order(2)
5456
public class RunTestCodeLensSupplier
5557
extends AbstractRunTestsCodeLensSupplier<RunTestCodeLensSupplier.RunTestCodeLensData> {
5658

@@ -139,7 +141,7 @@ private CodeLens toCodeLens(MethodSymbol method, DocumentContext documentContext
139141
}
140142

141143
/**
142-
* DTO для хранения данных линз о сложности методов в документе.
144+
* DTO для хранения данных линз для запуска теста.
143145
*/
144146
@Value
145147
@EqualsAndHashCode(callSuper = true)

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/infrastructure/CodeLensesConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
import org.springframework.context.annotation.Bean;
3030
import org.springframework.context.annotation.Configuration;
3131
import org.springframework.context.annotation.Scope;
32+
import org.springframework.core.Ordered;
33+
import org.springframework.core.annotation.OrderUtils;
3234

3335
import java.util.Collection;
36+
import java.util.Comparator;
3437
import java.util.List;
3538
import java.util.Map;
39+
import java.util.Objects;
3640
import java.util.function.Function;
3741
import java.util.stream.Collectors;
3842

@@ -77,6 +81,8 @@ public List<CodeLensSupplier<CodeLensData>> enabledCodeLensSuppliers(
7781
var parameters = configuration.getCodeLensOptions().getParameters();
7882
return codeLensSuppliersById.values().stream()
7983
.filter(supplier -> supplierIsEnabled(supplier.getId(), parameters))
84+
.sorted(Comparator.comparing(o ->
85+
Objects.requireNonNullElse(OrderUtils.getOrder(o.getClass()), Ordered.LOWEST_PRECEDENCE)))
8086
.collect(Collectors.toList());
8187
}
8288

src/main/java/com/github/_1c_syntax/bsl/languageserver/codelenses/testrunner/TestRunnerAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private List<String> computeTestIdsByTestRunner(DocumentContext documentContext)
144144
.map(getTestsRegex::matcher)
145145
.filter(Matcher::matches)
146146
.map(matcher -> matcher.group(1))
147+
.distinct()
147148
.toList();
148149
}
149150

0 commit comments

Comments
 (0)