Skip to content

Commit

Permalink
Handle settings.gradle.kts or missing settings.gradle.dcl
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tk3y committed Nov 11, 2024
1 parent a1ab206 commit 00a3bf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,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 @@ -28,6 +28,7 @@
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class GetDeclarativeResourcesModel implements BuildAction<DeclarativeResourcesModel> {
Expand Down Expand Up @@ -103,7 +104,13 @@ 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<File> candidateFiles = Stream.of("settings.gradle.dcl", "settings.gradle.kts")
.map(it -> new File(getRootDir(), "settings.gradle.dcl"))
.collect(Collectors.toList());
return candidateFiles.stream()
.filter(File::exists)
.findFirst()
.orElse(candidateFiles.get(0));
}

@Override
Expand Down

0 comments on commit 00a3bf7

Please sign in to comment.