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 Windows by handling Url paths correctly. #136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hauserx
Copy link

@hauserx hauserx commented Dec 2, 2024

Previous implementation was using Url.path() where it should use Url.to_file_path()

It caused errors like:

"Error: `file:///C:/work/bazel_plain/sample.bzl` could not be converted back to a URL\n"

More: cameron-martin/bazel-lsp#62

The Url.path() is usually "/" + path to file which works fine as file path under unix-like systems, but breaks under Windows, where it can be e.g. "/c:/some/file". See
https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#syntax

Switched to using Url.to_file_path() which represents actual file path.

In the process:

  • Enabled back Windows tests that at least for my machine started passing;
  • In validate() function not converting from Url to LspUrl and back, just returning to client Url passed in the request.

Previous implementation was mixing Url paths with file paths.

It caused errors like:

"Error: `file:///C:/work/bazel_plain/sample.bzl` could not be converted back to a URL\n"

More: cameron-martin/bazel-lsp#62

The Url.path() is usually `"/" + path to file` which works fine as file
path under unix-like systems, but breaks under Windows, where it can be
e.g. "/c:/some/file". See
https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#syntax

Switched to using Url.to_file_path() which
represents actual file path.

In the process:
  - Enabled back Windows tests that at least for my machine started
    passing;
  - In validate() function not converting from Url to LspUrl and back,
    just returning to client Url passed in the request.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 2, 2024
Copy link
Contributor

@ndmitchell ndmitchell left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for this fix, a really nice improvement. One question around the test paths, let me know what seems best here, and then I'll merge it.

// Converts PathBuf to string that can be used in starlark load statements.
// Performs simple string quoting by replacing \ with \\ (for windows paths).
fn path_buf_to_load_string(p: &PathBuf) -> String {
p.to_str().unwrap().replace("\\", "\\\\")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would \ to / not be a simpler thing to do? Also I think you can do \\ for the first argument to get a more efficient replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants