@@ -16,6 +16,7 @@ import org.kotlinlsp.analysis.modules.LibraryModule
16
16
import org.kotlinlsp.analysis.modules.Module
17
17
import org.kotlinlsp.analysis.modules.SourceModule
18
18
import org.kotlinlsp.common.getCachePath
19
+ import org.kotlinlsp.common.info
19
20
import java.io.ByteArrayOutputStream
20
21
import java.io.File
21
22
@@ -37,7 +38,7 @@ class GradleBuildSystem(
37
38
override fun resolveModulesIfNeeded (cachedMetadata : String? ): BuildSystem .Result ? {
38
39
val androidVariant = " debug" // TODO Make it a config parameter
39
40
40
- if (! shouldReloadGradleProject(cachedMetadata)) {
41
+ if (! shouldReloadGradleProject(cachedMetadata)) {
41
42
return null
42
43
}
43
44
@@ -53,8 +54,12 @@ class GradleBuildSystem(
53
54
.withArguments(" --init-script" , androidInitScript.absolutePath, " -DandroidVariant=${androidVariant} " )
54
55
.setStandardOutput(output)
55
56
.addProgressListener({
56
- progressNotifier.onReportProgress(WorkDoneProgressKind .report, PROGRESS_TOKEN , " [GRADLE] ${it.displayName} " )
57
- }, OperationType .PROJECT_CONFIGURATION )
57
+ progressNotifier.onReportProgress(
58
+ WorkDoneProgressKind .report,
59
+ PROGRESS_TOKEN ,
60
+ " [GRADLE] ${it.displayName} "
61
+ )
62
+ }, OperationType .PROJECT_CONFIGURATION )
58
63
.get()
59
64
60
65
println (output)
@@ -81,46 +86,62 @@ class GradleBuildSystem(
81
86
val testDirs = contentRoot.testDirectories.map { it.directory.toPath() }
82
87
83
88
// Ignore empty modules
84
- if (sourceDirs.isEmpty()) return @mapNotNull null
89
+ if (sourceDirs.isEmpty()) return @mapNotNull null
85
90
86
91
// Seems that dependencies are the same for source and test source-sets?
87
- val dependencies : MutableList < Module > = module
92
+ val (testIdeaDeps, sourceIdeaDeps) = module
88
93
.dependencies
89
94
.filterIsInstance<IdeaSingleEntryLibraryDependency >()
90
- .map { dependency ->
95
+ .filter { it.scope.scope != " RUNTIME" } // We don't need runtime deps for an LSP
96
+ .partition { it.scope.scope == " TEST" }
97
+
98
+ val sourceDeps: MutableList <Module > = sourceIdeaDeps
99
+ .map {
100
+ LibraryModule (
101
+ id = it.file.name,
102
+ appEnvironment = appEnvironment,
103
+ project = project,
104
+ javaVersion = jvmTarget,
105
+ contentRoots = listOf (it.file.toPath()),
106
+ )
107
+ }
108
+ .toMutableList()
109
+
110
+ val testDeps: MutableList <Module > = testIdeaDeps
111
+ .map {
91
112
LibraryModule (
92
- id = dependency .file.name,
113
+ id = it .file.name,
93
114
appEnvironment = appEnvironment,
94
115
project = project,
95
116
javaVersion = jvmTarget,
96
- contentRoots = listOf (dependency .file.toPath()),
117
+ contentRoots = listOf (it .file.toPath()),
97
118
)
98
119
}
99
120
.toMutableList()
100
121
101
122
if (jdkModule != null ) {
102
- dependencies .add(jdkModule)
123
+ sourceDeps .add(jdkModule)
103
124
}
104
125
105
126
val sourceModule = SourceModule (
106
127
id = module.name,
107
128
project = project,
108
129
contentRoots = sourceDirs,
109
- dependencies = dependencies ,
130
+ dependencies = sourceDeps ,
110
131
javaVersion = jvmTarget,
111
132
kotlinVersion = LanguageVersion .KOTLIN_2_1 ,
112
133
)
113
134
114
135
if (testDirs.isEmpty()) return @mapNotNull listOf (sourceModule)
115
136
116
- val testDependencies = dependencies.toMutableList( )
117
- testDependencies.add(sourceModule )
137
+ testDeps.add(sourceModule )
138
+ testDeps.addAll(sourceDeps )
118
139
119
140
val testModule = SourceModule (
120
141
id = " ${module.name} -test" ,
121
142
project = project,
122
143
contentRoots = testDirs,
123
- dependencies = testDependencies ,
144
+ dependencies = testDeps ,
124
145
javaVersion = jvmTarget,
125
146
kotlinVersion = LanguageVersion .KOTLIN_2_1 ,
126
147
)
0 commit comments