Skip to content

Commit 42da586

Browse files
authored
feat: get Issues from LS (#212)
* feat: get Issues from LS
1 parent 4ed6db1 commit 42da586

15 files changed

Lines changed: 619 additions & 27 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.snyk.eclipse.plugin.domain;
2+
3+
public interface ProductConstants {
4+
public static final String OSS = "oss";
5+
public static final String CODE = "code";
6+
public static final String IAC = "iac";
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.snyk.languageserver;
2+
3+
public interface LsCommandID {
4+
public static final String SNYK_LOGIN = "snyk.login";
5+
public static final String SNYK_GET_ACTIVE_USER = "snyk.getActiveUser";
6+
public static final String SNYK_WORKSPACE_SCAN = "snyk.workspace.scan";
7+
public static final String SNYK_WORKSPACE_FOLDER_SCAN = "snyk.workspaceFolder.scan";
8+
public static final String SNYK_TRUST_WORKSPACE_FOLDERS = "snyk.trustWorkspaceFolders";
9+
public static final String SNYK_SAST_ENABLED = "snyk.getSettingsSastEnabled";
10+
public static final String SNYK_GENERATE_ISSUE_DESCRIPTION = "snyk.generateIssueDescription";
11+
public static final String SNYK_REPORT_ANALYTICS = "snyk.reportAnalytics";
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.snyk.languageserver;
2+
3+
public interface LsNotificationID {
4+
public static final String SNYK_HAS_AUTHENTICATED = "$/snyk.hasAuthenticated";
5+
public static final String SNYK_IS_AVAILABLE_CLI = "$/snyk.isAvailableCli";
6+
public static final String SNYK_ADD_TRUSTED_FOLDERS = "$/snyk.addTrustedFolders";
7+
public static final String SNYK_SCAN = "$/snyk.scan";
8+
public static final String SNYK_PUBLISH_DIAGNOSTICS_316 = "$/snyk.publishDiagnostics316";
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.snyk.languageserver;
2+
3+
public record ScanInProgressKey(String folderPath, String product) {
4+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.snyk.languageserver;
2+
3+
import java.util.concurrent.ConcurrentHashMap;
4+
5+
public class ScanState {
6+
private ScanState() {
7+
8+
}
9+
10+
private final ConcurrentHashMap<ScanInProgressKey, Boolean> scanInProgress = new ConcurrentHashMap<>();
11+
12+
private static ScanState instance = new ScanState();
13+
public static ScanState getInstance() {
14+
if (instance == null) {
15+
synchronized (ScanState.class) {
16+
if (instance == null) {
17+
instance = new ScanState();
18+
}
19+
}
20+
}
21+
return instance;
22+
}
23+
24+
// ----- Methods to Manage Scan States -----
25+
26+
/**
27+
* Checks if a scan is in progress for the given key.
28+
*
29+
* @param key The ScanInProgressKey identifying the scan
30+
* @return true if the scan is in progress, false otherwise
31+
*/
32+
public boolean isScanInProgress(ScanInProgressKey key) {
33+
return scanInProgress.getOrDefault(key, false);
34+
}
35+
36+
/**
37+
* Sets the scan state for the given key.
38+
*
39+
* @param key The ScanInProgressKey identifying the scan
40+
* @param inProgress true if the scan is in progress, false otherwise
41+
*/
42+
public void setScanInProgress(ScanInProgressKey key, boolean inProgress) {
43+
scanInProgress.put(key, inProgress);
44+
}
45+
46+
/**
47+
* Removes the scan state for the given key.
48+
*
49+
* @param key The ScanInProgressKey identifying the scan
50+
*/
51+
public void removeScanState(ScanInProgressKey key) {
52+
scanInProgress.remove(key);
53+
}
54+
55+
/**
56+
* Clears all scan states.
57+
*/
58+
public void clearAllScanStates() {
59+
scanInProgress.clear();
60+
}
61+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package io.snyk.languageserver;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.concurrent.ConcurrentHashMap;
6+
7+
import io.snyk.languageserver.protocolextension.messageObjects.scanResults.Issue;
8+
9+
public class SnykIssueCache {
10+
private static SnykIssueCache instance = new SnykIssueCache();
11+
12+
private final ConcurrentHashMap<String, Collection<Issue>> snykCodeIssueHashMap = new ConcurrentHashMap<>();
13+
private final ConcurrentHashMap<String, Collection<Issue>> snykOssIssueHashMap = new ConcurrentHashMap<>();
14+
private final ConcurrentHashMap<String, Collection<Issue>> snykIaCIssueHashMap = new ConcurrentHashMap<>();
15+
16+
private SnykIssueCache() {
17+
}
18+
19+
public static SnykIssueCache getInstance() {
20+
if (instance == null) {
21+
synchronized (SnykIssueCache.class) {
22+
if (instance == null) {
23+
instance = new SnykIssueCache();
24+
}
25+
}
26+
}
27+
return instance;
28+
}
29+
30+
/** Clears all issue caches */
31+
public void clearAll() {
32+
snykCodeIssueHashMap.clear();
33+
snykOssIssueHashMap.clear();
34+
snykIaCIssueHashMap.clear();
35+
}
36+
37+
/**
38+
* Removes all issues for a given path from all caches
39+
*
40+
* @param path The file path for which issues should be removed
41+
*/
42+
public void removeAllIssuesForPath(String path) {
43+
snykCodeIssueHashMap.remove(path);
44+
snykOssIssueHashMap.remove(path);
45+
snykIaCIssueHashMap.remove(path);
46+
}
47+
48+
// ----- Methods for Snyk Code Issues -----
49+
50+
/**
51+
* Adds or updates Snyk Code issues for a given path
52+
*
53+
* @param path The file path
54+
* @param issues The collection of issues to add
55+
*/
56+
public void addCodeIssues(String path, Collection<Issue> issues) {
57+
snykCodeIssueHashMap.put(path, issues);
58+
}
59+
60+
/**
61+
* Retrieves Snyk Code issues for a given path
62+
*
63+
* @param path The file path
64+
* @return An unmodifiable collection of issues, or an empty list if none exist
65+
*/
66+
public Collection<Issue> getCodeIssuesForPath(String path) {
67+
Collection<Issue> issues = snykCodeIssueHashMap.get(path);
68+
return issues != null ? Collections.unmodifiableCollection(issues) : Collections.emptyList();
69+
}
70+
71+
/**
72+
* Removes Snyk Code issues for a given path
73+
*
74+
* @param path The file path
75+
*/
76+
public void removeCodeIssuesForPath(String path) {
77+
snykCodeIssueHashMap.remove(path);
78+
}
79+
80+
// ----- Methods for Snyk Open Source Issues -----
81+
82+
/**
83+
* Adds or updates Snyk Open Source issues for a given path
84+
*
85+
* @param path The file path
86+
* @param issues The collection of issues to add
87+
*/
88+
public void addOssIssues(String path, Collection<Issue> issues) {
89+
snykOssIssueHashMap.put(path, issues);
90+
}
91+
92+
/**
93+
* Retrieves Snyk Open Source issues for a given path
94+
*
95+
* @param path The file path
96+
* @return An unmodifiable collection of issues, or an empty list if none exist
97+
*/
98+
public Collection<Issue> getOssIssuesForPath(String path) {
99+
Collection<Issue> issues = snykOssIssueHashMap.get(path);
100+
return issues != null ? Collections.unmodifiableCollection(issues) : Collections.emptyList();
101+
}
102+
103+
/**
104+
* Removes Snyk Open Source issues for a given path
105+
*
106+
* @param path The file path
107+
*/
108+
public void removeOssIssuesForPath(String path) {
109+
snykOssIssueHashMap.remove(path);
110+
}
111+
112+
// ----- Methods for Snyk IaC Issues -----
113+
114+
/**
115+
* Adds or updates Snyk IaC issues for a given path
116+
*
117+
* @param path The file path
118+
* @param issues The collection of issues to add
119+
*/
120+
public void addIacIssues(String path, Collection<Issue> issues) {
121+
snykIaCIssueHashMap.put(path, issues);
122+
}
123+
124+
/**
125+
* Retrieves Snyk IaC issues for a given path
126+
*
127+
* @param path The file path
128+
* @return An unmodifiable collection of issues, or an empty list if none exist
129+
*/
130+
public Collection<Issue> getIacIssuesForPath(String path) {
131+
Collection<Issue> issues = snykIaCIssueHashMap.get(path);
132+
return issues != null ? Collections.unmodifiableCollection(issues) : Collections.emptyList();
133+
}
134+
135+
/**
136+
* Removes Snyk IaC issues for a given path
137+
*
138+
* @param path The file path
139+
*/
140+
public void removeIacIssuesForPath(String path) {
141+
snykIaCIssueHashMap.remove(path);
142+
}
143+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.snyk.languageserver.protocolextension;
2+
3+
public class InvalidProductTypeException extends RuntimeException {
4+
public InvalidProductTypeException(String message) {
5+
super(message);
6+
}
7+
}

0 commit comments

Comments
 (0)