Java 类org.eclipse.lsp4j.PublishDiagnosticsParams 实例源码
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
@Test
public void testDidOpenStandaloneFile() 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 {"+
" public void method1(){\n"+
" super.whatever();"+
" }\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(0, diagParam.getDiagnostics().size());
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
@Test
public void testDidOpenNotOnClasspath() throws Exception {
importProjects("eclipse/hello");
IProject project = WorkspaceHelper.getProject("hello");
URI uri = project.getFile("nopackage/Test2.java").getRawLocationURI();
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
String source = FileUtils.readFileToString(FileUtils.toFile(uri.toURL()));
openDocument(cu, source, 1);
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
assertEquals(project, cu.getJavaProject().getProject());
assertEquals(source, cu.getSource());
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals(1, diagParam.getDiagnostics().size());
closeDocument(cu);
Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);
diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(2, diagnosticReports.size());
diagParam = diagnosticReports.get(1);
assertEquals(0, diagParam.getDiagnostics().size());
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
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();
}
项目:xtext-core
文件:AbstractLanguageServerTest.java
protected Map<String, List<Diagnostic>> getDiagnostics() {
try {
final Function1<CancelIndicator, HashMap<String, List<Diagnostic>>> _function = (CancelIndicator it) -> {
final HashMap<String, List<Diagnostic>> result = CollectionLiterals.<String, List<Diagnostic>>newHashMap();
final Function1<Pair<String, Object>, Object> _function_1 = (Pair<String, Object> it_1) -> {
return it_1.getValue();
};
Iterable<PublishDiagnosticsParams> _filter = Iterables.<PublishDiagnosticsParams>filter(ListExtensions.<Pair<String, Object>, Object>map(this.notifications, _function_1), PublishDiagnosticsParams.class);
for (final PublishDiagnosticsParams diagnostic : _filter) {
result.put(diagnostic.getUri(), diagnostic.getDiagnostics());
}
return result;
};
return this.languageServer.getRequestManager().<HashMap<String, List<Diagnostic>>>runRead(_function).get();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
项目:che
文件:PublishDiagnosticsParamsJsonRpcTransmitter.java
@Inject
private void subscribe(EventService eventService, RequestTransmitter requestTransmitter) {
eventService.subscribe(
event -> {
PublishDiagnosticsParams params = event.getParams();
if (params.getUri() != null) {
params.setUri(params.getUri().substring(16));
}
endpointIds.forEach(
endpointId ->
requestTransmitter
.newRequest()
.endpointId(endpointId)
.methodName("textDocument/publishDiagnostics")
.paramsAsDto(new ExtendedPublishDiagnosticsParamsDto(event))
.sendAndSkipResult());
},
ExtendedPublishDiagnosticsParams.class);
}
项目:SOMns-vscode
文件:SomAdapter.java
public void reportDiagnostics(final List<Diagnostic> diagnostics,
final String documentUri) {
if (diagnostics != null) {
PublishDiagnosticsParams result = new PublishDiagnosticsParams();
result.setDiagnostics(diagnostics);
result.setUri(documentUri);
client.publishDiagnostics(result);
}
}
项目:eclipse.jdt.ls
文件:BuildWorkspaceHandler.java
private void publishDiagnostics(List<IMarker> markers) {
Map<IResource, List<IMarker>> map = markers.stream().collect(Collectors.groupingBy(IMarker::getResource));
for (Map.Entry<IResource, List<IMarker>> entry : map.entrySet()) {
IResource resource = entry.getKey();
// ignore problems caused by standalone files
if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject())) {
continue;
}
IFile file = resource.getAdapter(IFile.class);
if (file == null) {
continue;
}
IDocument document = null;
String uri = JDTUtils.getFileURI(resource);
if (JavaCore.isJavaLikeFileName(file.getName())) {
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
try {
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} catch (JavaModelException e) {
logException("Failed to publish diagnostics.", e);
}
}
else if (projectsManager.isBuildFile(file)) {
document = JsonRpcHelpers.toDocument(file);
}
if (document != null) {
List<Diagnostic> diagnostics = WorkspaceDiagnosticsHandler.toDiagnosticsArray(document, entry.getValue().toArray(new IMarker[0]));
connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
}
}
}
项目:eclipse.jdt.ls
文件:WorkspaceDiagnosticsHandler.java
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
// Check if resource is accessible.
// We do not deal with the markers for deleted files here
// WorkspaceEventsHandler removes the diagnostics for deleted resources.
if (resource == null || !resource.isAccessible()) {
return false;
}
if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.ROOT) {
return true;
}
// ignore problems caused by standalone files
if (resource.getType() == IResource.PROJECT) {
return !JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(resource.getProject());
}
// No marker changes continue to visit
if ((delta.getFlags() & IResourceDelta.MARKERS) == 0) {
return false;
}
IFile file = (IFile) resource;
String uri = JDTUtils.getFileURI(resource);
IDocument document = null;
IMarker[] markers = null;
// Check if it is a Java ...
if (JavaCore.isJavaLikeFileName(file.getName())) {
markers = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ONE);
ICompilationUnit cu = (ICompilationUnit) JavaCore.create(file);
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} // or a build file
else if (projectsManager.isBuildFile(file)) {
//all errors on that build file should be relevant
markers = file.findMarkers(null, true, 1);
document = JsonRpcHelpers.toDocument(file);
}
if (document != null) {
this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(document, markers)));
}
return false;
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
@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());
}
项目:eclipse.jdt.ls
文件:DocumentLifeCycleHandlerTest.java
@Test
public void testDidOpenStandaloneFileWithNonSyntaxErrors() 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 {\n"+
" public static void notThis(){\n"+
" System.out.println(this);\n"+
" }\n"+
" public void method1(){\n"+
" }\n"+
" public void method1(){\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(), 3, diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Cannot use this in a static context", d.getMessage());
assertRange(3, 21, 25, d.getRange());
d = diagParam.getDiagnostics().get(1);
assertEquals("Duplicate method method1() in type Foo", d.getMessage());
assertRange(5, 13, 22, d.getRange());
d = diagParam.getDiagnostics().get(2);
assertEquals("Duplicate method method1() in type Foo", d.getMessage());
assertRange(7, 13, 22, d.getRange());
}
项目:eclipse.jdt.ls
文件:WorkspaceDiagnosticsHandlerTest.java
@Test
public void testMarkerListening() throws Exception {
InitHandler initHandler = new InitHandler(projectsManager, preferenceManager, connection);
initHandler.addWorkspaceDiagnosticsHandler();
//import project
importProjects("maven/broken");
ArgumentCaptor<PublishDiagnosticsParams> captor = ArgumentCaptor.forClass(PublishDiagnosticsParams.class);
verify(connection, atLeastOnce()).publishDiagnostics(captor.capture());
List<PublishDiagnosticsParams> allCalls = captor.getAllValues();
Collections.reverse(allCalls);
projectsManager.setConnection(client);
Optional<PublishDiagnosticsParams> fooDiags = allCalls.stream().filter(p -> p.getUri().endsWith("Foo.java")).findFirst();
assertTrue("No Foo.java errors were found", fooDiags.isPresent());
List<Diagnostic> diags = fooDiags.get().getDiagnostics();
Comparator<Diagnostic> comparator = (Diagnostic d1, Diagnostic d2) -> {
int diff = d1.getRange().getStart().getLine() - d2.getRange().getStart().getLine();
if (diff == 0) {
diff = d1.getMessage().compareTo(d2.getMessage());
}
return diff;
};
Collections.sort(diags, comparator );
assertEquals(diags.toString(), 2, diags.size());
assertEquals("The import org cannot be resolved", diags.get(0).getMessage());
assertEquals("StringUtils cannot be resolved", diags.get(1).getMessage());
Optional<PublishDiagnosticsParams> pomDiags = allCalls.stream().filter(p -> p.getUri().endsWith("pom.xml")).findFirst();
assertTrue("No pom.xml errors were found", pomDiags.isPresent());
diags = pomDiags.get().getDiagnostics();
Collections.sort(diags, comparator);
assertEquals(diags.toString(), 3, diags.size());
assertTrue(diags.get(0).getMessage()
.startsWith("For artifact {org.apache.commons:commons-lang3:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources)"));
assertTrue(diags.get(1).getMessage()
.startsWith("For artifact {org.apache.commons:commons-lang3:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-plugin:2.6:testResources:default-testResources:process-test-resources)"));
assertEquals("Project build error: 'dependencies.dependency.version' for org.apache.commons:commons-lang3:jar is missing.", diags.get(2).getMessage());
}
项目:che
文件:PomReconciler.java
public void reconcilePath(String fileLocation, String projectPath) {
String fileName = new Path(fileLocation).lastSegment();
if (!POM_FILE_NAME.equals(fileName)) {
return;
}
EditorWorkingCopy workingCopy = editorWorkingCopyManager.getWorkingCopy(fileLocation);
if (workingCopy == null) {
return;
}
String newPomContent = workingCopy.getContentAsString();
if (isNullOrEmpty(newPomContent)) {
return;
}
List<Problem> problems;
try {
problems = reconcile(fileLocation, projectPath, newPomContent);
List<Diagnostic> diagnostics = convertProblems(newPomContent, problems);
client.publishDiagnostics(
new PublishDiagnosticsParams(LanguageServiceUtils.prefixURI(fileLocation), diagnostics));
} catch (ServerException | NotFoundException e) {
LOG.error(e.getMessage(), e);
client.showMessage(new MessageParams(MessageType.Error, "Error reconciling " + fileLocation));
}
}
项目:che
文件:PomReconciler.java
public void reconcileUri(String uri, String text) {
try {
String pomPath = LanguageServiceUtils.removePrefixUri(uri);
List<Problem> problems = reconcile(pomPath, new File(pomPath).getParent(), text);
List<Diagnostic> diagnostics = convertProblems(text, problems);
client.publishDiagnostics(new PublishDiagnosticsParams(uri, diagnostics));
} catch (ServerException | NotFoundException e) {
LOG.error("Error reconciling content: " + uri, e);
client.showMessage(new MessageParams(MessageType.Error, "Error reconciling " + uri));
}
}
项目:camel-language-server
文件:AbstractCamelLanguageServerTest.java
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
}
项目:eclipse.jdt.ls
文件:DiagnosticsHandler.java
@Override
public void endReporting() {
JavaLanguageServerPlugin.logInfo(problems.size() + " problems reported for " + this.uri.substring(this.uri.lastIndexOf('/')));
PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(problems));
this.connection.publishDiagnostics($);
}
项目:eclipse.jdt.ls
文件:DiagnosticsHandler.java
public void clearDiagnostics() {
JavaLanguageServerPlugin.logInfo("Clearing problems for " + this.uri.substring(this.uri.lastIndexOf('/')));
problems.clear();
PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList());
this.connection.publishDiagnostics($);
}
项目:eclipse.jdt.ls
文件:WorkspaceEventsHandler.java
private void cleanUpDiagnostics(String uri){
this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList()));
}
项目:eclipse.jdt.ls
文件:JavaClientConnection.java
public void publishDiagnostics(PublishDiagnosticsParams diagnostics){
client.publishDiagnostics(diagnostics);
}
项目:xtext-core
文件:CommandRegistryTest.java
public void publishDiagnostics(final PublishDiagnosticsParams diagnostics) {
this.noImpl3.publishDiagnostics(diagnostics);
}
项目:lsp4j
文件:MockLanguageClient.java
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
}
项目:che
文件:CheLanguageClient.java
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
eventService.publish(new ExtendedPublishDiagnosticsParams(serverId, diagnostics));
}
项目:che
文件:ExtendedPublishDiagnosticsParams.java
public ExtendedPublishDiagnosticsParams(String serverId, PublishDiagnosticsParams diagnostics) {
this.languageServerId = serverId;
this.params = diagnostics;
}
项目:che
文件:ExtendedPublishDiagnosticsParams.java
public PublishDiagnosticsParams getParams() {
return params;
}
项目:che
文件:ExtendedPublishDiagnosticsParams.java
public void setParams(PublishDiagnosticsParams params) {
this.params = params;
}
项目:SOMns-vscode
文件:LanguageClient.java
/**
* Diagnostics notifications are sent from the server to the client to
* signal results of validation runs.
*/
@JsonNotification("textDocument/publishDiagnostics")
void publishDiagnostics(PublishDiagnosticsParams diagnostics);
项目:lsp4j
文件:LanguageClient.java
/**
* Diagnostics notifications are sent from the server to the client to
* signal results of validation runs.
*/
@JsonNotification("textDocument/publishDiagnostics")
void publishDiagnostics(PublishDiagnosticsParams diagnostics);