summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Move clangd tests to clangd directory. check-clangd is no longer ↵Sam McCall2019-04-291-710/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | part of check-clang-tools. Summary: Motivation: - this layout is a pain to work with - without a common root, it's painful to express things like "disable clangd" (D61122) - CMake/lit configs are a maintenance hazard, and the more the one-off hacks for various tools are entangled, the more we see apathy and non-ownership. This attempts to use the bare-minimum configuration needed (while still supporting the difficult cases: windows, standalone clang build, dynamic libs). In particular the lit.cfg.py and lit.site.cfg.py.in are merged into lit.cfg.in. The logic in these files is now minimal. (Much of clang-tools-extra's lit configs can probably be cleaned up by reusing lit.llvm.llvm_config.use_clang(), and every llvm project does its own version of LDPATH mangling. I haven't attempted to fix any of those). Docs are still in clang-tools-extra/docs, I don't have any plans to touch those. Reviewers: gribozavr Subscribers: mgorny, javed.absar, MaskRay, jkorous, arphaman, kadircet, jfb, cfe-commits, ilya-biryukov, thakis Tags: #clang Differential Revision: https://reviews.llvm.org/D61187 llvm-svn: 359424
* [clangd] Wait for compile command in ASTWorker instead of ClangdServerEric Liu2019-04-151-33/+32
| | | | | | | | | | | | | | | | | | Summary: This makes addDocument non-blocking and would also allow code completion (in fallback mode) to run when worker waits for the compile command. Reviewers: sammccall, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60607 llvm-svn: 358400
* [clangd] Implement textDocument/declaration from LSP 3.14Sam McCall2019-02-011-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: LSP now reflects the declaration/definition distinction. Language server changes: - textDocument/definition now returns a definition if one is found, otherwise the declaration. It no longer returns declaration + definition if they are distinct. - textDocument/declaration returns the best declaration we can find. - For macros, the active macro definition is returned for both methods. - For include directive, the top of the target file is returned for both. There doesn't appear to be a discovery mechanism (we can't return everything to clients that only know about definition), so this changes existing behavior. In practice, it should greatly reduce the fraction of the time we need to show the user a menu of options. C++ API changes: - findDefinitions is replaced by locateSymbolAt, which returns a vector<LocatedSymbol> - one for each symbol under the cursor. - this contains the preferred declaration, the definition (if found), and the symbol name This API enables some potentially-neat extensions, like swapping between decl and def, and exposing the symbol name to the UI in the case of multiple symbols. Reviewers: hokein Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D57388 llvm-svn: 352864
* [clangd] Suggest adding missing includes for incomplete type diagnostics.Eric Liu2019-01-281-4/+6
| | | | | | | | | | | | | | | | | | | Summary: This enables clangd to intercept compiler diagnostics and attach fixes (e.g. by querying index). This patch adds missing includes for incomplete types e.g. member access into class with only forward declaration. This would allow adding missing includes for user-typed symbol names that are missing declarations (e.g. typos) in the future. Reviewers: sammccall Reviewed By: sammccall Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D56903 llvm-svn: 352361
* [clangd] Support clang-tidy configuration in clangd.Haojian Wu2019-01-221-1/+2
| | | | | | | | | | | | | | | | | | | | | Summary: This patch adds some basic supports for clang-tidy configurations in clangd: - clangd will respect .clang-tidy configurations for each file - we don't aim to support all clang-tidy options in clangd, only a small subset of condfigurations (options related to which checks will be enabled) are supported. - add a `clang-tidy-checks` CLI option that can override options from .clang-tidy file Reviewers: ilya-biryukov, sammccall Reviewed By: sammccall Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D55256 llvm-svn: 351792
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clangd] Remove 'using namespace llvm' from .cpp files. NFCIlya Biryukov2019-01-071-5/+4
| | | | | | | | The new guideline is to qualify with 'llvm::' explicitly both in '.h' and '.cpp' files. This simplifies moving the code between header and source files and is easier to keep consistent. llvm-svn: 350531
* [clangd] clang-format everything. NFCIlya Biryukov2019-01-031-33/+31
| | | | llvm-svn: 350303
* [clangd] Avoid emitting Queued status when we are able to acquire the Barrier.Haojian Wu2018-12-131-2/+0
| | | | | | | | | | Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D55359 llvm-svn: 349032
* [clangd] Remove the test that sometimes deadlocksIlya Biryukov2018-12-061-23/+0
| | | | | | Will figure out how to properly rewrite it and recommit. llvm-svn: 348490
* [clangd] Update the test codeHaojian Wu2018-12-061-4/+0
| | | | | | I forgot to update it in the last round of code review. llvm-svn: 348478
* [clangd] C++ API for emitting file status.Haojian Wu2018-12-061-1/+79
| | | | | | Introduce clangd C++ API to emit the current status of file. llvm-svn: 348475
* [clangd] Fix a typo in TUSchedulerTestsHaojian Wu2018-12-061-1/+1
| | | | | | | | | | | | Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D55312 llvm-svn: 348467
* [clangd] Cleanup: make the diags callback global in TUSchedulerIlya Biryukov2018-11-221-96/+142
| | | | | | | | | | | | Reviewers: sammccall Reviewed By: sammccall Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54760 llvm-svn: 347474
* [clangd] Cleanup error consumption code. NFCIlya Biryukov2018-11-221-17/+9
| | | | | | | - Remove reimplementations of llvm::consumeError. - Simplify test code by using EXPECT_ERROR where it fits. llvm-svn: 347472
* [clangd] Cleanup: make diagnostics callbacks from TUScheduler non-racyIlya Biryukov2018-11-221-0/+7
| | | | | | | | | | | | | | | | | | | | | | Summary: Previously, removeDoc followed by an addDoc to TUScheduler resulted in racy diagnostic responses, i.e. the old dianostics could be delivered to the client after the new ones by TUScheduler. To workaround this, we tracked a version number in ClangdServer and discarded stale diagnostics. After this commit, the TUScheduler will stop delivering diagnostics for removed files and the workaround in ClangdServer is not required anymore. Reviewers: sammccall Reviewed By: sammccall Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54829 llvm-svn: 347468
* [clangd] Fix use-after-scope in unit testBenjamin Kramer2018-11-221-1/+1
| | | | | | | The scheduler holds a reference to `Proceed`, so it has to be destroyed after the scheduler. Found by asan. llvm-svn: 347460
* [clangd] Respect task cancellation in TUScheduler.Sam McCall2018-11-221-0/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: - Reads are never executed if canceled before ready-to run. In practice, we finalize cancelled reads eagerly and out-of-order. - Cancelled reads don't prevent prior updates from being elided, as they don't actually depend on the result of the update. - Updates are downgraded from WantDiagnostics::Yes to WantDiagnostics::Auto when cancelled, which allows them to be elided when all dependent reads are cancelled and there are subsequent writes. (e.g. when the queue is backed up with cancelled requests). The queue operations aren't optimal (we scan the whole queue for cancelled tasks every time the scheduler runs, and check cancellation twice in the end). However I believe these costs are still trivial in practice (compared to any AST operation) and the logic can be cleanly separated from the rest of the scheduler. Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54746 llvm-svn: 347450
* [clangd] workspace/symbol should be async, it reads from the index.Sam McCall2018-10-251-0/+12
| | | | | | | | | | | | | | Summary: To enable this, TUScheduler has to provide a way to run async tasks without needing a preamble or AST! Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53644 llvm-svn: 345268
* [clangd] Namespace style cleanup in cpp files. NFC.Sam McCall2018-10-201-28/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Standardize on the most common namespace setup in our *.cpp files: using namespace llvm; namespace clang { namespace clangd { void foo(StringRef) { ... } And remove redundant llvm:: qualifiers. (Except for cases like make_unique where this causes problems with std:: and ADL). This choice is pretty arbitrary, but some broad consistency is nice. This is going to conflict with everything. Sorry :-/ Squash the other configurations: A) using namespace llvm; using namespace clang; using namespace clangd; void clangd::foo(StringRef); This is in some of the older files. (It prevents accidentally defining a new function instead of one in the header file, for what that's worth). B) namespace clang { namespace clangd { void foo(llvm::StringRef) { ... } This is fine, but in practice the using directive often gets added over time. C) namespace clang { namespace clangd { using namespace llvm; // inside the namespace This was pretty common, but is a bit misleading: name lookup preferrs clang::clangd::foo > clang::foo > llvm:: foo (no matter where the using directive is). llvm-svn: 344850
* [clangd] Some nitpicking around the new split (preamble/main) dynamic indexSam McCall2018-09-031-10/+10
| | | | | | | | | | | | | | | | | | | | | | Summary: - DynamicIndex doesn't implement ParsingCallbacks, to make its role clearer. ParsingCallbacks is a separate object owned by the receiving TUScheduler. (I tried to get rid of the "index-like-object that doesn't implement index" but it was too messy). - Clarified(?) docs around DynamicIndex - fewer details up front, more details inside. - Exposed dynamic index from ClangdServer for memory monitoring and more direct testing of its contents (actual tests not added here, wanted to get this out for review) - Removed a redundant and sligthly confusing filename param in a callback Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51221 llvm-svn: 341325
* [clangd] Run SignatureHelp using an up-to-date preamble, waiting if needed.Sam McCall2018-08-301-12/+73
| | | | | | | | | | | | | | Summary: After code completion inserts a header, running signature help using the old preamble will usually fail. So we add support for consistent preamble reads. Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51438 llvm-svn: 341076
* [clangd] Increase the timeouts in TUScheduler tests to 10 seconds.Ilya Biryukov2018-08-231-9/+9
| | | | | | | | Some of them timeout on our buildbots in certain configurations. The timeouts are there to avoid hanging indefinitely on deadlocks, so the exact number we put there does not matter. llvm-svn: 340523
* [clangd] Add callbacks on parsed AST in addition to parsed preamblesIlya Biryukov2018-08-221-14/+12
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Will be used for updating the dynamic index on updates to the open files. Currently we collect only information coming from the preamble AST. This has a bunch of limitations: - Dynamic index misses important information from the body of the file, e.g. locations of definitions. - XRefs cannot be collected at all, since we can only obtain full information for the current file (preamble is parsed with skipped function bodies, therefore not reliable). This patch only adds the new callback, actually updates to the index will be done in a follow-up patch. Reviewers: hokein Reviewed By: hokein Subscribers: kadircet, javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50847 llvm-svn: 340401
* [clangd] Add a testcase for empty preamble.Haojian Wu2018-08-171-0/+45
| | | | | | | | | | | | Summary: This is a patch of add a testcase for https://reviews.llvm.org/D50628. Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50627 llvm-svn: 340035
* [clangd] Record the file being processed in a TUScheduler thread in context.Eric Liu2018-08-091-14/+20
| | | | | | | | | | | | | | | | | Summary: 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. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50446 llvm-svn: 339320
* [clangd] Report diagnostics even if WantDiags::No AST was reusedIlya Biryukov2018-07-311-0/+34
| | | | | | | | | | | | | | | | Summary: After r338256, clangd stopped reporting diagnostics if WantDiags::No request is followed by a WantDiags::Yes request but the AST can be reused. Reviewers: ioeric Reviewed By: ioeric Subscribers: javed.absar, MaskRay, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50045 llvm-svn: 338361
* [clangd] Do not rebuild AST if inputs have not changedIlya Biryukov2018-07-261-5/+61
| | | | | | | | | | | | | | | | | Summary: If the contents are the same, the update most likely comes from the fact that compile commands were invalidated. In that case we want to avoid rebuilds in case the compile commands are actually the same. Reviewers: ioeric Reviewed By: ioeric Subscribers: simark, javed.absar, MaskRay, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D49783 llvm-svn: 338012
* [clangd] Fix racy use-after-scope in unittestBenjamin Kramer2018-07-201-2/+1
| | | | | | This only shows up with asan when the stars align in a bad way. llvm-svn: 337601
* [clangd] Wait for first preamble before code completionIlya Biryukov2018-07-091-0/+36
| | | | | | | | | | | | | | | | Summary: To avoid doing extra work of processing headers in the preamble mutilple times in parallel. Reviewers: sammccall Reviewed By: sammccall Subscribers: javed.absar, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48940 llvm-svn: 336538
* [clangd] Keep only a limited number of idle ASTs in memoryIlya Biryukov2018-06-011-16/+73
| | | | | | | | | | | | | | | | | | | | | | | Summary: After this commit, clangd will only keep the last 3 accessed ASTs in memory. Preambles for each of the opened files are still kept in memory to make completion and AST rebuilds fast. AST rebuilds are usually fast enough, but having the last ASTs in memory still considerably improves latency of operations like findDefinition and documeneHighlight, which are often sent multiple times a second when moving around the code. So keeping some of the last accessed ASTs in memory seems like a reasonable tradeoff. Reviewers: sammccall Reviewed By: sammccall Subscribers: malaperle, arphaman, klimek, javed.absar, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47063 llvm-svn: 333737
* [clangd] Build index on preamble changes instead of the AST changesIlya Biryukov2018-05-241-4/+4
| | | | | | | | | | | | | | | | | | | | | Summary: This is more efficient and avoids data races when reading files that come from the preamble. The staleness can occur when reading a file from disk that changed after the preamble was built. This can lead to crashes, e.g. when parsing comments. We do not to rely on symbols from the main file anyway, since any info that those provide can always be taken from the AST. Reviewers: ioeric, sammccall Reviewed By: ioeric Subscribers: malaperle, klimek, javed.absar, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47272 llvm-svn: 333196
* [clangd] Don't expose vfs in TUScheduler::runWithPreamble.Ilya Biryukov2018-03-141-2/+1
| | | | | | | | | | | | | | | | Summary: It was previously an easy way to concurrently access a mutable vfs, which is a recipe for disaster. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, jkorous-apple, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D44463 llvm-svn: 327537
* [clangd] Revamp handling of diagnostics.Ilya Biryukov2018-03-121-11/+11
| | | | | | | | | | | | | | | | Summary: The new implementation attaches notes to diagnostic message and shows the original diagnostics in the message of the note. Reviewers: hokein, ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, cfe-commits, jkorous-apple Differential Revision: https://reviews.llvm.org/D44142 llvm-svn: 327282
* [clangd] Use higher timoout values in TUSchedulerTest::DebounceIlya Biryukov2018-03-021-3/+4
| | | | | | Should unbreak windows buildbots. llvm-svn: 326598
* [clangd] Debounce streams of updates.Sam McCall2018-03-021-5/+31
| | | | | | | | | | | | | | | | | | | Summary: Don't actually start building ASTs for new revisions until either: - 500ms have passed since the last revision, or - we actually need the revision for something (or to unblock the queue) In practice, this avoids the "first keystroke results in diagnostics" problem. This is kind of awkward to test, and the test is pretty bad. It can be observed nicely by capturing a trace, though. Reviewers: hokein, ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D43648 llvm-svn: 326546
* [clangd] fix test use-after-free from r325774Sam McCall2018-02-221-4/+3
| | | | llvm-svn: 325801
* [clangd] Allow embedders some control over when diagnostics are generated.Sam McCall2018-02-221-2/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Through the C++ API, we support for a given snapshot version: - Yes: make sure we generate diagnostics for exactly this version - Auto: generate eventually-consistent diagnostics for at least this version - No: don't generate diagnostics for this version Eventually auto should be debounced for better UX. Through LSP, we force diagnostics for initial load (bypassing future debouncing) and all updates follow the "auto" policy. This is complicated to implement under the CancellationFlag design, so rewrote that part to just inspect the queue instead. It turns out we never pass None to the diagnostics callback, so remove Optional from the signature. The questionable behavior of not invoking the callback at all if CppFile::rebuild fails is not changed. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D43518 llvm-svn: 325774
* [clangd] Tracing: name worker threads, and enforce naming scheduled async tasksSam McCall2018-02-191-23/+28
| | | | | | | | | | | | | | | | | | | Summary: This has a bit of a blast radius, but I think there's enough value in "forcing" us to give names to these async tasks for debugging. Guessing about what multithreaded code is doing is so unfun... The "file" param attached to the tasks may seem to be redundant with the thread names, but note that thread names are truncated to 15 chars on linux! We'll be lucky to get the whole basename... Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D43388 llvm-svn: 325480
* [clangd] TestFS cleanup: getVirtualBlahBlah -> testPath/testRoot. Remove ↵Sam McCall2018-02-161-11/+8
| | | | | | SmallString micro-opt for more ergonomic tests. NFC llvm-svn: 325326
* Resubmit "[clangd] The new threading implementation"Ilya Biryukov2018-02-081-9/+5
| | | | | | | | | | | Initially submitted as r324356 and reverted in r324386. This change additionally contains a fix to crashes of the buildbots. The source of the crash was undefined behaviour caused by std::future<> whose std::promise<> was destroyed without calling set_value(). llvm-svn: 324575
* [clangd] Pass Context implicitly using TLS.Sam McCall2018-01-311-36/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Instead of passing Context explicitly around, we now have a thread-local Context object `Context::current()` which is an implicit argument to every function. Most manipulation of this should use the WithContextValue helper, which augments the current Context to add a single KV pair, and restores the old context on destruction. Advantages are: - less boilerplate in functions that just propagate contexts - reading most code doesn't require understanding context at all, and using context as values in fewer places still - fewer options to pass the "wrong" context when it changes within a scope (e.g. when using Span) - contexts pass through interfaces we can't modify, such as VFS - propagating contexts across threads was slightly tricky (e.g. copy vs move, no move-init in lambdas), and is now encapsulated in the threadpool Disadvantages are all the usual TLS stuff - hidden magic, and potential for higher memory usage on threads that don't use the context. (In practice, it's just one pointer) Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D42517 llvm-svn: 323872
* [clangd] Refactored threading in ClangdServerIlya Biryukov2018-01-311-0/+176
Summary: We now provide an abstraction of Scheduler that abstracts threading and resource management in ClangdServer. No changes to behavior are intended with an exception of changed error messages. This patch is preliminary work to allow a revamped threading implementation that will move the threading code out of CppFile. Reviewers: sammccall, bkramer, jkorous-apple Reviewed By: sammccall Subscribers: hokein, mgorny, hintonda, ioeric, jkorous-apple, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D42174 llvm-svn: 323851
OpenPOWER on IntegriCloud