From 94c2ad0ca89f530f578368e911c69ba2528e6683 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 14 Jan 2016 11:29:22 +0300 Subject: [PATCH] close #92 - refresh project dependencies after build --- dub.json | 2 +- src/dlangide/ui/frame.d | 5 ++++- src/dlangide/workspace/project.d | 34 ++++++++++++++++++++++-------- src/dlangide/workspace/workspace.d | 25 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/dub.json b/dub.json index a768cec..0698aeb 100644 --- a/dub.json +++ b/dub.json @@ -13,7 +13,7 @@ "dependencies": { "dlangui": "~>0.7.37", - "dcd": "~>0.7.5-3" + "dcd": "~>0.7.4" }, "versions": ["EmbedStandardResources"] diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index 19ae0f6..fad7f22 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -1247,7 +1247,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL } void refreshProject(Project project) { - // TODO + if (currentWorkspace && project.loadSelections()) { + currentWorkspace.cleanupUnusedDependencies(); + refreshWorkspace(); + } } void buildProject(BuildOperation buildOp, Project project, BuildResultListener listener = null) { diff --git a/src/dlangide/workspace/project.d b/src/dlangide/workspace/project.d index 9981751..ee17cfb 100644 --- a/src/dlangide/workspace/project.d +++ b/src/dlangide/workspace/project.d @@ -642,37 +642,53 @@ class Project : WorkspaceItem { protected Project[] _dependencies; @property Project[] dependencies() { return _dependencies; } - protected bool addDependency(Project dep) { - if (_workspace) - _workspace.addDependencyProject(dep); - _dependencies ~= dep; - return true; + + Project findDependencyProject(string filename) { + foreach(dep; _dependencies) { + if (dep.filename.equal(filename)) + return dep; + } + return null; } bool loadSelections() { + Project[] newdeps; _dependencies.length = 0; DubPackageFinder finder = new DubPackageFinder(); scope(exit) destroy(finder); SettingsFile selectionsFile = new SettingsFile(buildNormalizedPath(_dir, "dub.selections.json")); - if (!selectionsFile.load()) + if (!selectionsFile.load()) { + _dependencies = newdeps; return false; + } Setting versions = selectionsFile.objectByPath("versions"); - if (!versions.isObject) + if (!versions.isObject) { + _dependencies = newdeps; return false; + } string[string] versionMap = versions.strMap; foreach(packageName, packageVersion; versionMap) { string fn = finder.findPackage(packageName, packageVersion); Log.d("dependency ", packageName, " ", packageVersion, " : ", fn ? fn : "NOT FOUND"); if (fn) { - Project p = new Project(_workspace, fn, packageVersion); + Project p = findDependencyProject(fn); + if (p) { + Log.d("Found existing dependency project ", fn); + newdeps ~= p; + continue; + } + p = new Project(_workspace, fn, packageVersion); if (p.load()) { - addDependency(p); + newdeps ~= p; + if (_workspace) + _workspace.addDependencyProject(p); } else { Log.e("cannot load dependency package ", packageName, " ", packageVersion, " from file ", fn); destroy(p); } } } + _dependencies = newdeps; return true; } } diff --git a/src/dlangide/workspace/workspace.d b/src/dlangide/workspace/workspace.d index 2d15348..452944e 100644 --- a/src/dlangide/workspace/workspace.d +++ b/src/dlangide/workspace/workspace.d @@ -194,6 +194,31 @@ class Workspace : WorkspaceItem { fillStartupProject(); } + Project removeProject(int index) { + if (index < 0 || index > _projects.length) + return null; + Project res = _projects[index]; + for (int j = index; j + 1 < _projects.length; j++) + _projects[j] = _projects[j + 1]; + return res; + } + + bool isDependencyProjectUsed(string filename) { + foreach(p; _projects) + if (!p.isDependency && p.findDependencyProject(filename)) + return true; + return false; + } + + void cleanupUnusedDependencies() { + for (int i = cast(int)_projects.length - 1; i >= 0; i--) { + if (_projects[i].isDependency) { + if (!isDependencyProjectUsed(_projects[i].filename)) + removeProject(i); + } + } + } + bool addDependencyProject(Project p) { for (int i = 0; i < _projects.length; i++) { if (_projects[i].filename.equal(p.filename)) {