use of org.eclipse.lsp4j.PublishDiagnosticsParams in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method checkFilePathForAllProblems.
private boolean checkFilePathForAllProblems(Path path, Boolean quick) {
ICompilationUnit mainUnit = getCompilationUnit(path);
if (mainUnit == null) {
return false;
}
CompilerProject project = (CompilerProject) mainUnit.getProject();
Collection<ICompilerProblem> fatalProblems = project.getFatalProblems();
if (fatalProblems == null || fatalProblems.size() == 0) {
fatalProblems = project.getProblems();
}
if (fatalProblems != null && fatalProblems.size() > 0) {
URI uri = path.toUri();
PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
publish.setDiagnostics(new ArrayList<>());
publish.setUri(uri.toString());
codeProblemTracker.trackFileWithProblems(uri);
for (ICompilerProblem problem : fatalProblems) {
addCompilerProblem(problem, publish);
}
codeProblemTracker.cleanUpStaleProblems();
if (languageClient != null) {
languageClient.publishDiagnostics(publish);
}
return true;
}
IASNode ast = null;
try {
ast = mainUnit.getSyntaxTreeRequest().get().getAST();
} catch (Exception e) {
System.err.println("Exception during build: " + e);
return false;
}
if (ast == null) {
return false;
}
Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
try {
if (quick) {
PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(mainUnit);
URI uri = Paths.get(mainUnit.getAbsoluteFilename()).toUri();
files.put(uri, params);
} else {
boolean continueCheckingForErrors = true;
while (continueCheckingForErrors) {
try {
for (ICompilationUnit unit : compilationUnits) {
if (unit == null || unit instanceof SWCCompilationUnit) {
//compiled compilation units won't have problems
continue;
}
PublishDiagnosticsParams params = checkCompilationUnitForAllProblems(unit);
URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
files.put(uri, params);
}
continueCheckingForErrors = false;
} catch (ConcurrentModificationException e) {
//when we finished building one of the compilation
//units, more were added to the collection, so we need
//to start over because we can't iterate over a modified
//collection.
}
}
//only clean up stale errors on a full check
codeProblemTracker.cleanUpStaleProblems();
}
} catch (Exception e) {
System.err.println("Exception during build: " + e);
e.printStackTrace();
return false;
}
if (languageClient != null) {
files.values().forEach(languageClient::publishDiagnostics);
}
return true;
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method checkCompilationUnitForAllProblems.
private PublishDiagnosticsParams checkCompilationUnitForAllProblems(ICompilationUnit unit) {
URI uri = Paths.get(unit.getAbsoluteFilename()).toUri();
PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
publish.setDiagnostics(new ArrayList<>());
publish.setUri(uri.toString());
codeProblemTracker.trackFileWithProblems(uri);
ArrayList<ICompilerProblem> problems = new ArrayList<>();
try {
unit.waitForBuildFinish(problems, ITarget.TargetType.SWF);
for (ICompilerProblem problem : problems) {
addCompilerProblem(problem, publish);
}
} catch (Exception e) {
System.err.println("Exception during waitForBuildFinish(): " + e);
e.printStackTrace();
Diagnostic diagnostic = createDiagnosticWithoutRange();
diagnostic.setSeverity(DiagnosticSeverity.Error);
diagnostic.setMessage("A fatal error occurred while checking a file for problems: " + unit.getAbsoluteFilename());
publish.getDiagnostics().add(diagnostic);
}
return publish;
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method newPublishDiagnostics.
private static PublishDiagnosticsParams newPublishDiagnostics(URI newUri) {
PublishDiagnosticsParams p = new PublishDiagnosticsParams();
p.setDiagnostics(new ArrayList<>());
p.setUri(newUri.toString());
return p;
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method assertNewProblemReported.
private void assertNewProblemReported(ExpectedProblemReport... expectedReports) {
List<PublishDiagnosticsParams> diags = getClientRequests("publishDiagnostics");
assertEquals(expectedReports.length, diags.size());
for (int i = 0; i < expectedReports.length; i++) {
PublishDiagnosticsParams diag = diags.get(i);
ExpectedProblemReport expected = expectedReports[i];
assertEquals(JDTUtils.toURI(expected.cu), diag.getUri());
if (expected.problemCount != diag.getDiagnostics().size()) {
String message = "";
for (Diagnostic d : diag.getDiagnostics()) {
message += d.getMessage() + ", ";
}
assertEquals(message, expected.problemCount, diag.getDiagnostics().size());
}
}
diags.clear();
}
use of org.eclipse.lsp4j.PublishDiagnosticsParams 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());
}
Aggregations