-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: iac & code separation of navigation logic and ui logic
- Loading branch information
1 parent
3a059a2
commit 40669e4
Showing
13 changed files
with
114 additions
and
87 deletions.
There are no files selected for viewing
12 changes: 11 additions & 1 deletion
12
src/main/kotlin/io/snyk/plugin/snykcode/core/SnykCodeFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package io.snyk.plugin.snykcode.core | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.Iconable | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.jetbrains.kotlin.idea.core.util.toPsiFile | ||
import snyk.common.RelativePathHelper | ||
import javax.swing.Icon | ||
|
||
data class SnykCodeFile(val project: Project, val virtualFile: VirtualFile) { | ||
fun getRelativePath(): String = RelativePathHelper().getRelativePath(virtualFile, project) ?: virtualFile.path | ||
var icon: Icon? = null | ||
val relativePath = RelativePathHelper().getRelativePath(virtualFile, project) | ||
init { | ||
ApplicationManager.getApplication().runReadAction { | ||
virtualFile.toPsiFile(project)?.getIcon(Iconable.ICON_FLAG_READ_STATUS) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
package snyk.common | ||
|
||
import com.intellij.openapi.vfs.LocalFileSystem | ||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
data class SnykError( | ||
val message: String, | ||
val path: String, | ||
val code: Int? = null | ||
) | ||
) { | ||
var virtualFile: VirtualFile? = null | ||
|
||
init { | ||
if (path.isNotEmpty()) { | ||
virtualFile = LocalFileSystem.getInstance().findFileByPath(this.path) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
package snyk.iac | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.LocalFileSystem | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import snyk.common.RelativePathHelper | ||
|
||
data class IacIssuesForFile( | ||
val infrastructureAsCodeIssues: List<IacIssue>, | ||
val targetFile: String, | ||
val targetFilePath: String, | ||
val packageManager: String | ||
val packageManager: String, | ||
val virtualFile: VirtualFile?, | ||
val project: Project?, | ||
val relativePath: String? = null, | ||
) { | ||
val obsolete: Boolean get() = infrastructureAsCodeIssues.any { it.obsolete } | ||
val ignored: Boolean get() = infrastructureAsCodeIssues.all { it.ignored } | ||
val uniqueCount: Int get() = infrastructureAsCodeIssues.groupBy { it.id }.size | ||
|
||
val virtualFile: VirtualFile | ||
get() = LocalFileSystem.getInstance().findFileByPath(this.targetFilePath)!! | ||
|
||
var project: Project? = null | ||
|
||
// this is necessary as the creation of the class by the GSon is not initializing fields | ||
private var relativePathHelper: RelativePathHelper? = null | ||
get() = field ?: RelativePathHelper() | ||
|
||
var relativePath: String? = null | ||
get() = field ?: project?.let { | ||
field = relativePathHelper!!.getRelativePath(virtualFile, it) | ||
return field | ||
} | ||
} |
Oops, something went wrong.