@@ -16,6 +16,7 @@ import org.kotlinlsp.analysis.modules.LibraryModule
1616import org.kotlinlsp.analysis.modules.Module
1717import org.kotlinlsp.analysis.modules.SourceModule
1818import org.kotlinlsp.common.getCachePath
19+ import org.kotlinlsp.common.info
1920import java.io.ByteArrayOutputStream
2021import java.io.File
2122
@@ -37,7 +38,7 @@ class GradleBuildSystem(
3738 override fun resolveModulesIfNeeded (cachedMetadata : String? ): BuildSystem .Result ? {
3839 val androidVariant = " debug" // TODO Make it a config parameter
3940
40- if (! shouldReloadGradleProject(cachedMetadata)) {
41+ if (! shouldReloadGradleProject(cachedMetadata)) {
4142 return null
4243 }
4344
@@ -53,8 +54,12 @@ class GradleBuildSystem(
5354 .withArguments(" --init-script" , androidInitScript.absolutePath, " -DandroidVariant=${androidVariant} " )
5455 .setStandardOutput(output)
5556 .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 )
5863 .get()
5964
6065 println (output)
@@ -81,46 +86,62 @@ class GradleBuildSystem(
8186 val testDirs = contentRoot.testDirectories.map { it.directory.toPath() }
8287
8388 // Ignore empty modules
84- if (sourceDirs.isEmpty()) return @mapNotNull null
89+ if (sourceDirs.isEmpty()) return @mapNotNull null
8590
8691 // Seems that dependencies are the same for source and test source-sets?
87- val dependencies : MutableList < Module > = module
92+ val (testIdeaDeps, sourceIdeaDeps) = module
8893 .dependencies
8994 .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 {
91112 LibraryModule (
92- id = dependency .file.name,
113+ id = it .file.name,
93114 appEnvironment = appEnvironment,
94115 project = project,
95116 javaVersion = jvmTarget,
96- contentRoots = listOf (dependency .file.toPath()),
117+ contentRoots = listOf (it .file.toPath()),
97118 )
98119 }
99120 .toMutableList()
100121
101122 if (jdkModule != null ) {
102- dependencies .add(jdkModule)
123+ sourceDeps .add(jdkModule)
103124 }
104125
105126 val sourceModule = SourceModule (
106127 id = module.name,
107128 project = project,
108129 contentRoots = sourceDirs,
109- dependencies = dependencies ,
130+ dependencies = sourceDeps ,
110131 javaVersion = jvmTarget,
111132 kotlinVersion = LanguageVersion .KOTLIN_2_1 ,
112133 )
113134
114135 if (testDirs.isEmpty()) return @mapNotNull listOf (sourceModule)
115136
116- val testDependencies = dependencies.toMutableList( )
117- testDependencies.add(sourceModule )
137+ testDeps.add(sourceModule )
138+ testDeps.addAll(sourceDeps )
118139
119140 val testModule = SourceModule (
120141 id = " ${module.name} -test" ,
121142 project = project,
122143 contentRoots = testDirs,
123- dependencies = testDependencies ,
144+ dependencies = testDeps ,
124145 javaVersion = jvmTarget,
125146 kotlinVersion = LanguageVersion .KOTLIN_2_1 ,
126147 )
0 commit comments