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
- Build Status
Buildable 25278 Build 25277: arc lint + arc unit
Event Timeline
clangd/Protocol.h | ||
---|---|---|
73 | We need to document the APIs and motivation, these are subtle. | |
74 | 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) | |
74 | 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. | |
98 | Are there really *no* cases where the caller doesn't need canonicalization? | |
clangd/URI.cpp | ||
235 | 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 | ||
---|---|---|
42 | TUPath | |
62–65 | maybe more explicit: input should be "file" or "test" scheme, which do not... | |
clangd/Protocol.h | ||
87 | TUPath | |
clangd/URI.cpp | ||
227 | TUPath | |
234 | TUPath | |
clangd/URI.h | ||
65 | TUPath (and in comment) | |
72 | TUPath | |
unittests/clangd/TestFS.cpp | ||
92 | TUPath | |
unittests/clangd/URITests.cpp | ||
155 | 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.