-
Notifications
You must be signed in to change notification settings - Fork 73
fix: use Path.toUri() to handle WSL paths correctly #1378
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
base: main
Are you sure you want to change the base?
Conversation
|
Converted to draft due to open to-dos:
@angelozerr Would you prefer the first ones in separate PRs? |
|
@tim-sh thanks for your contribution. I plan to do a release soon,I don't know how it will take time to fix this issue? |
|
Windows CI build is failling https://github.com/redhat-developer/lsp4ij/actions/runs/19733661567/job/56541191426?pr=1378#step:5:74 but it is perhaps normal (you have not finished your work). |
|
Do you need this PR for the next release? |
|
@angelozerr Thanks for asking! Yes, that would be phantastic. I'm working to get it done now. |
Ok I wanted to create release next week, do you think it will possible? |
The previous implementation used `File.toURI()`, which incorrectly encodes the server name of a UNC path (including WSL paths like `\\wsl$\...`) into the URI's path component. This resulted in invalid URIs with four leading slashes (e.g., `file:////wsl$/...`). This change updates the logic to use the modern `java.nio.file.Path.toUri()` method. This correctly parses the server name (e.g., `wsl$`) into the URI's authority component, producing a valid and standards-compliant URI (e.g., `file://wsl$/...`). Also: - add a new test case to verify the correct handling of WSL paths. - add the JUnit Jupiter engine dependency to the build to enable the execution of the test.
b2e15f9 to
409c48a
Compare
src/main/java/com/redhat/devtools/lsp4ij/features/formatting/AbstractLSPFormattingService.java
Outdated
Show resolved
Hide resolved
src/test/java/com/redhat/devtools/lsp4ij/LSPIJUtils_toUriTest.java
Outdated
Show resolved
Hide resolved
| } catch (URISyntaxException e) { | ||
| LOGGER.warn(e.getLocalizedMessage(), e); | ||
| return file.getAbsoluteFile().toURI(); | ||
| return file.toPath().toUri(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment Hich explains why path is used by adding in comments some url sample
|
The PR seems very nice. My only fear is that it doesnt cover some cases and introduce some bugs |
Thanks for the feedback! I can understand that fear. |
|
I will also add a test comparing the old and the new result and asserting that it only changes for WSL or other paths starting with a host name. What do you think, would that provide sufficient safety? |
Your tests is great. If you want to test I suggest that you read section build zip from readme. I will also test on my side |
|
@angelozerr Thanks! I will do that. Also, I saw that the core functionality doesn't even seem to work, which will have to be debugged. Might not manage all that today but hopefully on Monday. |
|
@tim-sh please note that test fails https://github.com/redhat-developer/lsp4ij/actions/runs/19746312974/job/56630539800?pr=1378#step:5:79 |
Yes, as mentioned, I'll have to debug this… |
Thanks! Once test will pass, I will try your PR on my side. |
|
@tim-sh I would like to create a release this week. Even if your PR makes sense, it is too dangerous to merge it for the release. Hope you will understand. |
|
@angelozerr I see. So far, I haven't been able to get the Windows build running in a VM, but will continue to work on it on Thu. If it's not included in lsp4ij for now, I'd see where we can override to test this. However, since I understand you have a positive outlook on this PR in general, is there any way we could test a build output from this PR? |
I am on windows os, i will investigate the problem after the release.
I fear for formatting you will not able to override it. For other features you should implement your own file uri support.
Except installing the build zip, no |
Thank you.
I see. In my mind, the better solution (considering other servers face the same problem) would be fixing this in lsp4ij anyway.
Thanks for the hint – overlooked the artifact. That'll be an opportunity to test against lsp4ij in the shape of a zip (we should try that anyway). |
I totally agree! Hope your fix will be included in 0.20.0 future release.
|
The previous implementation used
File.toURI(), which incorrectly encodes the server name of a UNC path (including WSL paths like\\wsl$\...) into the URI's path component. This resulted in invalid URIs with four leading slashes (e.g.,file:////wsl$/...).This change updates the logic to use the modern
java.nio.file.Path.toUri()method. This correctly parses the server name (e.g.,wsl$) into the URI's authority component, producing a valid and standards-compliant URI (e.g.,file://wsl$/...).Also: