Skip to content

Conversation

@tim-sh
Copy link

@tim-sh tim-sh commented Nov 27, 2025

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.

@tim-sh tim-sh marked this pull request as draft November 27, 2025 10:53
@tim-sh
Copy link
Author

tim-sh commented Nov 27, 2025

Converted to draft due to open to-dos:

  • replace a couple of remaining direct calls to File#toURI with toUri
  • clarify what to do with the rootPath (as opposed to Uri) → let's leave that one out of the equation for now, since it's not the core problem here – and LSP4IJ just calls VirtualFile#getPath on an element of what the IJ BaseProjectDirectories.Companion#getBaseDirectories method returns, which is pretty generic
  • test on Windows

@angelozerr Would you prefer the first ones in separate PRs?

@angelozerr
Copy link
Contributor

@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?

@angelozerr
Copy link
Contributor

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).

@angelozerr
Copy link
Contributor

Do you need this PR for the next release?

@tim-sh
Copy link
Author

tim-sh commented Nov 27, 2025

@angelozerr Thanks for asking! Yes, that would be phantastic. I'm working to get it done now.

@angelozerr
Copy link
Contributor

@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.
@tim-sh tim-sh marked this pull request as ready for review November 27, 2025 15:10
@tim-sh tim-sh changed the title fix(lsp): use Path.toUri() to handle WSL paths correctly fix: use Path.toUri() to handle WSL paths correctly Nov 27, 2025
} catch (URISyntaxException e) {
LOGGER.warn(e.getLocalizedMessage(), e);
return file.getAbsoluteFile().toURI();
return file.toPath().toUri();
Copy link
Contributor

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

@angelozerr
Copy link
Contributor

The PR seems very nice. My only fear is that it doesnt cover some cases and introduce some bugs

@tim-sh
Copy link
Author

tim-sh commented Nov 28, 2025

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.
Is there any way I could test the version of this PR from a nightly-like build? This way I could do a first smoke test for both Linux and Windows.

@tim-sh
Copy link
Author

tim-sh commented Nov 28, 2025

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?

@angelozerr
Copy link
Contributor

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

@tim-sh
Copy link
Author

tim-sh commented Nov 28, 2025

@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.

@angelozerr
Copy link
Contributor

@tim-sh
Copy link
Author

tim-sh commented Nov 28, 2025

@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…

@angelozerr
Copy link
Contributor

@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.

@angelozerr
Copy link
Contributor

@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.

@tim-sh
Copy link
Author

tim-sh commented Dec 2, 2025

@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?

@angelozerr
Copy link
Contributor

@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.

I am on windows os, i will investigate the problem after the release.

If it's not included in lsp4ij for now, I'd see where we can override to test this.

I fear for formatting you will not able to override it. For other features you should implement your own file uri support.

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?

Except installing the build zip, no

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.

2 participants