1919import java .util .concurrent .CompletableFuture ;
2020import java .util .stream .Collectors ;
2121
22+ import org .apache .commons .io .filefilter .TrueFileFilter ;
2223import org .apache .commons .lang3 .StringUtils ;
2324
2425import com .microsoft .java .debug .core .DebugUtility ;
2526import com .microsoft .java .debug .core .adapter .AdapterUtils ;
2627import com .microsoft .java .debug .core .adapter .IDebugAdapterContext ;
2728import com .microsoft .java .debug .core .adapter .IDebugRequestHandler ;
2829import com .microsoft .java .debug .core .adapter .ISourceLookUpProvider ;
30+ import com .microsoft .java .debug .core .adapter .IStepFilterProvider ;
2931import com .microsoft .java .debug .core .adapter .formatter .SimpleTypeFormatter ;
3032import com .microsoft .java .debug .core .adapter .variables .StackFrameReference ;
3133import com .microsoft .java .debug .core .protocol .Messages .Response ;
3234import com .microsoft .java .debug .core .protocol .Requests .Arguments ;
3335import com .microsoft .java .debug .core .protocol .Requests .Command ;
3436import com .microsoft .java .debug .core .protocol .Requests .StackTraceArguments ;
37+ import com .microsoft .java .debug .core .protocol .Requests ;
3538import com .microsoft .java .debug .core .protocol .Responses ;
3639import com .microsoft .java .debug .core .protocol .Types ;
3740import com .sun .jdi .AbsentInformationException ;
4144import com .sun .jdi .ObjectCollectedException ;
4245import com .sun .jdi .StackFrame ;
4346import com .sun .jdi .ThreadReference ;
47+ import java .util .Optional ;
4448
4549public class StackTraceRequestHandler implements IDebugRequestHandler {
4650
@@ -61,22 +65,30 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
6165 int totalFrames = 0 ;
6266 if (thread != null ) {
6367 try {
68+
6469 totalFrames = thread .frameCount ();
6570 if (totalFrames <= stacktraceArgs .startFrame ) {
6671 response .body = new Responses .StackTraceResponseBody (result , totalFrames );
6772 return CompletableFuture .completedFuture (response );
6873 }
6974 StackFrame [] frames = context .getStackFrameManager ().reloadStackFrames (thread );
70-
75+
7176 int count = stacktraceArgs .levels == 0 ? totalFrames - stacktraceArgs .startFrame
7277 : Math .min (totalFrames - stacktraceArgs .startFrame , stacktraceArgs .levels );
7378 for (int i = stacktraceArgs .startFrame ; i < frames .length && count -- > 0 ; i ++) {
7479 StackFrameReference stackframe = new StackFrameReference (thread , i );
7580 int frameId = context .getRecyclableIdPool ().addObject (thread .uniqueID (), stackframe );
76- result .add (convertDebuggerStackFrameToClient (frames [i ], frameId , context ));
81+ IStepFilterProvider stackTraceFilterProvider = context .getProvider (IStepFilterProvider .class );
82+ Optional <String > optionalFormattedName = stackTraceFilterProvider .formatMethodName (thread .frame (i ).location ().method ());
83+
84+
85+ if (!stackTraceFilterProvider .shouldSkipFrame (thread .frame (i ).location ().method ()) && !optionalFormattedName .isEmpty () )
86+ result .add (convertDebuggerStackFrameToClient (frames [i ], frameId , context ,optionalFormattedName .get ()));
7787 }
7888 } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException
7989 | AbsentInformationException | ObjectCollectedException e ) {
90+ e .printStackTrace ();
91+ System .out .println (e .getMessage ());
8092 // when error happens, the possible reason is:
8193 // 1. the vscode has wrong parameter/wrong uri
8294 // 2. the thread actually terminates
@@ -87,25 +99,26 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
8799 return CompletableFuture .completedFuture (response );
88100 }
89101
90- private Types .StackFrame convertDebuggerStackFrameToClient (StackFrame stackFrame , int frameId , IDebugAdapterContext context )
102+ private Types .StackFrame convertDebuggerStackFrameToClient (StackFrame stackFrame , int frameId , IDebugAdapterContext context , String formattedName )
91103 throws URISyntaxException , AbsentInformationException {
92104 Location location = stackFrame .location ();
93105 Method method = location .method ();
94106 Types .Source clientSource = this .convertDebuggerSourceToClient (location , context );
95- String methodName = formatMethodName (method , true , true );
107+ // String methodName = formatMethodName(method, true, true,formattedName );
96108 int lineNumber = AdapterUtils .convertLineNumber (location .lineNumber (), context .isDebuggerLinesStartAt1 (), context .isClientLinesStartAt1 ());
97109 // Line number returns -1 if the information is not available; specifically, always returns -1 for native methods.
98110 if (lineNumber < 0 ) {
99111 if (method .isNative ()) {
100112 // For native method, display a tip text "native method" in the Call Stack View.
101- methodName += "[native method]" ;
113+ formattedName += "[native method]" ;
102114 } else {
103115 // For other unavailable method, such as lambda expression's built-in methods run/accept/apply,
104116 // display "Unknown Source" in the Call Stack View.
105117 clientSource = null ;
106118 }
107119 }
108- return new Types .StackFrame (frameId , methodName , clientSource , lineNumber , context .isClientColumnsStartAt1 () ? 1 : 0 );
120+
121+ return new Types .StackFrame (frameId , formattedName , clientSource , lineNumber , context .isClientColumnsStartAt1 () ? 1 : 0 );
109122 }
110123
111124 private Types .Source convertDebuggerSourceToClient (Location location , IDebugAdapterContext context ) throws URISyntaxException {
@@ -133,6 +146,7 @@ public static Types.Source convertDebuggerSourceToClient(String fullyQualifiedNa
133146 IDebugAdapterContext context ) throws URISyntaxException {
134147 // use a lru cache for better performance
135148 String uri = context .getSourceLookupCache ().computeIfAbsent (fullyQualifiedName , key -> {
149+
136150 String fromProvider = context .getProvider (ISourceLookUpProvider .class ).getSourceFileURI (key , relativeSourcePath );
137151 // avoid return null which will cause the compute function executed again
138152 return StringUtils .isBlank (fromProvider ) ? "" : fromProvider ;
@@ -162,14 +176,14 @@ public static Types.Source convertDebuggerSourceToClient(String fullyQualifiedNa
162176 }
163177 }
164178
165- private String formatMethodName (Method method , boolean showContextClass , boolean showParameter ) {
179+ private String formatMethodName (Method method , boolean showContextClass , boolean showParameter , String formattedNameString ) {
166180 StringBuilder formattedName = new StringBuilder ();
167- if (showContextClass ) {
168- String fullyQualifiedClassName = method .declaringType ().name ();
169- formattedName .append (SimpleTypeFormatter .trimTypeName (fullyQualifiedClassName ));
181+ /* if (showContextClass) {
182+ // String fullyQualifiedClassName = method.declaringType().name();
183+ formattedName.append(SimpleTypeFormatter.trimTypeName(formattedNameString ));
170184 formattedName.append(".");
171- }
172- formattedName .append (method . name () );
185+ }*/
186+ formattedName .append (formattedNameString );
173187 if (showParameter ) {
174188 List <String > argumentTypeNames = method .argumentTypeNames ().stream ().map (SimpleTypeFormatter ::trimTypeName ).collect (Collectors .toList ());
175189 formattedName .append ("(" );
0 commit comments