smithy-lang / smithy-language-server

A Language Server Protocol implementation for the Smithy IDL
https://smithy.io
Apache License 2.0
33 stars 18 forks source link

Store model text in memory #121

Open milesziemer opened 10 months ago

milesziemer commented 10 months ago

This is primarily a refactor of SmithyProject to store raw model text in memory. Previously, we only stored file objects for the model, and gave those to the model assembler. There are two issues with this approach:

  1. While a file is being editted, the source of truth for the file contents should be what the client sends back to the server in the didChange event, not whats actually in the file. To get around this, we've been using a temporary file that stores the contents of the file being editted, and giving that to the model assembler. When publishing diagnostics however, we needed to re-map the file location from the temporary file to the actual file on disk.
  2. The language server needs literal text to provide some of its features, meaning we need to read in files frequently.

These changes update SmithyProject to store a map of URI -> String for each of the model files in the loaded model by walking the shapes and collecting all unique file locations. SmithyTDS is updated to use that when it needs to have literal text of the model for formatting, version diagnostics, and other features.

Various other updates were also made:

The following test updates were made:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.