Skip to content

Commit 770293e

Browse files
committed
fix: remove project node before scanning with Delta
1 parent 3da99f1 commit 770293e

4 files changed

Lines changed: 41 additions & 12 deletions

File tree

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/ContentRootNode.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ContentRootNode extends BaseTreeNode {
2222
public ContentRootNode(String name, Path value) {
2323
super(value);
2424
reset();
25-
this.name = name;
25+
this.setName(name);
2626
this.setPath(value);
2727
}
2828

@@ -79,7 +79,7 @@ public void reset() {
7979

8080
@Override
8181
public String getText() {
82-
return name;
82+
return getName();
8383
}
8484

8585
public Path getPath() {
@@ -89,4 +89,12 @@ public Path getPath() {
8989
public void setPath(Path path) {
9090
this.path = path.normalize();
9191
}
92+
93+
public String getName() {
94+
return name;
95+
}
96+
97+
public void setName(String name) {
98+
this.name = name;
99+
}
92100
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/ISnykToolView.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,11 @@ static String getPlural(long count) {
115115
* @return
116116
*/
117117
abstract void disableDelta();
118+
119+
/**
120+
* Remove the scan results for the Project from the TreeViewer.
121+
*
122+
* @param project
123+
*/
124+
abstract void resetContentRootNode(String project);
118125
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/SnykToolView.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ public ProductTreeNode getProductNode(String product, String folderPath) {
186186
return null;
187187
}
188188

189+
@Override
190+
public void resetContentRootNode(String project) {
191+
if (project == null ) {
192+
return;
193+
}
194+
195+
for (TreeNode child : rootObject.getChildren()) {
196+
if (child instanceof ContentRootNode) {
197+
ContentRootNode contentRoot = (ContentRootNode) child;
198+
if (project.startsWith(contentRoot.getName())) {
199+
resetNode(contentRoot);
200+
}
201+
}
202+
}
203+
}
204+
189205
@Override
190206
public BaseTreeNode getRoot() {
191207
return ((RootNode) treeViewer.getInput());
@@ -281,7 +297,7 @@ public void enableDelta() {
281297
TreeItem[] rootItems = getTreeViewer().getTree().getItems();
282298
for (TreeItem item : rootItems) {
283299
ContentRootNode node = (ContentRootNode) item.getData();
284-
String projectName = node.getText().toString();
300+
String projectName = node.getName();
285301
String projectPath = node.getPath().toString();
286302
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
287303
String baseBranch = preferenceState.getBaseBranch(projectPath);
@@ -327,7 +343,7 @@ private void clearDeltaNodeListeners() {
327343
Listener listener = entry.getValue();
328344

329345
ContentRootNode node = (ContentRootNode) item.getData();
330-
String project = node.getText().toString();
346+
String project = node.getName();
331347

332348
// Revert text to original
333349
item.setText(project);

plugin/src/main/java/io/snyk/languageserver/protocolextension/SnykExtendedLanguageClient.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
5959
import org.eclipse.lsp4j.services.LanguageServer;
6060
import org.eclipse.swt.widgets.Display;
61-
import org.eclipse.ui.ISelectionService;
6261
import org.eclipse.ui.IWorkbenchPage;
63-
import org.eclipse.ui.IWorkbenchWindow;
6462
import org.eclipse.ui.PartInitException;
6563
import org.eclipse.ui.PlatformUI;
6664

@@ -74,7 +72,6 @@
7472
import io.snyk.eclipse.plugin.properties.preferences.EclipsePreferenceState;
7573
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
7674
import io.snyk.eclipse.plugin.utils.SnykLogger;
77-
import io.snyk.eclipse.plugin.views.SnykView;
7875
import io.snyk.eclipse.plugin.views.snyktoolview.FileTreeNode;
7976
import io.snyk.eclipse.plugin.views.snyktoolview.ISnykToolView;
8077
import io.snyk.eclipse.plugin.views.snyktoolview.InfoTreeNode;
@@ -182,19 +179,20 @@ public void triggerScan(IProject project) {
182179
runSnykWizard();
183180
} else {
184181
openToolView();
185-
this.toolView.resetNode(this.toolView.getRoot());
186182

187183
if (Preferences.getInstance().getBooleanPref(Preferences.FILTER_DELTA_NEW_ISSUES))
188184
this.toolView.enableDelta();
189185

190186
try {
191-
if (project == null) {
192-
executeCommand(LsCommandID.COMMAND_WORKSPACE_SCAN, new ArrayList<>());
187+
if (project != null) {
188+
this.toolView.resetContentRootNode(project.getName());
189+
executeCommand(LsCommandID.COMMAND_WORKSPACE_FOLDER_SCAN,
190+
List.of(project.getLocation().toOSString()));
193191
return;
194192
}
195193

196-
executeCommand(LsCommandID.COMMAND_WORKSPACE_FOLDER_SCAN,
197-
List.of(project.getLocation().toOSString()));
194+
this.toolView.resetNode(this.toolView.getRoot());
195+
executeCommand(LsCommandID.COMMAND_WORKSPACE_SCAN, new ArrayList<>());
198196

199197
Object firstElement = structured.getFirstElement();
200198
IProject project = null;

0 commit comments

Comments
 (0)