Skip to content

Commit 5daa072

Browse files
committed
Другая регулярка
1 parent 20b8e84 commit 5daa072

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@
1919
)
2020
public class TabAlignmentDiagnostic extends AbstractDiagnostic {
2121

22+
private static final Pattern pattern = Pattern.compile("\\S[\\S ]*(\\t+)");
23+
2224
@Override
2325
public void check() {
2426

25-
Pattern pattern = Pattern.compile("(\\t*\\S ?)\\t+");
2627
String[] lines = documentContext.getContentList();
2728
for (int i = 0; i < lines.length; i++) {
28-
Matcher matcher = pattern.matcher(lines[i]);
29-
if (!matcher.find()) {
29+
String currentLine = lines[i].strip();
30+
if (currentLine.startsWith("|")
31+
|| currentLine.startsWith("//")) {
3032
continue;
3133
}
32-
diagnosticStorage.addDiagnostic(i, matcher.start(), i, matcher.end());
34+
35+
Matcher matcher = pattern.matcher(lines[i]);
36+
if (matcher.find()) {
37+
diagnosticStorage.addDiagnostic(i, matcher.start(1), i, matcher.end(1));
38+
}
3339
}
3440
}
3541
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github._1c_syntax.bsl.languageserver.diagnostics;
2+
3+
import org.eclipse.lsp4j.Diagnostic;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.util.List;
7+
8+
import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat;
9+
10+
class TabAlignmentDiagnosticTest extends AbstractDiagnosticTest<TabAlignmentDiagnostic> {
11+
TabAlignmentDiagnosticTest() {
12+
super(TabAlignmentDiagnostic.class);
13+
}
14+
15+
@Test
16+
void test() {
17+
18+
List<Diagnostic> diagnostics = getDiagnostics();
19+
20+
assertThat(diagnostics).hasSize(3);
21+
assertThat(diagnostics, true)
22+
.hasRange(3, 5, 6)
23+
.hasRange(4, 6, 7)
24+
.hasRange(5, 5, 6)
25+
;
26+
27+
}
28+
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

2-
Foo = f;
3-
foo = foo;
4-
foo = foo;
5-
foo = foo;
6-
foo = foo;
2+
foo = f;
3+
foo = foo;
4+
foo = foo;
5+
foo = foo;
6+
foo = foo;
7+
F = ";
8+
| foo ";
9+
10+
// foo = foo;

0 commit comments

Comments
 (0)