3636import com .microsoft .java .debug .core .adapter .IDebugAdapterContext ;
3737import com .microsoft .java .debug .core .adapter .IDebugRequestHandler ;
3838import com .microsoft .java .debug .core .adapter .ISourceLookUpProvider ;
39+ import com .microsoft .java .debug .core .adapter .Source ;
40+ import com .microsoft .java .debug .core .adapter .SourceType ;
3941import com .microsoft .java .debug .core .adapter .formatter .SimpleTypeFormatter ;
4042import com .microsoft .java .debug .core .adapter .variables .StackFrameReference ;
4143import com .microsoft .java .debug .core .protocol .Messages .Response ;
@@ -141,7 +143,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
141143 }
142144
143145 private static List <StackFrameInfo > resolveStackFrameInfos (StackFrame [] frames , boolean async )
144- throws AbsentInformationException , IncompatibleThreadStateException {
146+ throws AbsentInformationException , IncompatibleThreadStateException {
145147 List <StackFrameInfo > jdiFrames = new ArrayList <>();
146148 List <CompletableFuture <Void >> futures = new ArrayList <>();
147149 for (StackFrame frame : frames ) {
@@ -221,7 +223,7 @@ private Types.StackFrame convertDebuggerStackFrameToClient(StackFrameInfo jdiFra
221223 clientSource = null ;
222224 }
223225 } else if (DebugSettings .getCurrent ().debugSupportOnDecompiledSource == Switch .ON
224- && clientSource != null && clientSource .path != null ) {
226+ && clientSource != null && clientSource .path != null ) {
225227 // Align the original line with the decompiled line.
226228 int [] lineMappings = context .getProvider (ISourceLookUpProvider .class ).getOriginalLineMappings (clientSource .path );
227229 int [] renderLines = AdapterUtils .binarySearchMappedLines (lineMappings , clientLineNumber );
@@ -244,7 +246,7 @@ private Types.StackFrame convertDebuggerStackFrameToClient(StackFrameInfo jdiFra
244246 });
245247 if (match ) {
246248 clientColumnNumber = AdapterUtils .convertColumnNumber (breakpoint .getColumnNumber (),
247- context .isDebuggerColumnsStartAt1 (), context .isClientColumnsStartAt1 ());
249+ context .isDebuggerColumnsStartAt1 (), context .isClientColumnsStartAt1 ());
248250 }
249251 }
250252 }
@@ -256,33 +258,44 @@ private Types.StackFrame convertDebuggerStackFrameToClient(StackFrameInfo jdiFra
256258 /**
257259 * Find the source mapping for the specified source file name.
258260 */
259- public static Types .Source convertDebuggerSourceToClient (String fullyQualifiedName , String sourceName , String relativeSourcePath ,
261+ public static Types .Source convertDebuggerSourceToClient (String fullyQualifiedName , String sourceName ,
262+ String relativeSourcePath ,
260263 IDebugAdapterContext context ) throws URISyntaxException {
264+
261265 // use a lru cache for better performance
262- String uri = context .getSourceLookupCache ().computeIfAbsent (fullyQualifiedName , key -> {
263- String fromProvider = context .getProvider (ISourceLookUpProvider .class ).getSourceFileURI (key , relativeSourcePath );
264- // avoid return null which will cause the compute function executed again
265- return StringUtils .isBlank (fromProvider ) ? "" : fromProvider ;
266+ Source source = context .getSourceLookupCache ().computeIfAbsent (fullyQualifiedName , key -> {
267+ Source result = context .getProvider (ISourceLookUpProvider .class ).getSource (key , relativeSourcePath );
268+ if (result == null ) {
269+ return new Source ("" , SourceType .LOCAL );
270+ }
271+ return result ;
266272 });
267273
274+ Integer sourceReference = 0 ;
275+ String uri = source .getUri ();
276+
277+ if (source .getType ().equals (SourceType .REMOTE )) {
278+ sourceReference = context .createSourceReference (source .getUri ());
279+ }
280+
268281 if (!StringUtils .isBlank (uri )) {
269282 // The Source.path could be a file system path or uri string.
270283 if (uri .startsWith ("file:" )) {
271284 String clientPath = AdapterUtils .convertPath (uri , context .isDebuggerPathsAreUri (), context .isClientPathsAreUri ());
272- return new Types .Source (sourceName , clientPath , 0 );
285+ return new Types .Source (sourceName , clientPath , sourceReference );
273286 } else {
274287 // If the debugger returns uri in the Source.path for the StackTrace response, VSCode client will try to find a TextDocumentContentProvider
275288 // to render the contents.
276289 // Language Support for Java by Red Hat extension has already registered a jdt TextDocumentContentProvider to parse the jdt-based uri.
277290 // The jdt uri looks like 'jdt://contents/rt.jar/java.io/PrintStream.class?=1.helloworld/%5C/usr%5C/lib%5C/jvm%5C/java-8-oracle%5C/jre%5C/
278291 // lib%5C/rt.jar%3Cjava.io(PrintStream.class'.
279- return new Types .Source (sourceName , uri , 0 );
292+ return new Types .Source (sourceName , uri , sourceReference );
280293 }
281294 } else {
282295 // If the source lookup engine cannot find the source file, then lookup it in the source directories specified by user.
283296 String absoluteSourcepath = AdapterUtils .sourceLookup (context .getSourcePaths (), relativeSourcePath );
284297 if (absoluteSourcepath != null ) {
285- return new Types .Source (sourceName , absoluteSourcepath , 0 );
298+ return new Types .Source (sourceName , absoluteSourcepath , sourceReference );
286299 } else {
287300 return null ;
288301 }
0 commit comments