This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Extract FsPath from file:// uri
ClosedPublic

Authored by stanionascu on Mar 27 2017, 10:32 AM.

Details

Summary

rfc8089#appendix-E.2 specifies that paths can begin with a drive letter e.g. as file:///c:/.
In this case just consuming front file:// is not enough and the 3rd slash must be consumed to produce a valid path on windows.

The patch introduce a generic way of converting an uri to a filesystem path and back.

Event Timeline

stanionascu created this revision.Mar 27 2017, 10:32 AM
krasimir added inline comments.Apr 4 2017, 3:12 AM
clangd/ASTManager.cpp
166

I think we should rename the Uri parameter here to File.

178

I think we should rename the Uri parameter here to File.

clangd/Protocol.cpp
61

Hm, seems to me that here the uri should be kept as-is and the clients of Result.uri should convert it to file when appropriate. Otherwise it's confusing.

167

Same thing: I think that the clients should be responsible of converting Result.uri to a filename.

clangd/Protocol.h
32

It's a little confusing: the parse method turns an uri to a file and the unparse method does the opposite. Maybe we should use more descriptive names, like uriToFile and fileToUri. This does not seem to be inconsistent with the rest of the protocol since the protocol only cares about uri-s, and file-s are an implementation detail of clangd I guess.

clangd/clients/clangd-vscode/src/extension.ts
28

By the way, what does this do? I'm not a typescript vs code guru.

Refactored URI handling to make it more explicit, also updated the parts which expect a File parameter and not an URI.

stanionascu marked 5 inline comments as done.Apr 5 2017, 12:53 PM
stanionascu added inline comments.
clangd/Protocol.cpp
61

Implemented the "URI::parse" to store both representations.

clangd/Protocol.h
32

2nd try now, instead of actually storing a string based URI, store the object which both representations (uri and file).

clangd/clients/clangd-vscode/src/extension.ts
28

Extended the FIXME, with the description, e.g. when vscode (on windows) sends the uri to clangd, it's represented as "file:///c%3A/path/tofile" which leads to:

  • incorrect detection of the compilation database location.
  • cannot find the actual unit in the database.

uri.toString(true) - skips the percent encoding and sends the uri parameter to clangd as "file:///c:/path/tofile"

krasimir accepted this revision.Apr 6 2017, 5:27 AM

Looks good!

This revision is now accepted and ready to land.Apr 6 2017, 5:27 AM
stanionascu marked 2 inline comments as done.Apr 6 2017, 10:16 PM

Thank you for the review!

If there are no other comments/suggestions, would be great if someone would merge it as I'm lacking the permission to do so.

This revision was automatically updated to reflect the committed changes.