25
25
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticSeverity ;
26
26
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticTag ;
27
27
import com .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticType ;
28
+ import com .github ._1c_syntax .bsl .parser .BSLLexer ;
29
+ import org .antlr .v4 .runtime .Token ;
28
30
29
- import java .util .regex .Matcher ;
30
- import java .util .regex .Pattern ;
31
+ import java .util .List ;
31
32
32
33
@ DiagnosticMetadata (
33
34
type = DiagnosticType .CODE_SMELL ,
41
42
)
42
43
public class TabAlignmentDiagnostic extends AbstractDiagnostic {
43
44
44
- private static final Pattern pattern = Pattern .compile ("\\ S[\\ S ]*(\\ t+)(?! *//)" );
45
-
46
45
@ Override
47
46
public void check () {
48
47
49
- String [] lines = documentContext .getContentList ();
50
- for (int i = 0 ; i < lines .length ; i ++) {
51
- String currentLine = lines [i ].strip ();
52
- if (currentLine .startsWith ("|" )
53
- || currentLine .startsWith ("//" )) {
54
- continue ;
48
+ List <Token > tokens = documentContext .getTokens ();
49
+
50
+ int lineNum = 0 ;
51
+ boolean afterChar = false ;
52
+
53
+ for (Token token : tokens ) {
54
+
55
+ if (lineNum < token .getLine ()) {
56
+ afterChar = false ;
57
+ lineNum = token .getLine ();
55
58
}
56
59
57
- Matcher matcher = pattern .matcher (lines [i ].stripTrailing ());
58
- if (matcher .find ()) {
59
- diagnosticStorage .addDiagnostic (i , matcher .start (1 ), i , matcher .end (1 ));
60
+ if (afterChar
61
+ && token .getType () == BSLLexer .WHITE_SPACE
62
+ && !token .getText ().contains ("\n \t " )
63
+ && token .getText ().contains ("\t " )) {
64
+ diagnosticStorage .addDiagnostic (token );
60
65
}
66
+
67
+ if (!afterChar && token .getType () != BSLLexer .WHITE_SPACE ) {
68
+ afterChar = true ;
69
+ }
70
+
61
71
}
72
+
62
73
}
63
- }
74
+ }
0 commit comments