Skip to content

Commit

Permalink
Fix a project caching issue during debugger restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
NipunaRanasinghe committed Dec 4, 2024
1 parent 0d9e94d commit 38a426c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,8 @@ public DebugProjectCache() {
public Project getProject(Path filePath) {
Map.Entry<ProjectKind, Path> projectKindAndRoot = computeProjectKindAndRoot(filePath);
Path projectRoot = projectKindAndRoot.getValue();
if (!loadedProjects.containsKey(projectRoot)) {
addProject(loadProject(filePath.toAbsolutePath().toString()));
}
return loadedProjects.get(projectRoot);
}

/**
* Adds the given project instance into the cache.
*
* @param project project instance.
*/
public void addProject(Project project) {
Path projectSourceRoot = project.sourceRoot().toAbsolutePath();
loadedProjects.put(projectSourceRoot, project);
return loadedProjects.computeIfAbsent(projectRoot, key -> loadProject(projectKindAndRoot));
}

/**
Expand All @@ -78,13 +66,10 @@ public void clear() {
/**
* Loads the target ballerina source project instance using the Project API, from the file path of the open/active
* editor instance in the client(plugin) side.
*
* @param filePath file path of the open/active editor instance in the plugin side.
*/
private static Project loadProject(String filePath) {
Map.Entry<ProjectKind, Path> projectKindAndProjectRootPair = computeProjectKindAndRoot(Path.of(filePath));
ProjectKind projectKind = projectKindAndProjectRootPair.getKey();
Path projectRoot = projectKindAndProjectRootPair.getValue();
private static Project loadProject(Map.Entry<ProjectKind, Path> projectKindAndRoot) {
ProjectKind projectKind = projectKindAndRoot.getKey();
Path projectRoot = projectKindAndRoot.getValue();
BuildOptions options = BuildOptions.builder().setOffline(true).build();
if (projectKind == ProjectKind.BUILD_PROJECT) {
return BuildProject.load(projectRoot, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,12 @@ public Project getSourceProject() {
public void setSourceProject(Project sourceProject) {
this.sourceProject = sourceProject;
this.setSourceProjectRoot(sourceProject.sourceRoot().toAbsolutePath().toString());
updateProjectCache(sourceProject);
}

public DebugProjectCache getProjectCache() {
return projectCache;
}

public void updateProjectCache(Project project) {
this.projectCache.addProject(project);
}

public String getSourceProjectRoot() {
return sourceProjectRoot;
}
Expand Down

0 comments on commit 38a426c

Please sign in to comment.