Skip to content

Commit 8e81372

Browse files
wenytang-msCopilot
andcommitted
Address source path review feedback
Use a null-safe SourceType comparison and convert sourcePaths matches to the client's expected path format. Extend regression coverage for URI clients and null source types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 38f8a1c commit 8e81372

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StackTraceRequestHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,18 @@ public static Types.Source convertDebuggerSourceToClient(String fullyQualifiedNa
302302
}
303303

304304
private static int getSourceReference(Source source, IDebugAdapterContext context) {
305-
return source.getType().equals(SourceType.REMOTE) ? context.createSourceReference(source.getUri()) : 0;
305+
return SourceType.REMOTE == source.getType() ? context.createSourceReference(source.getUri()) : 0;
306306
}
307307

308308
private static Types.Source resolveSourceFromSourcePaths(String sourceName, String relativeSourcePath,
309309
IDebugAdapterContext context) {
310310
String absoluteSourcepath = AdapterUtils.sourceLookup(context.getSourcePaths(), relativeSourcePath);
311-
return absoluteSourcepath == null ? null : new Types.Source(sourceName, absoluteSourcepath, 0);
311+
if (absoluteSourcepath == null) {
312+
return null;
313+
}
314+
315+
String clientPath = AdapterUtils.convertPath(absoluteSourcepath, false, context.isClientPathsAreUri());
316+
return new Types.Source(sourceName, clientPath, 0);
312317
}
313318

314319
private String formatMethodName(String methodName, List<String> argumentTypeNames, String fqn, boolean showContextClass, boolean showParameter) {

com.microsoft.java.debug.core/src/test/java/com/microsoft/java/debug/core/adapter/handler/StackTraceRequestHandlerTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,37 @@ public void convertDebuggerSourceShouldPreferSourcePathsOverCachedJdtUri() throw
6767

6868
assertEquals(sourceFile.toString(), localSource.path);
6969
assertEquals(0, localSource.sourceReference);
70+
71+
context.setClientPathsAreUri(true);
72+
Types.Source localUriSource = StackTraceRequestHandler.convertDebuggerSourceToClient(fullyQualifiedName,
73+
sourceName, relativeSourcePath, context);
74+
75+
assertEquals(sourceFile.toUri().toString(), localUriSource.path);
76+
verifyAll();
77+
}
78+
79+
@Test
80+
public void convertDebuggerSourceShouldHandleSourceWithNullType() throws Exception {
81+
String fullyQualifiedName = "com.example.Bar";
82+
String sourceName = "Bar.java";
83+
Path sourceFile = tempFolder.newFile(sourceName).toPath();
84+
String sourceUri = sourceFile.toUri().toString();
85+
86+
ISourceLookUpProvider sourceProvider = createMock(ISourceLookUpProvider.class);
87+
expect(sourceProvider.getSource(fullyQualifiedName, sourceName))
88+
.andReturn(new Source(sourceUri, null))
89+
.once();
90+
replayAll();
91+
92+
ProviderContext providerContext = new ProviderContext();
93+
providerContext.registerProvider(ISourceLookUpProvider.class, sourceProvider);
94+
DebugAdapterContext context = new DebugAdapterContext(null, providerContext);
95+
96+
Types.Source source = StackTraceRequestHandler.convertDebuggerSourceToClient(fullyQualifiedName, sourceName,
97+
sourceName, context);
98+
99+
assertEquals(sourceFile.toString(), source.path);
100+
assertEquals(0, source.sourceReference);
70101
verifyAll();
71102
}
72103
}

0 commit comments

Comments
 (0)