summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests
Commit message (Collapse)AuthorAgeFilesLines
...
* [clangd] Build dynamic index and use it for code completion.Eric Liu2017-12-191-0/+32
| | | | | | | | | | | | Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41289 llvm-svn: 321092
* [clangd] Fix warnings/compiler pickiness after r321083Sam McCall2017-12-191-1/+1
| | | | llvm-svn: 321086
* [clangd] Index-based code completion.Eric Liu2017-12-192-5/+105
| | | | | | | | | | | | | | Summary: Use symbol index to populate completion results for qualfified IDs e.g. "nx::A^". Reviewers: ilya-biryukov, sammccall Reviewed By: ilya-biryukov, sammccall Subscribers: rwols, klimek, mgorny, cfe-commits, sammccall Differential Revision: https://reviews.llvm.org/D41281 llvm-svn: 321083
* [clangd] Expose offset <-> LSP position functions, and fix bugsSam McCall2017-12-193-0/+78
| | | | | | | | | | | | | | | | | | | | | | | Summary: - Moved these functions to SourceCode.h - added unit tests - fix off by one in positionToOffset: Offset - 1 in final calculation was wrong - fixed formatOnType which had an equal and opposite off-by-one - positionToOffset and offsetToPosition both consistently clamp to beginning/end of file when input is out of range - gave variables more descriptive names - removed windows line ending fixmes where there is nothing to fix - elaborated on UTF-8 fixmes This will conflict with Eric's D41281, but in a pretty easy-to-resolve way. Reviewers: ioeric Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41351 llvm-svn: 321073
* [clangd] Support filtering by fixing scopes in fuzzyFind.Eric Liu2017-12-193-25/+102
| | | | | | | | | | | | | | Summary: When scopes are specified, only match symbols from scopes. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41367 llvm-svn: 321067
* [clangd] Add unit tests for signature help. SigHelp/CodeComplete lit tests ↵Sam McCall2017-12-191-1/+89
| | | | | | are smoke only. llvm-svn: 321065
* [clangd] Build in-memory index on symbols in files.Eric Liu2017-12-153-92/+194
| | | | | | | | | | | | Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41276 llvm-svn: 320807
* [clangd] Implemented tracing using ContextIlya Biryukov2017-12-141-3/+5
| | | | | | | | | | | | Reviewers: sammccall, ioeric, hokein Reviewed By: sammccall Subscribers: klimek, luckygeck, cfe-commits Differential Revision: https://reviews.llvm.org/D40488 llvm-svn: 320706
* [clangd] Add a FileSymbols container that manages symbols from multiple files.Eric Liu2017-12-142-0/+92
| | | | | | | | | | | | Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41232 llvm-svn: 320701
* [clangd] Fix a potential use-after-move bug.Eric Liu2017-12-141-1/+2
| | | | llvm-svn: 320695
* [clangd] Construct SymbolSlab from YAML format.Haojian Wu2017-12-141-0/+45
| | | | | | | | | | | | | | Summary: This will be used together with D40548 for the global index source (experimental). Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D41178 llvm-svn: 320694
* [clangd] Symbol index interfaces and an in-memory index implementation.Eric Liu2017-12-142-0/+115
| | | | | | | | | | | | | | | | | | | | Summary: o Index interfaces to support using different index sources (e.g. AST index, global index) for code completion, cross-reference finding etc. This patch focuses on code completion. The following changes in the original patch has been split out. o Implement an AST-based index. o Add an option to replace sema code completion for qualified-id with index-based completion. o Implement an initial naive code completion index which matches symbols that have the query string as substring. Reviewers: malaperle, sammccall Reviewed By: sammccall Subscribers: hokein, klimek, malaperle, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40548 llvm-svn: 320688
* [clangd] Fix the unitttest build error on buildbot.Haojian Wu2017-12-141-0/+1
| | | | llvm-svn: 320678
* [clangd] clang-format the source code. NFCIlya Biryukov2017-12-132-5/+5
| | | | llvm-svn: 320577
* [clangd] Implemented logging using ContextIlya Biryukov2017-12-132-69/+72
| | | | | | | | | | | | Reviewers: sammccall, ioeric, hokein Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D40486 llvm-svn: 320576
* [clangd] Introduce a "Symbol" class.Haojian Wu2017-12-122-0/+111
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: * The "Symbol" class represents a C++ symbol in the codebase, containing all the information of a C++ symbol needed by clangd. clangd will use it in clangd's AST/dynamic index and global/static index (code completion and code navigation). * The SymbolCollector (another IndexAction) will be used to recollect the symbols when the source file is changed (for ASTIndex), or to generate all C++ symbols for the whole project. In the long term (when index-while-building is ready), clangd should share a same "Symbol" structure and IndexAction with index-while-building, but for now we want to have some stuff working in clangd. Reviewers: ioeric, sammccall, ilya-biryukov, malaperle Reviewed By: sammccall Subscribers: malaperle, klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D40897 llvm-svn: 320486
* [clangd] clang-format the code. NFCIlya Biryukov2017-12-121-2/+3
| | | | llvm-svn: 320476
* [clangd] Introduced a Context that stores implicit dataIlya Biryukov2017-12-122-0/+58
| | | | | | | | | | | | | | | | Summary: It will be used to pass around things like Logger and Tracer throughout clangd classes. Reviewers: sammccall, ioeric, hokein, bkramer Reviewed By: sammccall Subscribers: klimek, bkramer, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D40485 llvm-svn: 320468
* [clangd] Convert lit code completion tests to unit-tests. NFCSam McCall2017-12-082-66/+278
| | | | | | | | | | | | Summary: This improves readability of tests and error messages. Reviewers: ioeric Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40952 llvm-svn: 320148
* [change-namespace] Fix crash when injected base-class name is used in friend ↵Eric Liu2017-12-081-0/+54
| | | | | | | | | | | | declarations. Reviewers: hokein Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41001 llvm-svn: 320139
* [CMake] Use PRIVATE in target_link_libraries for executablesShoaib Meenai2017-12-058-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We currently use target_link_libraries without an explicit scope specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables. Dependencies added in this way apply to both the target and its dependencies, i.e. they become part of the executable's link interface and are transitive. Transitive dependencies generally don't make sense for executables, since you wouldn't normally be linking against an executable. This also causes issues for generating install export files when using LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM library dependencies, which are currently added as interface dependencies. If clang is in the distribution components but the LLVM libraries it depends on aren't (which is a perfectly legitimate use case if the LLVM libraries are being built static and there are therefore no run-time dependencies on them), CMake will complain about the LLVM libraries not being in export set when attempting to generate the install export file for clang. This is reasonable behavior on CMake's part, and the right thing is for LLVM's build system to explicitly use PRIVATE dependencies for executables. Unfortunately, CMake doesn't allow you to mix and match the keyword and non-keyword target_link_libraries signatures for a single target; i.e., if a single call to target_link_libraries for a particular target uses one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must also be updated to use those keywords. This means we must do this change in a single shot. I also fully expect to have missed some instances; I tested by enabling all the projects in the monorepo (except dragonegg), and configuring both with and without shared libraries, on both Darwin and Linux, but I'm planning to rely on the buildbots for other configurations (since it should be pretty easy to fix those). Even after this change, we still have a lot of target_link_libraries calls that don't specify a scope keyword, mostly for shared libraries. I'm thinking about addressing those in a follow-up, but that's a separate change IMO. Differential Revision: https://reviews.llvm.org/D40823 llvm-svn: 319840
* [clangd] Clean up code complete unit tests. NFCSam McCall2017-12-051-282/+151
| | | | llvm-svn: 319820
* [clangd] Set completion options per-request.Ilya Biryukov2017-12-052-26/+28
| | | | | | | | | | | | | | | | | | | | Summary: Previously, completion options were set per ClangdServer instance. It will allow to change completion preferences during the lifetime of a single ClangdServer instance. Also rewrote ClangdCompletionTest.CompletionOptions to reuse single ClangdServer instance, the test now runs 2x faster on my machine. Reviewers: sammccall, ioeric, hokein Reviewed By: sammccall, ioeric Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D40654 llvm-svn: 319753
* [clangd] Remove unused test param. NFCSam McCall2017-12-054-19/+17
| | | | llvm-svn: 319742
* [clangd] Split code-completion tests out of ClangdTests. NFC.Sam McCall2017-12-055-552/+636
| | | | | | | | | | | | | | Summary: Common parts are mostly FS related, so pulled out TestFS.h for the common stuff. Deliberately resisted cleaning up much here, so this is pretty mechanical. Reviewers: hokein Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40784 llvm-svn: 319741
* [clangd] GlobalCompilationDatabase interface changesSam McCall2017-12-041-11/+7
| | | | | | | | | | | | | | | | | | Summary: - GlobalCompilationDatabase now returns a single command (that's all we use) - fallback flags are now part of the GlobalCompilationDatabase. There's a default implementation that they can optionally customize. - this allows us to avoid invoking the fallback logic on two separate codepaths - race on extra flags fixed by locking the mutex - made GCD const-correct (DBGCD does have mutating methods) Reviewers: hokein Subscribers: klimek, cfe-commits, ilya-biryukov Differential Revision: https://reviews.llvm.org/D40733 llvm-svn: 319647
* [clangd] Fuzzy match scorerSam McCall2017-12-012-0/+253
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This will be used for rescoring code completion results based on partial identifiers. Short-term use: - we want to limit the number of code completion results returned to improve performance of global completion. The scorer will be used to rerank the results to return when the user has applied a filter. Long-term use case: - ranking of completion results from in-memory index - merging of completion results from multiple sources (merging usually works best when done at the component-score level, rescoring the fuzzy-match quality avoids different backends needing to have comparable scores) Reviewers: ilya-biryukov Subscribers: cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D40060 llvm-svn: 319557
* [clangd] Filter completion results by fuzzy-matching identifiers.Sam McCall2017-12-011-0/+55
| | | | | | | | | | | | | | | | | | Summary: This allows us to limit the number of results we return and still allow them to be surfaced by refining a query (D39852). The initial algorithm is very conservative - it accepts a completion if the filter is any case-insensitive sub-sequence. It does not attempt to rank items based on match quality. Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39882 llvm-svn: 319552
* [clangd] New conventions for JSON-marshalling functions, centralize machinerySam McCall2017-11-301-0/+58
| | | | | | | | | | | | | | | | | | Summary: - JSON<->Obj interface is now ADL functions, so they play nicely with enums - recursive vector/map parsing and ObjectMapper moved to JSONExpr and tested - renamed (un)parse to (de)serialize, since text -> JSON is called parse - Protocol.cpp gets a bit shorter Sorry for the giant patch, it's prety mechanical though Reviewers: ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D40596 llvm-svn: 319478
* [clangd] Switch from YAMLParser to JSONExprSam McCall2017-11-281-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: - Converted Protocol.h parse() functions to take JSON::Expr. These no longer detect and log unknown fields, as this is not that useful and no longer free. I haven't changed the error handling too much: fields that were treated as optional before are still optional, even when it's wrong. Exception: object properties with the wrong type are now ignored. - Made JSONRPCDispatcher parse using json::parse - The bug where 'method' must come before 'params' in the stream is fixed as a side-effect. (And the same bug in executeCommand). - Some parser crashers fixed as a side effect. e.g. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3890 - The debug stream now prettyprints the input messages with --pretty. - Request params are attached to traces when tracing is enabled. - Fixed some bugs in tests (errors tolerated by YAMLParser, and off-by-ones in Content-Length that our null-termination was masking) - Fixed a random double-escape bug in ClangdLSPServer (it was our last use of YAMLParser!) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40406 llvm-svn: 319159
* [clangd] Add missing (but documented!) JSONExpr typed accessorsSam McCall2017-11-281-1/+43
| | | | | | | | | | | | | | Summary: Noticed this when I tried to port the Protocol.h parsers. And tests for the inspect API, which caught a small bug. Reviewers: ioeric Subscribers: ilya-biryukov Differential Revision: https://reviews.llvm.org/D40399 llvm-svn: 319157
* [clangd] Tracing improvementsSam McCall2017-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | Summary: [clangd] Tracing improvements Compose JSON using JSONExpr Allow attaching metadata to spans (and avoid it if tracing is off) Attach IDs and responses of JSON RPCs to their spans The downside is that large responses make the trace viewer sluggish. We should make our responses less huge :-) Or fix trace viewer. Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40132 llvm-svn: 318928
* [clang-tidy] rename_check.py misc-argument-comment bugprone-argument-commentAlexander Kornienko2017-11-232-41/+0
| | | | | | | | | | | | | | Summary: + manually convert the unit test to lit test. Reviewers: hokein Reviewed By: hokein Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40392 llvm-svn: 318926
* [clangd] Drop impossible completions (unavailable or inaccessible)Sam McCall2017-11-231-10/+23
| | | | | | | | | | | | Summary: (There must be some reason why D38077 didn't just do this, but I don't get it!) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39836 llvm-svn: 318925
* [clangd] avoid divide by literal zero to satisfy msvcSam McCall2017-11-211-1/+1
| | | | llvm-svn: 318798
* [clangd] use u8 strings in tests to avoid problems on windowsSam McCall2017-11-211-4/+4
| | | | llvm-svn: 318793
* [clangd] Add JSON tests with invalid unicodeSam McCall2017-11-211-1/+4
| | | | llvm-svn: 318791
* [clangd] Add parsing and value inspection to JSONExpr.Sam McCall2017-11-211-0/+74
| | | | | | | | | | | | | | | | | | | | | Summary: This will replace the places where we're using YAMLParser to parse JSON now: - the new marshalling code (T::parse()) should handle fewer cases and require fewer explicit casts - we'll early-reject invalid JSON that YAMLParser accepts - we'll be able to fix protocol-parsing bugs caused by the fact that YAML can only parse forward I plan to do the conversion as soon as this lands, but I don't want it in one patch as the protocol.cpp changes are conflict-prone. Reviewers: ioeric Subscribers: ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D40182 llvm-svn: 318774
* [clangd] Use in-memory preambles in clangd.Ilya Biryukov2017-11-161-6/+21
| | | | | | | | | | | | Reviewers: klimek, bkramer, sammccall Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39843 llvm-svn: 318412
* [clangd] clang-format the source code. NFC.Ilya Biryukov2017-11-151-14/+12
| | | | llvm-svn: 318317
* [clangd] Support returning a limited number of completion results.Sam McCall2017-11-151-4/+41
| | | | | | | | | | | | | | | | | | | | Summary: All results are scored, we only process CodeCompletionStrings for the winners. We now return CompletionList rather than CompletionItem[] (both are valid). sortText is now based on CodeCompletionResult::orderedName (mostly the same). This is the first clangd-only completion option, so plumbing changed. It requires a small clangd patch (exposing CodeCompletionResult::orderedName). (This can't usefully be enabled yet: we don't support server-side filtering) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39852 llvm-svn: 318287
* Fix compile issue on MSVC.Douglas Yung2017-11-081-3/+5
| | | | llvm-svn: 317642
* [clangd] MSVC - third time's the charmSam McCall2017-11-071-1/+1
| | | | llvm-svn: 317581
* [clangd] another try at fixing MSVCSam McCall2017-11-071-1/+1
| | | | llvm-svn: 317575
* ClangdTests/JSONExprTests.cpp: Appease g++-4.8 to move raw string literal ↵NAKAMURA Takumi2017-11-071-3/+5
| | | | | | out of macro arg. llvm-svn: 317538
* Adds a json::Expr type to represent intermediate JSON expressions.Sam McCall2017-11-062-0/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This form can be created with a nice clang-format-friendly literal syntax, and gets escaping right. It knows how to call unparse() on our Protocol types. All the places where we pass around JSON internally now use this type. Object properties are sorted (stored as std::map) and so serialization is canonicalized, with optional prettyprinting (triggered by a -pretty flag). This makes the lit tests much nicer to read and somewhat nicer to debug. (Unfortunately the completion tests use CHECK-DAG, which only has line-granularity, so pretty-printing is disabled there. In future we could make completion ordering deterministic, or switch to unittests). Compared to the current approach, it has some efficiencies like avoiding copies of string literals used as object keys, but is probably slower overall. I think the code/test quality benefits are worth it. This patch doesn't attempt to do anything about JSON *parsing*. It takes direction from the proposal in this doc[1], but is limited in scope and visibility, for now. I am of half a mind just to use Expr as the target of a parser, and maybe do a little string deduplication, but not bother with clever memory allocation. That would be simple, and fast enough for clangd... [1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit +cc d0k so he can tell me not to use std::map. Reviewers: ioeric, malaperle Subscribers: bkramer, ilya-biryukov, mgorny, klimek Differential Revision: https://reviews.llvm.org/D39435 llvm-svn: 317486
* Fix clangd test on platforms where get_thread_name does nothing.Sam McCall2017-11-021-2/+10
| | | | llvm-svn: 317194
* Performance tracing facility for clangd.Sam McCall2017-11-022-0/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This lets you visualize clangd's activity on different threads over time, and understand critical paths of requests and object lifetimes. The data produced can be visualized in Chrome (at chrome://tracing), or in a standalone copy of catapult (http://github.com/catapult-project/catapult) This patch consists of: - a command line flag "-trace" that causes clangd to emit JSON trace data - an API (in Trace.h) allowing clangd code to easily add events to the stream - several initial uses of this API to capture JSON-RPC requests, builds, logs Example result: https://photos.app.goo.gl/12L9swaz5REGQ1rm1 Caveats: - JSON serialization is ad-hoc (isn't it everywhere?) so the API is limited to naming events rather than attaching arbitrary metadata. I'd like to fix this (I think we could use a JSON-object abstraction). - The recording is very naive: events are written immediately by locking a mutex. Contention on the mutex might disturb performance. - For now it just traces instants or spans on the current thread. There are other things that make sense to show (cross-thread flows, non-thread resources such as ASTs). But we have to start somewhere. Reviewers: ioeric, ilya-biryukov Subscribers: cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D39086 llvm-svn: 317193
* [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassingHaojian Wu2017-10-271-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is part 3 of 3 of a series of changes to improve Objective-C linting in clang-tidy. This adds a new clang-tidy check `objc-forbidden-subclassing` which ensures clients do not create subclasses of Objective-C classes which are not designed to be subclassed. (Note that for code under your control, you should use __attribute__((objc_subclassing_restricted)) instead -- this is intended for third-party APIs which cannot be modified.) By default, the following classes (which are publicly documented as not supporting subclassing) are forbidden from subclassing: ABNewPersonViewController ABPeoplePickerNavigationController ABPersonViewController ABUnknownPersonViewController NSHashTable NSMapTable NSPointerArray NSPointerFunctions NSTimer UIActionSheet UIAlertView UIImagePickerController UITextInputMode UIWebView Clients can set a CheckOption `objc-forbidden-subclassing.ClassNames` to a semicolon-separated list of class names, which overrides this list. Test Plan: `ninja check-clang-tools` Patch by Ben Hamilton! Reviewers: hokein, alexfh Reviewed By: hokein Subscribers: saidinwot, Wizard, srhines, mgorny, xazax.hun Differential Revision: https://reviews.llvm.org/D39142 llvm-svn: 316744
* [clangd] Report an error on findDefinitions/signatureHelp on an unopened ↵Benjamin Kramer2017-10-261-1/+1
| | | | | | | | file instead of crashing. Found by clangd-fuzzer. llvm-svn: 316659
OpenPOWER on IntegriCloud