generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 24
Add completions for for build files #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
milesziemer
merged 1 commit into
smithy-lang:main
from
milesziemer:build-file-completions
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
59 changes: 59 additions & 0 deletions
59
src/main/java/software/amazon/smithy/lsp/language/BuildCompletionHandler.java
This file contains hidden or 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,59 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.lsp.language; | ||
|
|
||
| import java.util.List; | ||
| import org.eclipse.lsp4j.CompletionItem; | ||
| import org.eclipse.lsp4j.CompletionParams; | ||
| import org.eclipse.lsp4j.Position; | ||
| import org.eclipse.lsp4j.Range; | ||
| import software.amazon.smithy.lsp.document.DocumentId; | ||
| import software.amazon.smithy.lsp.project.BuildFile; | ||
| import software.amazon.smithy.lsp.project.Project; | ||
| import software.amazon.smithy.lsp.syntax.NodeCursor; | ||
| import software.amazon.smithy.model.shapes.Shape; | ||
|
|
||
| /** | ||
| * Handles completions requests for {@link BuildFile}s. | ||
| */ | ||
| public final class BuildCompletionHandler { | ||
| private final Project project; | ||
| private final BuildFile buildFile; | ||
|
|
||
| public BuildCompletionHandler(Project project, BuildFile buildFile) { | ||
| this.project = project; | ||
| this.buildFile = buildFile; | ||
| } | ||
|
|
||
| /** | ||
| * @param params The request params | ||
| * @return A list of possible completions | ||
| */ | ||
| public List<CompletionItem> handle(CompletionParams params) { | ||
| Position position = CompletionHandler.getTokenPosition(params); | ||
| DocumentId id = buildFile.document().copyDocumentId(position); | ||
| Range insertRange = CompletionHandler.getInsertRange(id, position); | ||
|
|
||
| Shape buildFileShape = Builtins.getBuildFileShape(buildFile.type()); | ||
|
|
||
| if (buildFileShape == null) { | ||
| return List.of(); | ||
| } | ||
|
|
||
| NodeCursor cursor = NodeCursor.create( | ||
| buildFile.getParse().value(), | ||
| buildFile.document().indexOfPosition(position) | ||
| ); | ||
| NodeSearch.Result searchResult = NodeSearch.search(cursor, Builtins.MODEL, buildFileShape); | ||
| var candidates = CompletionCandidates.fromSearchResult(searchResult); | ||
|
|
||
| var context = CompleterContext.create(id, insertRange, project) | ||
| .withExclude(searchResult.getOtherPresentKeys()); | ||
| var mapper = new SimpleCompleter.BuildFileMapper(context); | ||
|
|
||
| return new SimpleCompleter(context, mapper).getCompletionItems(candidates); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
90 changes: 90 additions & 0 deletions
90
src/main/resources/software/amazon/smithy/lsp/language/build.smithy
This file contains hidden or 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,90 @@ | ||
| $version: "2.0" | ||
|
|
||
| namespace smithy.lang.server | ||
|
|
||
| structure SmithyProjectJson { | ||
| sources: Strings | ||
| imports: Strings | ||
| outputDirectory: String | ||
| dependencies: ProjectDependencies | ||
| } | ||
|
|
||
| list ProjectDependencies { | ||
| member: ProjectDependency | ||
| } | ||
|
|
||
| structure ProjectDependency { | ||
| name: String | ||
|
|
||
| @required | ||
| path: String | ||
| } | ||
|
|
||
| structure SmithyBuildJson { | ||
| @required | ||
| version: SmithyBuildVersion | ||
|
|
||
| outputDirectory: String | ||
| sources: Strings | ||
| imports: Strings | ||
| projections: Projections | ||
| plugins: Plugins | ||
| ignoreMissingPlugins: Boolean | ||
| maven: Maven | ||
| } | ||
|
|
||
| @default("1") | ||
| string SmithyBuildVersion | ||
|
|
||
| map Projections { | ||
| key: String | ||
| value: Projection | ||
| } | ||
|
|
||
| structure Projection { | ||
| abstract: Boolean | ||
| imports: Strings | ||
| transforms: Transforms | ||
| plugins: Plugins | ||
| } | ||
|
|
||
| map Plugins { | ||
| key: String | ||
| value: Document | ||
| } | ||
|
|
||
| list Transforms { | ||
| member: Transform | ||
| } | ||
|
|
||
| structure Transform { | ||
| @required | ||
| name: String | ||
|
|
||
| args: TransformArgs | ||
| } | ||
|
|
||
| structure TransformArgs { | ||
| } | ||
|
|
||
| structure Maven { | ||
| dependencies: Strings | ||
| repositories: MavenRepositories | ||
| } | ||
|
|
||
| list MavenRepositories { | ||
| member: MavenRepository | ||
| } | ||
|
|
||
| structure MavenRepository { | ||
| @required | ||
| url: String | ||
|
|
||
| httpCredentials: String | ||
| proxyHost: String | ||
| proxyCredentials: String | ||
| } | ||
|
|
||
| list Strings { | ||
| member: String | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are constraints used by the LS? Could we possibly add more constraints to save energy doing validations like urls etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They really aren't right now. Originally I intended to use them for validation, but I scrapped that idea to use the validation errors from smithy-build. However, with trait values, required members get autopopulated in completions, so maybe a future update could do that for node values too.