Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle settings.gradle.kts or missing settings.gradle.dcl #4

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Now I realize we don't handle these cases when adding a new settings file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that the editor will not react to the creation of a settings file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - didCreate and didOpen would fire, but we don't have any logic saying: "ah, this is a new root build/setting file for this build"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to merge this as-is, so we have a (partially, maybe) working build sooner. Let's maybe track the problem you found as an issue?

)

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