Skip to content

Commit

Permalink
Handle settings.gradle.kts or missing settings.gradle.dcl (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tk3y authored Nov 13, 2024
1 parent a9b700b commit 1a2128b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ class DeclarativeTextDocumentService : TextDocumentService {
val fileName = uri.path.substringAfterLast('/')
val fileSchema = schemaAnalysisEvaluator.evaluate(fileName, text)
val settingsSchema = schemaAnalysisEvaluator.evaluate(
declarativeResources.settingsFile.name, declarativeResources.settingsFile.readText()
declarativeResources.settingsFile.name,
declarativeResources.settingsFile.takeIf { it.canRead() }?.readText().orEmpty()
)

val document = AnalysisDocumentUtils.documentWithModelDefaults(settingsSchema, fileSchema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.gradle.tooling.model.gradle.GradleBuild;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -103,7 +105,14 @@ public File getRootDir() {
@Override
public File getSettingsFile() {
// TODO: this is an assumption about the location of the settings file – get it from Gradle instead.
return new File(getRootDir(), "settings.gradle.dcl");
List<String> candidateFileNames = Arrays.asList("settings.gradle.dcl", "settings.gradle.kts");
Function<String, File> asFileInRootDirectory = it -> new File(getRootDir(), it);

return candidateFileNames.stream()
.map(asFileInRootDirectory)
.filter(File::exists)
.findFirst()
.orElse(asFileInRootDirectory.apply(candidateFileNames.get(0)));
}

@Override
Expand Down

0 comments on commit 1a2128b

Please sign in to comment.