File paths in URIForFile can come from index or local AST. Path from
index goes through URI transformation and the final path is resolved by URI
scheme and could be potentially different from the original path. Hence, we
should do the same transformation for all paths. We do this in URIForFile, which
now converts a path to URI and back to a canonicalized path.
Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
Event Timeline
clangd/Protocol.h | ||
---|---|---|
74 | We need to document the APIs and motivation, these are subtle. | |
75 | I think it's no longer sufficiently clear what this constructor does - it should be a named factory function, and the HintPath should be required. e.g. URIForFile URIForFile::canonicalize(StringRef AbsPath, StringRef HintPath) | |
75 | As we're exposing HintPath in more far-flung places, its semantics are becoming less obvious. I think we should make them more concrete, e.g. rename to TUPath and doc like Files can be referred to by several paths (e.g. in the presence of links). Which one we prefer may depend on where we're coming from. TUPath is a hint, and should usually be the main entrypoint file we're processing. | |
109 | Are there really *no* cases where the caller doesn't need canonicalization? | |
clangd/URI.cpp | ||
229 | this seems pretty indirect - including the call to create(), this function special-cases File 3 times. Seems a little cleaner to me to remove "file" from the registry, and repeat the loop here. Up to you. |
Thanks!
Mostly just places that should be updated HintPath -> TUPath. Changing the whole codebase doesn't seem important, but in places that are touched...
clangd/Protocol.cpp | ||
---|---|---|
45 | TUPath | |
64–67 | maybe more explicit: input should be "file" or "test" scheme, which do not... | |
clangd/Protocol.h | ||
88 | TUPath | |
clangd/URI.cpp | ||
221 | TUPath | |
228 | TUPath | |
clangd/URI.h | ||
65 | TUPath (and in comment) | |
72 | TUPath | |
unittests/clangd/TestFS.cpp | ||
95 | TUPath | |
unittests/clangd/URITests.cpp | ||
140 | TUPath |
As chatted offline, URIForFile is closer to ClangdServer, so TUPath is a good fit. But URI is more generic, and HintPath still seems to be a good fit there.
We need to document the APIs and motivation, these are subtle.