Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
milesziemer committed Oct 28, 2024
1 parent 24a93bb commit b716764
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
13 changes: 1 addition & 12 deletions src/main/java/software/amazon/smithy/lsp/FilePatterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
}

Expand Down Expand Up @@ -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<String> 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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

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;
import java.nio.file.PathMatcher;
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;

Expand All @@ -23,6 +25,7 @@
final class ProjectRootVisitor extends SimpleFileVisitor<Path> {
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<Path> roots = new ArrayList<>();

Expand All @@ -36,7 +39,7 @@ final class ProjectRootVisitor extends SimpleFileVisitor<Path> {
*/
static List<Path> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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() {
}

Expand Down

0 comments on commit b716764

Please sign in to comment.