/** * Clears already existing diagnostics with the new diagnostics. * * @param client Language server client * @param lastDiagnosticMap last diagnostic map * @param diagnosticMap new diagnostic map */ private void clearDiagnostics(LanguageClient client, Map<String, List<Diagnostic>> lastDiagnosticMap, Map<String, List<Diagnostic>> diagnosticMap) { lastDiagnosticMap.entrySet().stream() .filter(entry -> !diagnosticMap.containsKey(entry.getKey())) .forEach(entry -> client.publishDiagnostics( new PublishDiagnosticsParams(entry.getKey(), EMPTY_DIAGNOSTIC_LIST)) ); }
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($); }
private void cleanUpDiagnostics(String uri){ this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList())); }
@Override public void endReporting() { JavaLanguageServerPlugin.logInfo(problems.size() + " problems reported for " + this.uri.substring(this.uri.lastIndexOf('/'))); PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(this.cu, problems)); this.connection.publishDiagnostics($); }
public void publishDiagnostics(TextDocumentIdentifier docId, Collection<Diagnostic> diagnostics) { LanguageClient client = server.getClient(); if (client!=null && diagnostics!=null) { PublishDiagnosticsParams params = new PublishDiagnosticsParams(); params.setUri(docId.getUri()); params.setDiagnostics(ImmutableList.copyOf(diagnostics)); client.publishDiagnostics(params); } }
/** * Compiles and publishes diagnostics for a source file. * * @param client Language server client * @param lsCompiler LS Compiler * @param filePath file path * @param compilationPath compilation path */ public synchronized void compileAndSendDiagnostics( LanguageClient client, LSCompiler lsCompiler, Path filePath, Path compilationPath) { // Compile diagnostics BallerinaFile balFile = lsCompiler.compileFile(compilationPath, CompilerPhase.COMPILER_PLUGIN); Map<String, List<Diagnostic>> diagnosticMap = getDiagnostics(balFile, filePath); // If the client is null, returns if (client == null) { return; } // Or else, publish diagnostics clearDiagnostics(client, lastDiagnosticMap, diagnosticMap); // Publish diagnostics diagnosticMap.forEach((key, value) -> client.publishDiagnostics(new PublishDiagnosticsParams(key, value))); // Update home-repo packages balFile.getBLangPackage().ifPresent(this::updateHomeRepoPackages); lastDiagnosticMap = diagnosticMap; }
.map(entry -> new PublishDiagnosticsParams(entry.getKey().toString(), entry.getValue())) .collect(Collectors.toSet());
if (!project.equals(projectsManager.getDefaultProject())) { String uri = JDTUtils.getFileURI(project); connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList()));
@Test public void testCompile_withDiagnostics() throws IOException { when(compiler.compile(any())).thenReturn(Sets.newHashSet( new PublishDiagnosticsParams("uri", ImmutableList.of( new Diagnostic(Ranges.UNDEFINED_RANGE, "name", DiagnosticSeverity.Error, "groovyc"))))); wrapper.compile(ImmutableSet.of()); // assert parser wasn't called Mockito.verify(parser, Mockito.never()).parseAllSymbols(); }
connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
private void publishMarkers(IProject project, IMarker[] markers) throws CoreException { Range range = new Range(new Position(0, 0), new Position(0, 0)); List<IMarker> projectMarkers = new ArrayList<>(markers.length); String uri = JDTUtils.getFileURI(project); IFile pom = project.getFile("pom.xml"); List<IMarker> pomMarkers = new ArrayList<>(); for (IMarker marker : markers) { if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) { continue; } if (IMavenConstants.MARKER_CONFIGURATION_ID.equals(marker.getType())) { pomMarkers.add(marker); } else { projectMarkers.add(marker); } } List<Diagnostic> diagnostics = toDiagnosticArray(range, projectMarkers); String clientUri = ResourceUtils.toClientUri(uri); connection.publishDiagnostics(new PublishDiagnosticsParams(clientUri, diagnostics)); if (pom.exists()) { IDocument document = JsonRpcHelpers.toDocument(pom); diagnostics = toDiagnosticsArray(document, pom.findMarkers(null, true, IResource.DEPTH_ZERO)); List<Diagnostic> diagnosicts2 = toDiagnosticArray(range, pomMarkers); diagnostics.addAll(diagnosicts2); connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(clientUri + "/pom.xml"), diagnostics)); } }
private void publishDiagnostics(final URI uri, final Iterable<? extends Issue> issues) { final Consumer<InitializedParams> _function = (InitializedParams it) -> { PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams(); final Procedure1<PublishDiagnosticsParams> _function_1 = (PublishDiagnosticsParams it_1) -> { it_1.setUri(this._uriExtensions.toUriString(uri)); final Function1<Issue, Boolean> _function_2 = (Issue it_2) -> { Severity _severity = it_2.getSeverity(); return Boolean.valueOf((_severity != Severity.IGNORE)); }; final Function1<Issue, Diagnostic> _function_3 = (Issue it_2) -> { return this.toDiagnostic(it_2); }; it_1.setDiagnostics(IterableExtensions.<Diagnostic>toList(IterableExtensions.map(IterableExtensions.filter(issues, _function_2), _function_3))); }; final PublishDiagnosticsParams diagnostics = ObjectExtensions.<PublishDiagnosticsParams>operator_doubleArrow(_publishDiagnosticsParams, _function_1); this.client.publishDiagnostics(diagnostics); }; this.initialized.thenAccept(_function); }
@Test public void testCompile_WithJavaExtensionError() throws InterruptedException, ExecutionException, IOException { File test = addFileToFolder(root.getRoot(), "Test.java", "public class Test {" + "Foo foo;" + "}"); GroovyWorkspaceCompiler compiler = createGroovyWorkspaceCompiler(); Set<PublishDiagnosticsParams> diagnostics = compiler.compile(ImmutableSet.of()); assertEquals(Sets.newHashSet(new PublishDiagnosticsParams( test.toPath().toUri().toString(), ImmutableList.of(new Diagnostic(Ranges.createRange(0, 19, 0, 26), "unable to resolve class Foo \n @ line 1, column 20.", DiagnosticSeverity.Error, GroovyConstants.GROOVY_COMPILER)))), diagnostics); }
@Before public void setup() throws IOException { MockitoAnnotations.initMocks(this); Diagnostic d1 = new Diagnostic(); d1.setMessage("Some message"); d1.setSeverity(DiagnosticSeverity.Error); Diagnostic d2 = new Diagnostic(); d2.setMessage("Some other message"); d2.setSeverity(DiagnosticSeverity.Warning); expectedDiagnostics = Sets.newHashSet(new PublishDiagnosticsParams("uri", ImmutableList.of(d1, d2))); expectedReferences.add(new SymbolInformation( "MyClassName", SymbolKind.Class, new Location("uri", Ranges.createRange(1, 1, 9, 9)), "Something")); expectedReferences.add(new SymbolInformation( "MyClassName2", SymbolKind.Class, new Location("uri", Ranges.createRange(1, 1, 9, 9)), "SomethingElse")); Set<SymbolInformation> allReferencesReturned = Sets.newHashSet(expectedReferences); // The reference that will be filtered out allReferencesReturned.add(new SymbolInformation( "MyClassName3", SymbolKind.Class, new Location("uri", Ranges.UNDEFINED_RANGE), "SomethingElse")); when(compilerWrapper.getWorkspaceRoot()).thenReturn(workspace.getRoot().toPath().toUri()); when(compilerWrapper.compile(any())).thenReturn(expectedDiagnostics); when(compilerWrapper.getFilteredSymbols(any())).thenReturn(allReferencesReturned); when(state.getCompilerWrapper()).thenReturn(compilerWrapper); service = new TestWorkspaceService(state); }
expectedDiagnostics = Sets.newHashSet(new PublishDiagnosticsParams("foo", ImmutableList.of( createDiagnostic("Some message", DiagnosticSeverity.Error, filePath.toString()), createDiagnostic("Some other message", DiagnosticSeverity.Warning, filePath.toString())
new PublishDiagnosticsParams(test1.toPath().toUri().toString(), ImmutableList.of( new Diagnostic( DiagnosticSeverity.Error, GroovyConstants.GROOVY_COMPILER))), new PublishDiagnosticsParams(test2.toPath().toUri().toString(), ImmutableList.of( new Diagnostic(
this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), Collections.emptyList())); return false; this.connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), toDiagnosticsArray(document, markers)));
it.setJsonrpc("2.0"); it.setMethod(MessageMethods.SHOW_DIAGNOSTICS); PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams(); final Procedure1<PublishDiagnosticsParams> _function_1 = (PublishDiagnosticsParams it_1) -> { it_1.setUri("file:///tmp/foo");
it.setJsonrpc("2.0"); it.setMethod(MessageMethods.SHOW_DIAGNOSTICS); PublishDiagnosticsParams _publishDiagnosticsParams = new PublishDiagnosticsParams(); final Procedure1<PublishDiagnosticsParams> _function_1 = (PublishDiagnosticsParams it_1) -> { it_1.setUri("file:///tmp/foo");