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(lsp): normalize windows file URLs properly #10034

Merged
merged 5 commits into from
Apr 8, 2021

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Apr 6, 2021

@kitsonk kitsonk requested review from lucacasonato and ry April 6, 2021 08:07
@ry ry requested review from piscisaureus and removed request for ry and lucacasonato April 6, 2021 18:34
@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 7, 2021

ok, I have test this under windows and it resolves the issue...

cli/lsp/urls.rs Outdated Show resolved Hide resolved
cli/lsp/urls.rs Outdated Show resolved Hide resolved
@piscisaureus
Copy link
Member

It's not quite clear to me what the purpose of normalizing is here. I would suppose that file:https:/// URLs would always get percent-decoded, as they are URLs after all.

So if I had written:

import "file:https:///C%2A/foo/bar/baz/file%20with%20%25%20and%20%23%20in%20the%20name.txt";

It'd import from:

C:\foo\bar\baz\file with % and # in the name.txt

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 8, 2021

@piscisaureus thanks for the feedback. I have taken a different approach, which should be far more foolproof. File URLs are transformed into file paths and then back into file URLs. This ensures that the URL will be normalized in a way that matches Rust's behaviour. I tested it again on windows and it fixes both the linked issues, but should be able to be generically applied to any client URL.

@piscisaureus
Copy link
Member

This looks good! Would be great to have a unit test.

@kitsonk
Copy link
Contributor Author

kitsonk commented Apr 8, 2021

This looks good! Would be great to have a unit test.

There are two unit tests, one for a Windows system (which ensures the drive letter get recapitalised) and one for non-windows which deals just with percent encoding of parts of the path.

Did you mean some sort of integration test? Those are complicated in this case because of the need to write out real files, mangle them, craft the messages and then send them in and deal with the nature of windows versus non-windows.

Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

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

LGTM

@piscisaureus
Copy link
Member

Sorry, I must have overlooked the tests that were already there.

@kitsonk kitsonk merged commit 1ed9512 into denoland:main Apr 8, 2021
@kitsonk kitsonk deleted the kitsonk/issue9744 branch April 8, 2021 23:36
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.

Bug: Weird path resolving lsp: Extension reports spurious errors on Windows because of path encoding issues
2 participants