This allows implementations like different symbol indexes to know what
the current active file is. For example, some customized index implementation
might decide to only return results for some files.
Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
- Build Status
Buildable 21243 Build 21243: arc lint + arc unit
Event Timeline
Short summary of the offline discussion: I suggest adding this parameter into the corresponding requests of the index (FuzzyFindRequest, FindDefinitionsRequest) instead of stashing it in the context. Context has all the same problems as the global variables, so we should try to avoid using it where possible.
On the other hand, where this key is stored might not be terribly important if we don't have too many usages and remove it when we can workaround the limitations that we're currently facing.
In any case, we should add a comment that the active file should be avoided and will be removed.
clangd/ClangdServer.cpp | ||
---|---|---|
162 ↗ | (On Diff #159701) | If we want to set this value more consistently, maybe do it in TUScheduler::runWithPreamble/runWithAST? |
clangd/Context.cpp | ||
35 ↗ | (On Diff #159701) | Maybe move it somewhere else? E.g. to Index.h, since that's where it's supposed to be used to workaround current limitations? |
35 ↗ | (On Diff #159701) | Maybe use std::string? Contexts can easily be cloned/migrated between threads, so it's very easy to end up with pointers to dead strings here. |
clangd/Context.h | ||
223 ↗ | (On Diff #159701) | Maybe choose a scarier name and add a comment that we're not gonna use it in the long-term? |
Thanks for the summary! Just for the record, my concerns were:
- The concept of active files are not really index-specific.
- We need to do this for all 3 different requests (need "scary" comments 3 places?).
- The context value seems to be trivial enough and hard to be misused.
On the other hand, where this key is stored might not be terribly important if we don't have too many usages and remove it when we can workaround the limitations that we're currently facing.
clangd/ClangdServer.cpp | ||
---|---|---|
162 ↗ | (On Diff #159701) | I have two concerns about doing this:
|
clangd/Context.cpp | ||
35 ↗ | (On Diff #159701) | I intentionally used StringRef here to make it harder to use and hoped that users would be more careful when using this. For the current simple use cases, StringRef should be sufficient IMO. |
35 ↗ | (On Diff #159701) | We should probably look for some other place to put this, but I don't think Index.h is the right place. Although context might not be the best place to host the active file, the active file seems to be a well-defined concept in clangd in general and not index-specific. |
clangd/ClangdServer.cpp | ||
---|---|---|
162 ↗ | (On Diff #159701) |
If we want to make the data-flow explicit, let's add this to the index request parameters.
And we don't set the file path for them anyway, because there's not active file in that case. How is that different in either of the approaches? |
clangd/Context.cpp | ||
35 ↗ | (On Diff #159701) | Maybe move it ClangdServer.h or TUScheduler,h then? (depending on where we set it). I still don't think Context.h is the right place for it, it should not contain any application-specific keys. |
35 ↗ | (On Diff #159701) | We're relying too much on the data flow of contexts, which is implicit and we completely don't control. Even if we don't access dead StringRefs now, it's very easy to accidentally introduce this behavior later. We should use string here, there's just too high risk of hitting a bug otherwise. What are the disadvantages of using string here? |
Ok, I am convinced :) Putting the context key into TUScheduler.cpp and exposing a static method to access it sound like a better idea afterall. Thanks for the suggestions!
NIT: accidental whitespace change?