-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit makes the language server work with Smithy projects in subdirectories of the folder (or folders, in the case of e.g. vscode workspace folders) open in the editor. I previously added support for multiple _workspace folders_ (an LSP concept), but I assumed only one _project_ (Smithy LS concept) per workspace folder. So this commit fixes that mixing, allowing many projects per workspace folder. Now, the language server will search through subdirectories of all workspace folders (by default, one workspace folder is open in the client) to find projects. Changes to build files, i.e. smithy-build.json, .smithy-project.json, are now tracked at the workspace level, so you can add a new project to an existing workspace. I also did _some_ cleanup of the project/workspace synchronization code, and moved some things around. A note on some tests: I'm using a `Files.createTempDirectory`, and adding the `TestWorkspace` as a subdir. In a follow-up commit, I will be changing `TestWorkspace` to be something like `TestProject`, which is more accurate. I didn't include it here to avoid a bunch of noise.
- Loading branch information
1 parent
b425716
commit f7d843e
Showing
19 changed files
with
742 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/software/amazon/smithy/lsp/ProjectRootVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.lsp; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileSystems; | ||
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.List; | ||
import software.amazon.smithy.lsp.project.ProjectConfigLoader; | ||
|
||
/** | ||
* Finds Project roots based on the location of smithy-build.json and .smithy-project.json. | ||
*/ | ||
final class ProjectRootVisitor extends SimpleFileVisitor<Path> { | ||
private static final PathMatcher PROJECT_ROOT_MATCHER = FileSystems.getDefault().getPathMatcher( | ||
"glob:{" + ProjectConfigLoader.SMITHY_BUILD + "," + ProjectConfigLoader.SMITHY_PROJECT + "}"); | ||
|
||
private final List<Path> roots = new ArrayList<>(); | ||
|
||
/** | ||
* Walks through the file tree starting at {@code workspaceRoot}, collecting | ||
* paths of Project roots. | ||
* | ||
* @param workspaceRoot Root of the workspace to find projects in | ||
* @return A list of project roots | ||
* @throws IOException If an I/O error is thrown while walking files | ||
*/ | ||
static List<Path> findProjectRoots(Path workspaceRoot) throws IOException { | ||
ProjectRootVisitor visitor = new ProjectRootVisitor(); | ||
Files.walkFileTree(workspaceRoot, visitor); | ||
return visitor.roots; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { | ||
Path name = file.getFileName(); | ||
if (name != null && PROJECT_ROOT_MATCHER.matches(name)) { | ||
roots.add(file.getParent()); | ||
return FileVisitResult.SKIP_SIBLINGS; | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
} |
Oops, something went wrong.