-
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.
feat: add listener/callback to return the sdks for a workspace folder
- Loading branch information
1 parent
d49cab2
commit 0bb3452
Showing
3 changed files
with
43 additions
and
26 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package snyk.sdk | ||
|
||
import com.intellij.openapi.module.ModuleManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.projectRoots.Sdk | ||
import com.intellij.openapi.roots.ModuleRootManager | ||
import com.intellij.openapi.util.io.FileUtil | ||
import snyk.common.lsp.LsSdk | ||
|
||
class SdkHelper { | ||
companion object { | ||
fun getSdks(project: Project): List<LsSdk> { | ||
val list: MutableList<LsSdk> = mutableListOf() | ||
val modules = ModuleManager.getInstance(project).modules | ||
for (module in modules) { | ||
val moduleSdk = ModuleRootManager.getInstance(module).sdk | ||
addSdkToList(moduleSdk, list) | ||
} | ||
return list.toList() | ||
} | ||
|
||
private fun addSdkToList( | ||
sdk: Sdk?, | ||
list: MutableList<LsSdk> | ||
) { | ||
if (sdk != null && sdk.homeDirectory != null) { | ||
list.add(LsSdk(sdk.sdkType.name, FileUtil.toSystemDependentName(sdk.homeDirectory!!.path))) | ||
} | ||
} | ||
} | ||
} |