Skip to content

Commit ec8a4cc

Browse files
committed
Изменен состав проверок, поправлена работа быстрых исправлений
1 parent 3539570 commit ec8a4cc

File tree

2 files changed

+55
-23
lines changed

2 files changed

+55
-23
lines changed

ru.capralow.dt.bslls.validator.plugin.ui/src/ru/capralow/dt/bslls/validator/plugin/internal/ui/BslQuickFix.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package ru.capralow.dt.bslls.validator.plugin.internal.ui;
22

3+
import org.eclipse.emf.ecore.EObject;
34
import org.eclipse.text.edits.ReplaceEdit;
45
import org.eclipse.xtext.ui.editor.quickfix.Fix;
56
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
67
import org.eclipse.xtext.validation.Issue;
78

8-
import com._1c.g5.v8.dt.bsl.model.Module;
99
import com._1c.g5.v8.dt.bsl.ui.quickfix.AbstractExternalQuickfixProvider;
1010

1111
public class BslQuickFix extends AbstractExternalQuickfixProvider {
@@ -20,14 +20,14 @@ public void processBslLanguageServerDiagnostic(final Issue issue, final IssueRes
2020
String issueMessage = issueList[1];
2121
Integer issueOffset = Integer.decode(issueList[2]);
2222
Integer issueLength = Integer.decode(issueList[3]);
23-
String issueNewText = issueList[4];
23+
String issueNewText = issueList.length == 5 ? issueList[4] : ""; //$NON-NLS-1$
2424

2525
acceptor.accept(issue,
2626
issueCommand,
2727
issueMessage,
2828
(String) null,
29-
new AbstractExternalQuickfixProvider.ExternalQuickfixModification<Module>(issue,
30-
Module.class,
29+
new AbstractExternalQuickfixProvider.ExternalQuickfixModification<>(issue,
30+
EObject.class,
3131
module -> new ReplaceEdit(issueOffset, issueLength, issueNewText)));
3232
}
3333
}

ru.capralow.dt.bslls.validator.plugin.ui/src/ru/capralow/dt/bslls/validator/plugin/internal/ui/BslValidator.java

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import org.github._1c_syntax.bsl.languageserver.context.ServerContext;
2323
import org.github._1c_syntax.bsl.languageserver.diagnostics.BSLDiagnostic;
2424
import org.github._1c_syntax.bsl.languageserver.diagnostics.FunctionShouldHaveReturnDiagnostic;
25+
import org.github._1c_syntax.bsl.languageserver.diagnostics.ParseErrorDiagnostic;
2526
import org.github._1c_syntax.bsl.languageserver.diagnostics.ProcedureReturnsValueDiagnostic;
2627
import 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;
2730
import org.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
2831
import org.github._1c_syntax.bsl.languageserver.providers.DiagnosticProvider;
2932

@@ -32,6 +35,8 @@
3235
import com._1c.g5.v8.dt.bsl.validation.IExternalBslValidator;
3336

3437
public 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

Comments
 (0)