Looking up the stack frame's associated source file from source containers directly to improve searching perf and bugs#127
Conversation
| @@ -164,17 +170,32 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th | |||
|
|
|||
| @Override | |||
| public String getSourceFileURI(String fullyQualifiedName, String sourcePath) { | |||
There was a problem hiding this comment.
Seems like the fullyQualifiedName is never used. Shall we just delete it?
There was a problem hiding this comment.
Different provider implementation may have different source lookup mechanism. I prefer to keep current interface design.
If there is user compliant, i'd like to change the interface to public String getSourceFileURI(StackFrame stackFrame).
From the stack frame, the provider could get more info for accurate searching, such as class name, source name, source path, even source info for the specified stratum (like scala).
| // But because the inner class and anonymous class have the same java file as the enclosing type, | ||
| // search their enclosing type instead. | ||
| if (fullyQualifiedName.indexOf("$") >= 0) { | ||
| return searchDeclarationFileByFqn(AdapterUtils.parseEnclosingType(fullyQualifiedName)); |
There was a problem hiding this comment.
Please delete the obsolete method searchDeclarationFileByFqn and searchDeclarationFileByFqn. And even AdapterUtils.parseEnclosingType.
| * the current project name. | ||
| * @return the possible source container list. | ||
| */ | ||
| public static ISourceContainer[] getSourceContainers(String currentProject) { |
There was a problem hiding this comment.
A static function is typically stateless. So it usually does not have the knowledge of the "current" project. Suggest using the more stateless name "projectName".
|
|
||
| List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()); | ||
| projects.addAll(workspaceProjects.stream().filter((project) -> { | ||
| return !project.equals(targetProject); |
There was a problem hiding this comment.
Maybe we can just use whatever returned by getProjects() instead of filtering out the targetProject. The logic seems redundant. The project collection should already have the target project. So this function can have no parameter.
There was a problem hiding this comment.
The original purpose is "If the project name is specified, it will put the source containers from the specified project in the front of the result. "
The filter logic is to remove duplicated project to avoid duplicated computation.
Yes, it's unnecessary, because the final source container result is a set object, it'll remove the duplicated source container. Will change it as follows.
IProject targetProject = JdtUtils.getProject(projectName);
if (targetProject != null) {
projects.add(targetProject);
}
List workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
projects.addAll(workspaceProjects);
| } | ||
|
|
||
| private static ISourceContainer[] getSourceContainers(IJavaProject project, Set<IRuntimeClasspathEntry> calculated) { | ||
| if (project != null && project.exists()) { |
There was a problem hiding this comment.
Use early return.
if (project == null || !project.exists()) {
return empty;
}
In this way we avoid indenting large chunk of code.
| projects.addAll(workspaceProjects.stream().filter((project) -> { | ||
| return !project.equals(targetProject); | ||
| }).collect(Collectors.toList())); | ||
| projects.addAll(workspaceProjects); |
There was a problem hiding this comment.
There can be duplicated entries inside the projects collection. The targetProject is already inside.
ResourcesPlugin.getWorkspace().getRoot().getProjects()
JdtUtils.getProject(projectName)
Does the return value of the first call contain the return value of the second call?
There was a problem hiding this comment.
YES, it contains the second result.
There was a problem hiding this comment.
But it's OK to have duplicated projects because the later computation code has logic to avoid repeated calculation on the duplicated classpath entries.
| List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()); | ||
| projects.addAll(workspaceProjects); | ||
|
|
||
| Set<IRuntimeClasspathEntry> calculated = new LinkedHashSet<>(); |
There was a problem hiding this comment.
Use Java.Stream to optimize the coding logic below
There was a problem hiding this comment.
nice. fixed.
|
|
||
| Set<IRuntimeClasspathEntry> calculated = new LinkedHashSet<>(); | ||
|
|
||
| projects.stream().map(project -> JdtUtils.getJavaProject(project)) |
There was a problem hiding this comment.
Suggest using distinct() to avoid duplicates.
See the feature description microsoft/vscode-java-debug#121
Previous debugger use jdt search engine to look up the associated source file for the stack frame, but it has several issues: