-
Notifications
You must be signed in to change notification settings - Fork 99
Add NormalizedFilePath from ghcide #224
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
Conversation
631a192 to
c9f802b
Compare
alanz
left a comment
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.
LGTM, would want sign-off from @cocreature and/or @mpickering
c9f802b to
deefb9c
Compare
cocreature
left a comment
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.
The changes look reasonable but I would prefer to keep the way the tests are currently setup so that you can test Windows filepath conversions without access to a Windows machine. Yes, setting up CI would catch this but it’s much more convenient to be able to test this locally.
|
@cocreature ok, i would prefer to keep the To have CI running in windows have advantages beyond this concrete module. Not sure if you have tried to add windows to ghcide azure ci but i would recommend it strongly 😃 |
|
@cocreature ok, i've recovered the tests over the platform aware functions as they was in 2dceca9, cause those functions had been reverted to that version (they are not doing a full normalization now). |
| toNormalizedFilePath :: FilePath -> NormalizedFilePath | ||
| toNormalizedFilePath fp = NormalizedFilePath nuri nfp | ||
| where nfp | fp == "" = "" | ||
| -- ghcide want to keep empty paths instead of normalising them to "." |
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.
@cocreature what do you think about remove this corner case? i would prefer to keep it in ghcide instead the lib
| -- ghcide want to keep empty paths instead of normalising them to "." | ||
| | otherwise = FP.normalise fp | ||
| uriStr = fileScheme <> "//" <> platformAdjustToUriPath System.Info.os nfp | ||
| nuriStr = T.pack $ escapeURIString isUnescapedInURI $ unEscapeString $ uriStr |
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.
@cocreature i think this part is making roundtrip tests fail and i am not sure it is intentional. Consider the repl session:
> toNormalizedFilePath "C:\\a#s"
NormalizedFilePath "C:\\a#s"
> normalizedFilePathToUri $ toNormalizedFilePath "C:\\a#s"
NormalizedUri 1827512744 "file:///C:/a#s"
> uriToNormalizedFilePath $ normalizedFilePathToUri $ toNormalizedFilePath "C:\\a#s"
Just NormalizedFilePath "C:\\a"
shouldnt NormalizedUri _"file:///C:/a#s" be NormalizedUri _"file:///C:/a%23s"?
Like the old functions already does:
> filePathToUri "C:\\a#s"
Uri {getUri = "file:///C:/a%23s"}
> uriToFilePath $ filePathToUri "C:\\a#s"
Just "C:\\a#s"
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.
I've removed temporary the extra unescape/escape uri step to check if tests pass
|
I've added some changes to make the roundtrip tests pass, to do so i've have to change the function that normalizes the percent encoding I want to highlight the new test cases: it "converts a file path with reserved uri chars to a normalized URI and back" $ do
let start = if isWindows then "C:\\" else "/"
let fp = start ++ "path;part#fragmen?param=val"
let nuri = toNormalizedUri (filePathToUri fp)
uriToFilePath (fromNormalizedUri nuri) `shouldBe` Just fp
it "converts a file path with substrings that looks like uri escaped chars and back" $ do
let start = if isWindows then "C:\\" else "/"
let fp = start ++ "ca%C3%B1a"
let nuri = toNormalizedUri (filePathToUri fp)
uriToFilePath (fromNormalizedUri nuri) `shouldBe` Just fpBefore changing the normalization of percent encoding those tests did not hold and files with To achieve that i had to add another computation to |
cocreature
left a comment
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.
LGTM, thanks a lot!
|
@cocreature sorry for make more changes after your review, but i have a wip pr to adapt ghcide to this changes and i think it worths move the empty path case to ghcide cause other downstream packages could have troubles with that corner case. |
|
@jneira when you and @cocreature are happy with this please merge it. I think we should make a new haskell-lsp release soon, there have been a number of changes recently. |
|
In the light of haskell/ghcide#479 i think this pr could be merged as is. I'll do tomorrow if nobody disagree |
FP.normaliseonce infromNormalizedFilePath . uriToNormalizedFilePath . normalizedFilePathToUri . toNormalizedFilePath, like the actual ghcide impl so i hope the performance will be not degradeduriTofilePathandfilePathToUriare now deprecated, with the goal of replace them with the newNormalizedFilePathfunctions. They should be removed in the next breaking release after this one.