Skip to content
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

Replace DocumentParser impl with a real parser #162

Closed
wants to merge 4 commits into from

Conversation

milesziemer
Copy link
Contributor

Depends on #160 and #161 , leaving this in draft until those are merged.

This commit is the first of a few that refactor the 'frontend' of the
server, i.e. the completions, definition, hover, etc. It replaces the
implementation of DocumentParser, which was used to compute specific
syntactic information about a Smithy file, with an actual parser that
will be used in future commits to overhaul language features like
completions.

For now, this is mostly a 1:1 swap - DocumentParser now
does no parsing, but instead uses the results of the actual parser to
compute the same info it used to. The only other real change to
functionality is that DocumentParser no longer depends on the result of
loading the model, and SmithyFiles are re-parsed synchronously on
changes.

The javadoc for the new Syntax class contains more detailed
information on how the parser works, and why it works that way, but some
of it may not make complete sense with the current code in the language
server. The parser was built in tandem with the upgrades to completions,
and was specifically designed to enhance such features. Those upgrades
deserve their own commit, so I didn't include them here.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Previously, the language server only knew about a single workspace root,
so if your editor was using [WorkspaceFolders](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_workspaceFolders)
the server would just pick the first one, and not load any others. This
commit allows the server to load multiple workspaces. The primary
challenge was handling state changes to individual workspaces
independently. We use client-side file watchers and the
`didChangeWatchedFiles` notification to make sure projects are up to
date with new and deleted Smithy files, and any changes to build files
(i.e. smithy-build.json). `didChangeWatchedFiles` sends a flat list of
file events - not partitioned by workspace - so we have to figure out
which projects each change applies to. This is done by creating a
`PathMatcher` for each project's smithy files and build files, then
matching on each file event. This way, we can apply changes to each
individual project, rather than reloading everything. Selectors were
also updated to select from all available projects.
The file patterns we were using for telling the client which files to
watch, and to match file events in `didChangeWatchedFiles` to projects,
were not working properly on windows because they didn't use the correct
file separator.
Refactors various things to make use of newer java features, including
record classes, text blocks, and new APIs.
This commit is the first of a few that refactor the 'frontend' of the
server, i.e. the completions, definition, hover, etc. It replaces the
implementation of DocumentParser, which was used to compute specific
syntactic information about a Smithy file, with an actual parser that
will be used in future commits to overhaul language features like
completions.

For now, this is mostly a 1:1 swap - DocumentParser now
does no parsing, but instead uses the results of the actual parser to
compute the same info it used to. The only other real change to
functionality is that DocumentParser no longer depends on the result of
loading the model, and SmithyFiles are re-parsed synchronously on
changes.

The javadoc for the new `Syntax` class contains more detailed
information on how the parser works, and why it works that way, but some
of it may not make complete sense with the current code in the language
server. The parser was built in tandem with the upgrades to completions,
and was specifically designed to enhance such features. Those upgrades
deserve their own commit, so I didn't include them here.
@milesziemer
Copy link
Contributor Author

Closing in favor of #166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant