Skip to content

Commit 9480e11

Browse files
authored
fix: Use logException() when catching the error (#22)
1 parent 4dcd382 commit 9480e11

File tree

8 files changed

+21
-33
lines changed

8 files changed

+21
-33
lines changed

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/LanguageServerIndexerPlugin.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import java.io.PrintStream;
99

10-
import org.eclipse.core.runtime.CoreException;
1110
import org.eclipse.core.runtime.ILogListener;
1211
import org.eclipse.core.runtime.IStatus;
1312
import org.eclipse.core.runtime.Platform;
@@ -32,7 +31,8 @@ public void start(BundleContext context) throws Exception {
3231
Platform.getLog(LanguageServerIndexerPlugin.context.getBundle()).addLogListener(new ILogListener() {
3332
@Override
3433
public void logging(IStatus status, String plugin) {
35-
LanguageServerIndexerPlugin.out.println(status.getMessage());
34+
out.println(); // Make sure the log will ruin the emitter output line.
35+
out.println(status.getMessage());
3636
if (status.getException() != null) {
3737
status.getException().printStackTrace(LanguageServerIndexerPlugin.out);
3838
}
@@ -45,16 +45,6 @@ public void logging(IStatus status, String plugin) {
4545
public void stop(BundleContext context) throws Exception {
4646
}
4747

48-
public static void log(IStatus status) {
49-
if (context != null) {
50-
Platform.getLog(LanguageServerIndexerPlugin.context.getBundle()).log(status);
51-
}
52-
}
53-
54-
public static void log(CoreException e) {
55-
log(e.getStatus());
56-
}
57-
5848
public static void logError(String message) {
5949
if (context != null) {
6050
log(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), message));
@@ -84,4 +74,10 @@ public static void println() {
8474
public static void println(String message) {
8575
out.println(message);
8676
}
77+
78+
private static void log(IStatus status) {
79+
if (context != null) {
80+
Platform.getLog(LanguageServerIndexerPlugin.context.getBundle()).log(status);
81+
}
82+
}
8783
}

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/indexer/IdGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public IdGenerator(IdType type) {
2525
public String next() {
2626
switch (idtype) {
2727
case COUNTER:
28-
counter.incrementAndGet();
29-
return String.valueOf(counter);
28+
return String.valueOf(counter.incrementAndGet());
3029
case UUID:
3130
return UUID.randomUUID().toString();
3231
default:

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DefinitionVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package com.microsoft.java.lsif.core.internal.visitors;
77

8-
import org.eclipse.core.runtime.CoreException;
98
import org.eclipse.core.runtime.NullProgressMonitor;
109
import org.eclipse.jdt.core.IJavaElement;
1110
import org.eclipse.jdt.core.dom.SimpleName;
@@ -78,8 +77,8 @@ private void emitDefinition(int startPosition, int length) {
7877
LsifEmitter.getInstance().emit(defResult);
7978
LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().definition(resultSet, defResult));
8079

81-
} catch (CoreException ex) {
82-
LanguageServerIndexerPlugin.logException("Exception in definition visitor: ", ex);
80+
} catch (Throwable ex) {
81+
LanguageServerIndexerPlugin.logException("Exception when dumping definition information ", ex);
8382
}
8483
}
8584

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/DiagnosticVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public void enlist() {
6363
markers = Arrays.copyOf(javaMarkers, javaMarkers.length + taskMarkers.length);
6464
System.arraycopy(taskMarkers, 0, markers, javaMarkers.length, taskMarkers.length);
6565
document = JsonRpcHelpers.toDocument(cu.getJavaElement().getOpenable().getBuffer());
66-
} catch (CoreException ex) {
67-
LanguageServerIndexerPlugin.logException("Exception when dumping diagnostics ", ex);
66+
} catch (Throwable ex) {
67+
LanguageServerIndexerPlugin.logException("Exception when dumping diagnostic information ", ex);
6868
return;
6969
}
7070

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/HoverVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.List;
99

1010
import org.apache.commons.lang3.StringUtils;
11-
import org.eclipse.core.runtime.CoreException;
1211
import org.eclipse.core.runtime.NullProgressMonitor;
1312
import org.eclipse.jdt.core.dom.SimpleName;
1413
import org.eclipse.jdt.core.dom.SimpleType;
@@ -69,8 +68,8 @@ private void emitHover(int startPosition, int length) {
6968

7069
HoverResult hoverResult = Repository.getInstance().enlistHoverResult(this.getContext(), result);
7170
LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().hover(resultSet, hoverResult));
72-
} catch (CoreException e) {
73-
LanguageServerIndexerPlugin.log(e);
71+
} catch (Throwable ex) {
72+
LanguageServerIndexerPlugin.logException("Exception when dumping hover information ", ex);
7473
}
7574
}
7675

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ImplementationsVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.stream.Collectors;
1111

12-
import org.eclipse.core.runtime.CoreException;
1312
import org.eclipse.core.runtime.NullProgressMonitor;
1413
import org.eclipse.jdt.core.dom.ASTNode;
1514
import org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -81,8 +80,8 @@ private void emitImplementation(int startPosition, int length) {
8180
LsifEmitter.getInstance().emit(implResult);
8281
LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().implementation(resultSet, implResult));
8382

84-
} catch (CoreException ex) {
85-
LanguageServerIndexerPlugin.logException("Exception when visiting implementation ", ex);
83+
} catch (Throwable ex) {
84+
LanguageServerIndexerPlugin.logException("Exception when dumping implementation information ", ex);
8685
}
8786
}
8887

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/ReferencesVisitor.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.List;
99
import java.util.stream.Collectors;
1010

11-
import org.eclipse.core.runtime.CoreException;
1211
import org.eclipse.core.runtime.NullProgressMonitor;
1312
import org.eclipse.jdt.core.dom.SimpleName;
1413
import org.eclipse.jdt.core.dom.SimpleType;
@@ -79,10 +78,8 @@ public void emitReferences(int startPosition, int length) {
7978
LsifEmitter.getInstance()
8079
.emit(lsif.getEdgeBuilder().referenceItem(refResult, r, ReferenceItem.REFERENCE));
8180
}
82-
} catch (
83-
84-
CoreException ex) {
85-
LanguageServerIndexerPlugin.logException("Exception in visit references ", ex);
81+
} catch (Throwable ex) {
82+
LanguageServerIndexerPlugin.logException("Exception when dumping reference information ", ex);
8683
}
8784
}
8885

com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/visitors/TypeDefinitionVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import java.util.List;
99

10-
import org.eclipse.core.runtime.CoreException;
1110
import org.eclipse.core.runtime.NullProgressMonitor;
1211
import org.eclipse.jdt.core.dom.SimpleName;
1312
import org.eclipse.jdt.core.dom.SimpleType;
@@ -81,8 +80,8 @@ private void emitTypeDefinition(int startPosition, int length) {
8180
TypeDefinitionResult defResult = lsif.getVertexBuilder().typeDefinitionResult(targetRange.getId());
8281
LsifEmitter.getInstance().emit(defResult);
8382
LsifEmitter.getInstance().emit(lsif.getEdgeBuilder().typeDefinition(resultSet, defResult));
84-
} catch (CoreException e) {
85-
LanguageServerIndexerPlugin.log(e);
83+
} catch (Throwable ex) {
84+
LanguageServerIndexerPlugin.logException("Exception when dumping type definition information ", ex);
8685
}
8786
}
8887

0 commit comments

Comments
 (0)