Fix jar uri conversion #233
Merged
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.
The language server has to convert to and from LSP's URIs and the Smithy model's source location filenames. The filenames used for files in jars are actually URIs in the form
jar:file/foo.jar!/bar.smithy- obviously there isn't an actual file path to a file within a jar.Because LSP's URIs and these Jar URIs are URIs, they're percent-encoded. When we convert from a regular file URI -> filename,
Path.of(URI).toString()makes sure the filename ends up properly decoded, regardless of how the client encoded the URI. However, when going from jar file URI -> jar file filename (as it appears in the model), we don't want to decode the URI (because the filename is encoded in the model).This should be easy, but since some clients encode the URI differently, the URI sent by the client might not be encoded the same way it is in the model filename. In particular, VSCode is quite aggresive in its encoding, and encodes the
!in the jar URI. To handle this, we were decoding the LSP URI, but if the URI has other special characters, like spaces, those would also be decoded. I'm pretty sure this would always be an issue on windows too, since the:inC:would be encoded.The problem hasn't come up yet, because who puts special characters in file/directory names? However, when trying to autodownload our new standalone installations in the VSCode extension, I found that extensions' storage directories are under
/Application Support/on Mac. So we need to fix this in order to autodownload the language server.To fix this, I updated the implementation of a few methods in LspAdapter. Most notable is the new
smithyJarUriToJarModelFilenamemethod which takes an LSP jar URI and turns it into a Java URI that can properlytoString()into the model filename, ortoURL()into a URL that can be used to read the contents of the file. The method has a comment that explains how it works - it's really a hack.We really shouldn't be using strings to represent URIs and paths at all, but at some point we still need to go back and forth between LSP URI and model filename, so I'm not sure if that would fix the problem, or just move it.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.