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

URI - file system path conversion fixes #447

Merged
merged 11 commits into from
Jan 14, 2021

Conversation

lukaszsamson
Copy link
Collaborator

This PR adds tests and some fixes to URI handling. The tests was based on test cases from https://github.com/microsoft/vscode-uri/blob/master/src/test/uri.test.ts - this is the library used by vscode
Improvements to URI handling include:

  • Properly escapes control URI characters (#, ?, etc)
  • Normalizes Windows drive letter to downcase
  • Adds support for UNC paths (other language servers do support them)
  • Validates that URI is of file scheme
    Other improvements
  • Fixes invalid URIs used in tests
  • Fixes formatter tests depending on this project's .formatter.exs

Fixes #444
Fixes #416

file_path = file_uri |> SourceFile.path_from_uri() |> Path.absname()

not String.starts_with?(file_path, project_dir) or
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The negation that was here seems wrong. @axelson do you have any idea why it was like this?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, it does seem backwards. I'd have to do some investigation but I would guess that it would be related to the fact that previously it wasn't doing a Path.absname before. But I'd have to do some more investigation to be more sure. If we do keep a check like it around, then I think we should refactor it to make it a bit more obvious exactly what it is checking (and add some relevant tests).

For reference this is the commit that introduced it: d143772

Copy link
Collaborator Author

@lukaszsamson lukaszsamson Jan 10, 2021

Choose a reason for hiding this comment

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

Right, this module would use a refactor and better test coverage. Should I create a new issue? Edit: #459

lukaszsamson and others added 11 commits January 4, 2021 19:58
tests and implementation basing on https://github.com/microsoft/vscode-uri
adds support for UNC paths
adds downcasing for Windows drive letters
fixes character escaping for paths with URI control characters (?, #, : etc)
don't translate non file: URIs to paths
file://project/file.ex is a path to /file.ex on project server
valid UNIX path URI to /project/file.ex is file:///project/file.ex
Copy link
Member

@axelson axelson left a comment

Choose a reason for hiding this comment

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

Looks good ❤️

@axelson axelson merged commit e8c381b into master Jan 14, 2021
@axelson axelson deleted the ls-uri-fspath-conversions-fixes branch January 14, 2021 18:12
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.

Nova unsaved URI format crashes server mix format formats apps/elixir_ls_utils/test/tmp
2 participants