-
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 makes the language server work on files that aren't connected (or attached) to a smithy-build.json/other build file. This works by loading said files as they are opened in their own, single-file projects with no dependencies, which are removed when the file is closed. A diagnostic was also added to indicate when a file is 'detached' from a project, and appears on the first line of the file. I could have made all detached files part of their own special project, could be more convenient when doing something quick with multiple files without a smithy-build.json. The smithy cli can work this way, although you still have to specify the files to build in the command, so we could change this in the future. The difference is I don't think we'd have a way of opting out of the single project without some config that would end up being more work to set up than a smithy-build.json.
- Loading branch information
1 parent
cc605d7
commit 6fce052
Showing
13 changed files
with
694 additions
and
60 deletions.
There are no files selected for viewing
175 changes: 130 additions & 45 deletions
175
src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
src/main/java/software/amazon/smithy/lsp/diagnostics/DetachedDiagnostics.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,44 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.lsp.diagnostics; | ||
|
||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.Range; | ||
import software.amazon.smithy.lsp.project.SmithyFile; | ||
import software.amazon.smithy.lsp.protocol.RangeAdapter; | ||
|
||
/** | ||
* Diagnostics for when a Smithy file is not connected to a Smithy project via | ||
* smithy-build.json or other build file. | ||
*/ | ||
public final class DetachedDiagnostics { | ||
public static final String DETACHED_FILE = "detached-file"; | ||
|
||
private DetachedDiagnostics() { | ||
} | ||
|
||
/** | ||
* @param smithyFile The Smithy file to get a detached diagnostic for | ||
* @return The detached diagnostic associated with the Smithy file, or null | ||
* if one doesn't exist (this occurs if the file doesn't have a document | ||
* associated with it) | ||
*/ | ||
public static Diagnostic forSmithyFile(SmithyFile smithyFile) { | ||
if (smithyFile.getDocument() != null) { | ||
int end = smithyFile.getDocument().lineEnd(0); | ||
Range range = RangeAdapter.lineSpan(0, 0, end); | ||
return new Diagnostic( | ||
range, | ||
"This file isn't attached to a project", | ||
DiagnosticSeverity.Warning, | ||
"smithy-language-server", | ||
DETACHED_FILE | ||
); | ||
} | ||
return null; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/software/amazon/smithy/lsp/ext/serverstatus/OpenProject.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.ext.serverstatus; | ||
|
||
import java.util.List; | ||
import org.eclipse.lsp4j.jsonrpc.validation.NonNull; | ||
|
||
/** | ||
* A snapshot of a project the server has open. | ||
*/ | ||
public class OpenProject { | ||
@NonNull | ||
private final String root; | ||
@NonNull | ||
private final List<String> files; | ||
private final boolean isDetached; | ||
|
||
/** | ||
* @param root The root URI of the project | ||
* @param files The list of all file URIs tracked by the project | ||
* @param isDetached Whether the project is detached | ||
*/ | ||
public OpenProject(@NonNull final String root, @NonNull final List<String> files, boolean isDetached) { | ||
this.root = root; | ||
this.files = files; | ||
this.isDetached = isDetached; | ||
} | ||
|
||
/** | ||
* @return The root directory of the project | ||
*/ | ||
public String getRoot() { | ||
return root; | ||
} | ||
|
||
/** | ||
* @return The list of all file URIs tracked by the project | ||
*/ | ||
public List<String> getFiles() { | ||
return files; | ||
} | ||
|
||
/** | ||
* @return Whether the project is detached - tracking just a single open file | ||
*/ | ||
public boolean isDetached() { | ||
return isDetached; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/software/amazon/smithy/lsp/ext/serverstatus/ServerStatus.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,29 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.lsp.ext.serverstatus; | ||
|
||
import java.util.List; | ||
import org.eclipse.lsp4j.jsonrpc.validation.NonNull; | ||
|
||
/** | ||
* A snapshot of the server status, containing the projects it has open. | ||
* We can add more here later as we see fit. | ||
*/ | ||
public class ServerStatus { | ||
@NonNull | ||
private final List<OpenProject> openProjects; | ||
|
||
public ServerStatus(@NonNull final List<OpenProject> openProjects) { | ||
this.openProjects = openProjects; | ||
} | ||
|
||
/** | ||
* @return The open projects tracked by the server | ||
*/ | ||
public List<OpenProject> getOpenProjects() { | ||
return openProjects; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/software/amazon/smithy/lsp/ext/serverstatus/ServerStatusParams.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,14 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.lsp.ext.serverstatus; | ||
|
||
/** | ||
* LSP request parameters for a ServerStatus request. | ||
*/ | ||
public class ServerStatusParams { | ||
public ServerStatusParams() { | ||
} | ||
} |
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
Oops, something went wrong.