use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method testDidOpenStandaloneFileWithSyntaxError.
@Test
public void testDidOpenStandaloneFileWithSyntaxError() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
// @formatter:off
String standaloneFileContent = "package java;\n" + "public class Foo extends UnknownType {\n" + " public void method1(){\n" + " super.whatever()\n" + " }\n" + "}";
// @formatter:on
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
openDocument(cu1, cu1.getSource(), 1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 1, diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Syntax error, insert \";\" to complete BlockStatements", d.getMessage());
assertRange(3, 17, 18, d.getRange());
}
use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class WorkspaceDiagnosticsHandlerTest method testToDiagnosticsArray.
@Test
public void testToDiagnosticsArray() throws Exception {
String msg1 = "Something's wrong Jim";
IMarker m1 = createMarker(IMarker.SEVERITY_WARNING, msg1, 2, 95, 100);
String msg2 = "He's dead";
IMarker m2 = createMarker(IMarker.SEVERITY_ERROR, msg2, 10, 1015, 1025);
String msg3 = "It's probably time to panic";
IMarker m3 = createMarker(42, msg3, 100, 10000, 10005);
IDocument d = mock(IDocument.class);
when(d.getLineOffset(1)).thenReturn(90);
when(d.getLineOffset(9)).thenReturn(1000);
when(d.getLineOffset(99)).thenReturn(10000);
List<Diagnostic> diags = handler.toDiagnosticsArray(d, new IMarker[] { m1, m2, m3 });
assertEquals(3, diags.size());
Range r;
Diagnostic d1 = diags.get(0);
assertEquals(msg1, d1.getMessage());
assertEquals(DiagnosticSeverity.Warning, d1.getSeverity());
r = d1.getRange();
assertEquals(1, r.getStart().getLine());
assertEquals(5, r.getStart().getCharacter());
assertEquals(1, r.getEnd().getLine());
assertEquals(10, r.getEnd().getCharacter());
Diagnostic d2 = diags.get(1);
assertEquals(msg2, d2.getMessage());
assertEquals(DiagnosticSeverity.Error, d2.getSeverity());
r = d2.getRange();
assertEquals(9, r.getStart().getLine());
assertEquals(15, r.getStart().getCharacter());
assertEquals(9, r.getEnd().getLine());
assertEquals(25, r.getEnd().getCharacter());
Diagnostic d3 = diags.get(2);
assertEquals(msg3, d3.getMessage());
assertEquals(DiagnosticSeverity.Information, d3.getSeverity());
r = d3.getRange();
assertEquals(99, r.getStart().getLine());
assertEquals(0, r.getStart().getCharacter());
assertEquals(99, r.getEnd().getLine());
assertEquals(5, r.getEnd().getCharacter());
}
use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class CodeActionHandler method getProblemLocations.
private IProblemLocation[] getProblemLocations(ICompilationUnit unit, List<Diagnostic> diagnostics) {
IProblemLocation[] locations = new IProblemLocation[diagnostics.size()];
for (int i = 0; i < diagnostics.size(); i++) {
Diagnostic diagnostic = diagnostics.get(i);
int problemId = getProblemId(diagnostic);
int start = DiagnosticsHelper.getStartOffset(unit, diagnostic.getRange());
int end = DiagnosticsHelper.getEndOffset(unit, diagnostic.getRange());
boolean isError = diagnostic.getSeverity() == DiagnosticSeverity.Error;
locations[i] = new ProblemLocation(start, end - start, problemId, isError);
}
return locations;
}
use of org.eclipse.lsp4j.Diagnostic in project eclipse.jdt.ls by eclipse.
the class DiagnosticsHandler method toDiagnosticsArray.
public static List<Diagnostic> toDiagnosticsArray(IOpenable openable, List<IProblem> problems) {
List<Diagnostic> array = new ArrayList<>(problems.size());
for (IProblem problem : problems) {
Diagnostic diag = new Diagnostic();
diag.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
diag.setMessage(problem.getMessage());
diag.setCode(Integer.toString(problem.getID()));
diag.setSeverity(convertSeverity(problem));
diag.setRange(convertRange(openable, problem));
array.add(diag);
}
return array;
}
use of org.eclipse.lsp4j.Diagnostic in project ballerina by ballerina-lang.
the class BallerinaTextDocumentService method codeAction.
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
return CompletableFuture.supplyAsync(() -> {
List<Command> commands = new ArrayList<>();
String topLevelNodeType = CommonUtil.topLevelNodeTypeInLine(params.getTextDocument(), params.getRange().getStart(), documentManager);
if (topLevelNodeType != null) {
commands.add(CommandUtil.getDocGenerationCommand(topLevelNodeType, params.getTextDocument().getUri(), params.getRange().getStart().getLine()));
commands.add(CommandUtil.getAllDocGenerationCommand(params.getTextDocument().getUri()));
} else if (!params.getContext().getDiagnostics().isEmpty()) {
params.getContext().getDiagnostics().forEach(diagnostic -> {
commands.addAll(CommandUtil.getCommandsByDiagnostic(diagnostic, params, lSPackageCache));
});
}
return commands;
});
}
Aggregations