-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Project.kt
44 lines (29 loc) · 1.46 KB
/
Project.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.insyncwithfoo.pyrightls
import com.insyncwithfoo.pyrightls.configuration.AllConfigurations
import com.insyncwithfoo.pyrightls.configuration.ConfigurationService
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.profile.codeInspection.InspectionProjectProfileManager
import java.nio.file.Path
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.nameWithoutExtension
private val Project.sdk: Sdk?
get() = ProjectRootManager.getInstance(this).projectSdk
internal val Project.path: Path?
get() = basePath?.let { Path.of(it) }
internal val Project.sdkPath: Path?
get() = sdk?.homePath?.let { Path.of(it) }
internal val Project.pyrightLSConfigurations: AllConfigurations
get() = ConfigurationService.getInstance(this).state
internal fun Project.isPyrightLSInspectionEnabled(): Boolean {
val inspectionManager = InspectionProjectProfileManager.getInstance(this)
val profile = inspectionManager.currentProfile
val pyrightLSInspection = profile.allTools.find { it.tool.shortName == PyrightLSInspection.SHORT_NAME }
return pyrightLSInspection?.isEnabled ?: false
}
internal fun Project.findPyrightLSExecutable(): Path? {
val sdkDirectory = sdkPath?.parent ?: return null
val children = sdkDirectory.listDirectoryEntries()
return children.find { it.nameWithoutExtension == "pyright-langserver" }
}