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

Fix canonical paths for paths with spaces #3491

Merged
merged 5 commits into from
Feb 9, 2023
Merged

Conversation

MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented Feb 8, 2023

After testing today's version of Dafny in VSCode, I realized that a path with name triggered an error when attempting to resolve includes. Hence, I added a unit test to catch this regression for next time and fixed the method that transforms file paths (which can be gross URI) to actual file locations

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

After testing today's version of Dafny in VSCode, I realized that a path with name triggered an error when attempting to resolve includes.
Hence, I added a unit test to catch this regression for next time and fixed the method that trasnforms file paths (which can be gross URI) to actual file locations
@MikaelMayer MikaelMayer self-assigned this Feb 8, 2023
if (filePath.StartsWith("file:\\")) {
// Recovery mechanisms for the language server
return filePath.Substring("file:\\".Length);
var potentialPrefixes = new List<string>() { "file:\\", "file:/", "file:" };
Copy link
Member

@keyboardDrummer keyboardDrummer Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised we need custom code to handle file paths. Why can't Uri help us with all our path parsing and canonicalisation needs?

Also, where do all these potential prefixes come from? Can we document that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised too.
There is some history about that. In the formatter, I had to switch to plain file URIs for token's filenames, because otherwise it would not be consistent with VSCode URIs. It looks like VSCode's URIs are slightly different than LSP URI, for example, a period in a disk name is encoded on one and not the other.

I wish there is a better solution but for now it's urgent we have a fix. I remember having spent a lot of time previously to ensure everything was working acceptably on the CLI and the language server (including unsaved files, and stdin), both on Windows and Linux.
Yesterday was the first time I tested the code for paths with spaces, and that's probably why it wasn't caught before. After this fix is pushed, feel free to experiment with different alternatives.

@MikaelMayer MikaelMayer added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label release-blocker Must be resolved before the next release has-workaround: no There are no known workarounds labels Feb 9, 2023
@MikaelMayer MikaelMayer merged commit 9e16ab3 into master Feb 9, 2023
@MikaelMayer MikaelMayer deleted the fix-canonical-path branch February 9, 2023 16:10
fabiomadge added a commit to fabiomadge/dafny that referenced this pull request Feb 10, 2023
fabiomadge pushed a commit to fabiomadge/dafny that referenced this pull request Feb 10, 2023
MikaelMayer added a commit that referenced this pull request Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-workaround: no There are no known workarounds kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label release-blocker Must be resolved before the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants