From b7167645f7b4fd4ccac23f877a659d352b4c8a8d Mon Sep 17 00:00:00 2001 From: Miles Ziemer Date: Mon, 28 Oct 2024 16:42:47 -0400 Subject: [PATCH] Address comments --- .../software/amazon/smithy/lsp/FilePatterns.java | 13 +------------ .../amazon/smithy/lsp/ProjectRootVisitor.java | 5 ++++- .../smithy/lsp/project/ProjectConfigLoader.java | 8 ++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/software/amazon/smithy/lsp/FilePatterns.java b/src/main/java/software/amazon/smithy/lsp/FilePatterns.java index 34d407e6..23bab11f 100644 --- a/src/main/java/software/amazon/smithy/lsp/FilePatterns.java +++ b/src/main/java/software/amazon/smithy/lsp/FilePatterns.java @@ -9,7 +9,6 @@ import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.PathMatcher; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -21,8 +20,6 @@ * or build files in Projects and workspaces. */ final class FilePatterns { - private static final int BUILD_FILE_COUNT = 2 + ProjectConfigLoader.SMITHY_BUILD_EXTS.length; - private FilePatterns() { } @@ -81,14 +78,6 @@ private static PathMatcher toPathMatcher(String globPattern) { // whereas patterns for projects only look at the top level (because project locations // are defined by the presence of these build files). private static String getBuildFilesPattern(Path root, boolean isWorkspacePattern) { - List patterns = new ArrayList<>(BUILD_FILE_COUNT); - patterns.add(ProjectConfigLoader.SMITHY_BUILD); - patterns.add(ProjectConfigLoader.SMITHY_PROJECT); - for (String buildExt : ProjectConfigLoader.SMITHY_BUILD_EXTS) { - Path extPath = Path.of(buildExt); // buildExt may have file separators - patterns.add(extPath.toString()); - } - String rootString = root.toString(); if (!rootString.endsWith(File.separator)) { rootString += File.separator; @@ -98,7 +87,7 @@ private static String getBuildFilesPattern(Path root, boolean isWorkspacePattern rootString += "**" + File.separator; } - return escapeBackslashes(rootString + "{" + String.join(",", patterns) + "}"); + return escapeBackslashes(rootString + "{" + String.join(",", ProjectConfigLoader.PROJECT_BUILD_FILES) + "}"); } // When computing the pattern used for telling the client which files to watch, we want diff --git a/src/main/java/software/amazon/smithy/lsp/ProjectRootVisitor.java b/src/main/java/software/amazon/smithy/lsp/ProjectRootVisitor.java index d99f75e4..a1016b9d 100644 --- a/src/main/java/software/amazon/smithy/lsp/ProjectRootVisitor.java +++ b/src/main/java/software/amazon/smithy/lsp/ProjectRootVisitor.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -14,6 +15,7 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import software.amazon.smithy.lsp.project.ProjectConfigLoader; @@ -23,6 +25,7 @@ final class ProjectRootVisitor extends SimpleFileVisitor { private static final PathMatcher PROJECT_ROOT_MATCHER = FileSystems.getDefault().getPathMatcher( "glob:{" + ProjectConfigLoader.SMITHY_BUILD + "," + ProjectConfigLoader.SMITHY_PROJECT + "}"); + private static final int MAX_VISIT_DEPTH = 10; private final List roots = new ArrayList<>(); @@ -36,7 +39,7 @@ final class ProjectRootVisitor extends SimpleFileVisitor { */ static List findProjectRoots(Path workspaceRoot) throws IOException { ProjectRootVisitor visitor = new ProjectRootVisitor(); - Files.walkFileTree(workspaceRoot, visitor); + Files.walkFileTree(workspaceRoot, EnumSet.noneOf(FileVisitOption.class), MAX_VISIT_DEPTH, visitor); return visitor.roots; } diff --git a/src/main/java/software/amazon/smithy/lsp/project/ProjectConfigLoader.java b/src/main/java/software/amazon/smithy/lsp/project/ProjectConfigLoader.java index 77844694..5e5980ab 100644 --- a/src/main/java/software/amazon/smithy/lsp/project/ProjectConfigLoader.java +++ b/src/main/java/software/amazon/smithy/lsp/project/ProjectConfigLoader.java @@ -8,6 +8,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.logging.Logger; import software.amazon.smithy.build.model.SmithyBuildConfig; @@ -65,11 +66,18 @@ public final class ProjectConfigLoader { public static final String SMITHY_BUILD = "smithy-build.json"; public static final String[] SMITHY_BUILD_EXTS = {"build/smithy-dependencies.json", ".smithy.json"}; public static final String SMITHY_PROJECT = ".smithy-project.json"; + public static final List PROJECT_BUILD_FILES = new ArrayList<>(2 + SMITHY_BUILD_EXTS.length); private static final Logger LOGGER = Logger.getLogger(ProjectConfigLoader.class.getName()); private static final SmithyBuildConfig DEFAULT_SMITHY_BUILD = SmithyBuildConfig.builder().version("1").build(); private static final NodeMapper NODE_MAPPER = new NodeMapper(); + static { + PROJECT_BUILD_FILES.add(SMITHY_BUILD); + PROJECT_BUILD_FILES.add(SMITHY_PROJECT); + PROJECT_BUILD_FILES.addAll(Arrays.asList(SMITHY_BUILD_EXTS)); + } + private ProjectConfigLoader() { }