Skip to content

Commit

Permalink
Исправлен не-показ квик-фиксов для диагностик без тэгов
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Nov 16, 2020
1 parent 6a68976 commit edc3729
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@

import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionParams;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -50,10 +54,13 @@ public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext
return Collections.emptyList();
}

List<Diagnostic> computedDiagnostics = documentContext.getComputedDiagnostics();
Set<LightDiagnostic> computedDiagnostics = documentContext.getComputedDiagnostics()
.stream()
.map(LightDiagnostic::new)
.collect(Collectors.toSet());

Stream<Diagnostic> diagnosticStream = incomingDiagnostics.stream()
.filter(computedDiagnostics::contains);
.filter(diagnostic -> computedDiagnostics.contains(new LightDiagnostic(diagnostic)));

return processDiagnosticStream(diagnosticStream, params, documentContext)
.collect(Collectors.toList());
Expand All @@ -65,4 +72,17 @@ protected abstract Stream<CodeAction> processDiagnosticStream(
CodeActionParams params,
DocumentContext documentContext
);

@Value
private static class LightDiagnostic {
Either<String, Number> code;
Range range;
String source;

public LightDiagnostic(Diagnostic diagnostic) {
this.code = diagnostic.getCode();
this.range = diagnostic.getRange();
this.source = diagnostic.getSource();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ void testGetCodeActions() {
String filePath = "./src/test/resources/providers/codeAction.bsl";
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(filePath);

DiagnosticInfo diagnosticInfo = new DiagnosticInfo(
CanonicalSpellingKeywordsDiagnostic.class,
configuration
);
DiagnosticCode diagnosticCode = diagnosticInfo.getCode();

List<Diagnostic> diagnostics = documentContext.getDiagnostics().stream()
.filter(diagnostic -> {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(
CanonicalSpellingKeywordsDiagnostic.class,
configuration
);
DiagnosticCode diagnosticCode = diagnosticInfo.getCode();
return diagnostic.getCode().equals(diagnosticCode);
})
.filter(diagnostic -> diagnostic.getCode().equals(diagnosticCode))
// clean diagnostic tags array to emulate clear of tags property from the client
.peek(diagnostic -> diagnostic.setTags(null))
.collect(Collectors.toList());

CodeActionParams params = new CodeActionParams();
Expand Down

0 comments on commit edc3729

Please sign in to comment.