Skip to content

Commit

Permalink
Reduce unnecesary diagnostic.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaohaizh committed Nov 14, 2018
1 parent c8f676e commit 3dc6a0c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ public void handleClosed(DidCloseTextDocumentParams params) {
return;
}
try {
synchronized (toReconcile) {
toReconcile.remove(unit);
}
if (JDTUtils.isDefaultProject(unit) || !JDTUtils.isOnClassPath(unit) || unit.getResource().isDerived()) {
new DiagnosticsHandler(connection, unit).clearDiagnostics();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private void toggleCapability(boolean enabled, String id, String capability, Obj
@Override
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
logInfo(">> workspace/didChangeWatchedFiles ");
WorkspaceEventsHandler handler = new WorkspaceEventsHandler(pm, client);
WorkspaceEventsHandler handler = new WorkspaceEventsHandler(pm, client, this.documentLifeCycleHandler);
handler.didChangeWatchedFiles(params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public boolean visit(IResourceDelta delta) throws CoreException {
markers = Arrays.copyOf(javaMarkers, javaMarkers.length + taskMarkers.length);
System.arraycopy(taskMarkers, 0, markers, javaMarkers.length, taskMarkers.length);
ICompilationUnit cu = (ICompilationUnit) JavaCore.create(file);
document = JsonRpcHelpers.toDocument(cu.getBuffer());
if (!cu.isWorkingCopy()) {
document = JsonRpcHelpers.toDocument(cu.getBuffer());
}
} // or a build file
else if (projectsManager.isBuildFile(file)) {
//all errors on that build file should be relevant
Expand Down Expand Up @@ -230,10 +232,12 @@ private void publishDiagnostics(List<IMarker> markers) {
String uri = JDTUtils.getFileURI(resource);
if (JavaCore.isJavaLikeFileName(file.getName())) {
ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
try {
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Failed to publish diagnostics.", e);
if (!cu.isWorkingCopy()) {
try {
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Failed to publish diagnostics.", e);
}
}
} else if (projectsManager.isBuildFile(file)) {
document = JsonRpcHelpers.toDocument(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
import org.eclipse.lsp4j.DidCloseTextDocumentParams;
import org.eclipse.lsp4j.FileChangeType;
import org.eclipse.lsp4j.FileEvent;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.TextDocumentIdentifier;

public class WorkspaceEventsHandler {

private final ProjectsManager pm ;
private final JavaClientConnection connection;
private final DocumentLifeCycleHandler handler;

public WorkspaceEventsHandler(ProjectsManager projects, JavaClientConnection connection ) {
public WorkspaceEventsHandler(ProjectsManager projects, JavaClientConnection connection, DocumentLifeCycleHandler handler) {
this.pm = projects;
this.connection = connection;
this.handler = handler;
}

private CHANGE_TYPE toChangeType(FileChangeType vtype){
Expand All @@ -63,6 +67,7 @@ void didChangeWatchedFiles(DidChangeWatchedFilesParams param){
CHANGE_TYPE changeType = toChangeType(fileEvent.getType());
if(changeType==CHANGE_TYPE.DELETED){
cleanUpDiagnostics(fileEvent.getUri());
handler.didClose(new DidCloseTextDocumentParams(new TextDocumentIdentifier(fileEvent.getUri())));
}
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(fileEvent.getUri());
if (unit != null && changeType == CHANGE_TYPE.CREATED && !unit.exists()) {
Expand Down

0 comments on commit 3dc6a0c

Please sign in to comment.