Skip to content

Commit dffb02c

Browse files
committed
Add documentation to new methods
1 parent 6391aac commit dffb02c

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

src/main/java/software/amazon/smithy/lsp/ManagedFiles.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
import software.amazon.smithy.lsp.document.Document;
99

10+
/**
11+
* Provides access to {@link Document}s managed by the server.
12+
*
13+
* <p>A document is _managed_ if its state is controlled by the lifecycle methods
14+
* didOpen, didClose, didChange, didSave. In other words, reading from disk _may_
15+
* not provide the accurate file content.
16+
*/
1017
public interface ManagedFiles {
1118
/**
1219
* @param uri Uri of the document to get

src/main/java/software/amazon/smithy/lsp/ServerState.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ public ServerState() {
4949
this.lifecycleManager = new DocumentLifecycleManager();
5050
}
5151

52+
/**
53+
* @return All projects tracked by the server.
54+
*/
5255
public Collection<Project> getAllProjects() {
5356
return projects.values();
5457
}
5558

59+
/**
60+
* @return All files managed by the server, including their projects.
61+
*/
5662
public Collection<ProjectAndFile> getAllManaged() {
5763
List<ProjectAndFile> allManaged = new ArrayList<>(managedUris.size());
5864
for (String uri : managedUris) {
@@ -61,18 +67,13 @@ public Collection<ProjectAndFile> getAllManaged() {
6167
return allManaged;
6268
}
6369

70+
/**
71+
* @return All workspace paths tracked by the server.
72+
*/
6473
public Set<Path> workspacePaths() {
6574
return workspacePaths;
6675
}
6776

68-
public DocumentLifecycleManager lifecycleManager() {
69-
return lifecycleManager;
70-
}
71-
72-
public Project findProjectByRoot(String root) {
73-
return projects.get(root);
74-
}
75-
7677
@Override
7778
public Document getManagedDocument(String uri) {
7879
if (managedUris.contains(uri)) {
@@ -85,6 +86,14 @@ public Document getManagedDocument(String uri) {
8586
return null;
8687
}
8788

89+
DocumentLifecycleManager lifecycleManager() {
90+
return lifecycleManager;
91+
}
92+
93+
Project findProjectByRoot(String root) {
94+
return projects.get(root);
95+
}
96+
8897
ProjectAndFile findProjectAndFile(String uri) {
8998
String path = LspAdapter.toPath(uri);
9099

src/main/java/software/amazon/smithy/lsp/project/Project.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,23 @@ public final class Project {
6767
this.rebuildIndex = rebuildIndex;
6868
}
6969

70+
/**
71+
* The type of project, which depends on how it was loaded.
72+
*/
7073
public enum Type {
74+
/**
75+
* A project loaded using some build configuration files, i.e. smithy-build.json.
76+
*/
7177
NORMAL,
78+
79+
/**
80+
* A project loaded from a single source file, without any build configuration files.
81+
*/
7282
DETACHED,
83+
84+
/**
85+
* A project loaded with no source or build configuration files.
86+
*/
7387
EMPTY;
7488
}
7589

@@ -510,18 +524,22 @@ RebuildIndex recompute(ValidatedResult<Model> modelResult) {
510524
for (Node element : traitNode.expectArrayNode()) {
511525
String elementSourceFilename = element.getSourceLocation().getFilename();
512526
if (!elementSourceFilename.equals(shapeSourceFilename)) {
513-
newIndex.filesToDependentFiles.computeIfAbsent(elementSourceFilename, (f) -> new HashSet<>())
527+
newIndex.filesToDependentFiles
528+
.computeIfAbsent(elementSourceFilename, (f) -> new HashSet<>())
514529
.add(shapeSourceFilename);
515-
newIndex.shapeIdsToDependenciesFiles.computeIfAbsent(shape.getId(), (i) -> new HashSet<>())
530+
newIndex.shapeIdsToDependenciesFiles
531+
.computeIfAbsent(shape.getId(), (i) -> new HashSet<>())
516532
.add(elementSourceFilename);
517533
}
518534
}
519535
} else {
520536
String traitSourceFilename = traitApplication.getSourceLocation().getFilename();
521537
if (!traitSourceFilename.equals(shapeSourceFilename)) {
522-
newIndex.shapesToAppliedTraitsInOtherFiles.computeIfAbsent(shape.getId(), (i) -> new ArrayList<>())
538+
newIndex.shapesToAppliedTraitsInOtherFiles
539+
.computeIfAbsent(shape.getId(), (i) -> new ArrayList<>())
523540
.add(traitApplication);
524-
newIndex.filesToTraitsTheyApply.computeIfAbsent(traitSourceFilename, (f) -> new HashMap<>())
541+
newIndex.filesToTraitsTheyApply
542+
.computeIfAbsent(traitSourceFilename, (f) -> new HashMap<>())
525543
.computeIfAbsent(shape.getId(), (i) -> new ArrayList<>())
526544
.add(traitApplication);
527545
}

src/main/java/software/amazon/smithy/lsp/project/ProjectLoader.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public static Project loadDetached(String uri, String text) {
7575
LoadModelResult result;
7676
try {
7777
result = doLoad(managedFiles, dependencies, allSmithyFilePaths);
78-
} catch (Exception e) {
79-
// TODO: Clean up this comment
80-
// Note: This can't happen because we have no dependencies to turn into URLs
78+
} catch (IOException e) {
79+
// Note: This can't happen because we aren't doing any fallible IO,
80+
// as only the prelude will be read from disk
8181
throw new RuntimeException(e);
8282
}
8383

@@ -158,7 +158,7 @@ private static LoadModelResult doLoad(
158158
ManagedFiles managedFiles,
159159
List<Path> dependencies,
160160
List<Path> allSmithyFilePaths
161-
) throws Exception {
161+
) throws IOException {
162162
// The model assembler factory is used to get assemblers that already have the correct
163163
// dependencies resolved for future loads
164164
Supplier<ModelAssembler> assemblerFactory = createModelAssemblerFactory(dependencies);
@@ -278,7 +278,6 @@ private static URLClassLoader createDependenciesClassLoader(List<Path> dependenc
278278
return new URLClassLoader(urls);
279279
}
280280

281-
// TODO: Can there be duplicate paths in this list? If there are, we may end up reading from disk multiple times
282281
// sources and imports can contain directories or files, relative or absolute
283282
private static List<Path> collectAllSmithyPaths(Path root, List<String> sources, List<String> imports) {
284283
List<Path> paths = new ArrayList<>();

0 commit comments

Comments
 (0)