2222import org .github ._1c_syntax .bsl .languageserver .context .ServerContext ;
2323import org .github ._1c_syntax .bsl .languageserver .diagnostics .BSLDiagnostic ;
2424import org .github ._1c_syntax .bsl .languageserver .diagnostics .FunctionShouldHaveReturnDiagnostic ;
25+ import org .github ._1c_syntax .bsl .languageserver .diagnostics .ParseErrorDiagnostic ;
2526import org .github ._1c_syntax .bsl .languageserver .diagnostics .ProcedureReturnsValueDiagnostic ;
2627import org .github ._1c_syntax .bsl .languageserver .diagnostics .QuickFixProvider ;
28+ import org .github ._1c_syntax .bsl .languageserver .diagnostics .UnknownPreprocessorSymbolDiagnostic ;
29+ import org .github ._1c_syntax .bsl .languageserver .diagnostics .UsingServiceTagDiagnostic ;
2730import org .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticType ;
2831import org .github ._1c_syntax .bsl .languageserver .providers .DiagnosticProvider ;
2932
3235import com ._1c .g5 .v8 .dt .bsl .validation .IExternalBslValidator ;
3336
3437public class BslValidator implements IExternalBslValidator {
38+ private static final String [] EMPTY_ARRAY = {};
39+
3540 private DiagnosticProvider diagnosticProvider ;
3641
3742 public BslValidator () {
@@ -40,10 +45,18 @@ public BslValidator() {
4045 LanguageServerConfiguration configuration = LanguageServerConfiguration .create ();
4146
4247 Map <String , Either <Boolean , Map <String , Object >>> diagnostics = new HashMap <>();
48+
49+ // CODE_SMELL.INFO
50+ diagnostics .put (DiagnosticProvider .getDiagnosticCode (UsingServiceTagDiagnostic .class ), Either .forLeft (false ));
51+
52+ // Есть в EDT
4353 diagnostics .put (DiagnosticProvider .getDiagnosticCode (FunctionShouldHaveReturnDiagnostic .class ),
4454 Either .forLeft (false ));
55+ diagnostics .put (DiagnosticProvider .getDiagnosticCode (ParseErrorDiagnostic .class ), Either .forLeft (false ));
4556 diagnostics .put (DiagnosticProvider .getDiagnosticCode (ProcedureReturnsValueDiagnostic .class ),
4657 Either .forLeft (false ));
58+ diagnostics .put (DiagnosticProvider .getDiagnosticCode (UnknownPreprocessorSymbolDiagnostic .class ),
59+ Either .forLeft (false ));
4760
4861 configuration .setDiagnostics (diagnostics );
4962
@@ -72,12 +85,6 @@ public void validate(EObject object, CustomValidationMessageAcceptor messageAcce
7285 for (Diagnostic diagnostic : diagnostics ) {
7386 Class <? extends BSLDiagnostic > bslDiagnosticClass = DiagnosticProvider .getBSLDiagnosticClass (diagnostic );
7487 DiagnosticType diagnosticType = DiagnosticProvider .getDiagnosticType (bslDiagnosticClass );
75- org .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticSeverity diagnosticSeverity = DiagnosticProvider
76- .getDiagnosticSeverity (bslDiagnosticClass );
77-
78- if (diagnosticType .equals (DiagnosticType .CODE_SMELL ) && diagnosticSeverity
79- .equals (org .github ._1c_syntax .bsl .languageserver .diagnostics .metadata .DiagnosticSeverity .INFO ))
80- continue ;
8188
8289 Integer [] offsetAndLength = getOffsetAndLength (diagnostic .getRange (), doc );
8390 Integer offset = offsetAndLength [0 ];
@@ -90,28 +97,46 @@ public void validate(EObject object, CustomValidationMessageAcceptor messageAcce
9097
9198 String [] issueData = getIssueData (diagnostic , bslDiagnosticClass , documentContext , doc );
9299
93- if (diagnosticType .equals (DiagnosticType .ERROR ) || diagnosticType .equals (DiagnosticType .VULNERABILITY ))
94- messageAcceptor .acceptError (diagnostic
95- .getMessage (), diagnosticObject , offset , length , "bsl-language-server" , issueData ); //$NON-NLS-1$
96-
97- else
98- messageAcceptor .acceptWarning (diagnostic
99- .getMessage (), diagnosticObject , offset , length , "bsl-language-server" , issueData ); //$NON-NLS-1$
100+ if (diagnosticType .equals (DiagnosticType .ERROR ) || diagnosticType .equals (DiagnosticType .VULNERABILITY )) {
101+ if (issueData .length == 0 )
102+ messageAcceptor .acceptError (diagnostic .getMessage (), diagnosticObject , offset , length , "" ); //$NON-NLS-1$
103+
104+ else
105+ messageAcceptor .acceptError (diagnostic .getMessage (),
106+ diagnosticObject ,
107+ offset ,
108+ length ,
109+ "bsl-language-server" , //$NON-NLS-1$
110+ issueData );
111+
112+ } else {
113+ if (issueData .length == 0 )
114+ messageAcceptor .acceptWarning (diagnostic .getMessage (), diagnosticObject , offset , length , "" ); //$NON-NLS-1$
115+
116+ else
117+ messageAcceptor .acceptWarning (diagnostic .getMessage (),
118+ diagnosticObject ,
119+ offset ,
120+ length ,
121+ "bsl-language-server" , //$NON-NLS-1$
122+ issueData );
123+
124+ }
100125 }
101126
102127 }
103128
104129 private String [] getIssueData (Diagnostic diagnostic , Class <? extends BSLDiagnostic > bslDiagnosticClass ,
105130 DocumentContext documentContext , Document doc ) {
106- String [] issueData = { "" }; //$NON-NLS-1$
107- if (!QuickFixProvider .class .isAssignableFrom (bslDiagnosticClass ))
108- return issueData ;
131+ if (documentContext == null || !QuickFixProvider .class .isAssignableFrom (bslDiagnosticClass ))
132+ return EMPTY_ARRAY ;
109133
110134 QuickFixProvider diagnosticInstance = (QuickFixProvider ) diagnosticProvider
111135 .getDiagnosticInstance (bslDiagnosticClass );
112136 List <CodeAction > quickFixes = diagnosticInstance .getQuickFixes (diagnostic , null , documentContext );
113137
114- issueData = new String [quickFixes .size ()];
138+ List <String > issueArray = new ArrayList <>();
139+
115140 for (CodeAction quickFix : quickFixes ) {
116141 List <TextEdit > changes = quickFix .getEdit ().getChanges ().get (documentContext .getUri ());
117142 if (changes .size () != 1 )
@@ -129,9 +154,16 @@ private String[] getIssueData(Diagnostic diagnostic, Class<? extends BSLDiagnost
129154 issueLine .add (length .toString ());
130155 issueLine .add (change .getNewText ());
131156
132- issueData [ quickFixes . indexOf ( quickFix )] = String .join ("," , issueLine ); //$NON-NLS-1$
157+ issueArray . add ( String .join ("," , issueLine ) ); //$NON-NLS-1$
133158 }
134159
160+ if (issueArray .isEmpty ())
161+ return EMPTY_ARRAY ;
162+
163+ String [] issueData = new String [issueArray .size ()];
164+ for (String element : issueArray )
165+ issueData [issueArray .indexOf (element )] = element ;
166+
135167 return issueData ;
136168
137169 }
@@ -142,7 +174,7 @@ private Integer[] getOffsetAndLength(Range range, Document doc) {
142174 try {
143175 offset = doc .getLineOffset (range .getStart ().getLine ()) + range .getStart ().getCharacter ();
144176 Integer endOffset = doc .getLineOffset (range .getEnd ().getLine ()) + range .getEnd ().getCharacter ();
145- length = endOffset - offset + 1 ;
177+ length = endOffset - offset ;
146178
147179 } catch (BadLocationException e ) {
148180 BslValidatorPlugin
0 commit comments