summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clangd] Add line and column number to the index symbol.Haojian Wu2018-04-131-28/+50
| | | | | | | | | | | | | | | | | | Summary: LSP is using Line & column as symbol position, clangd needs to transfer file offset to Line & column when sending results back to LSP client, which is a high cost, especially for finding workspace symbol -- we have to read the file content from disk (if it isn't loaded in memory). Saving these information in the index will make the clangd life eaiser. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45513 llvm-svn: 329997
* s/LLVM_ON_WIN32/_WIN32/, clang-tools-extraNico Weber2018-04-101-2/+2
| | | | | | | | | | | LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the default macro instead of a reinvented one. See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev. No intended behavior change. llvm-svn: 329695
* [clangd] Adapt index interfaces to D45014, and fix the old bugs.Sam McCall2018-04-091-0/+2
| | | | | | | | | | | | | Summary: Fix bugs: - don't count occurrences of decls where we don't spell the name - findDefinitions at MACRO(^X) goes to the definition of MACRO Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45356 llvm-svn: 329571
* [clangd] Collect the number of files referencing a symbol in the static index.Sam McCall2018-03-121-1/+27
| | | | | | | | | | | | | | | Summary: This is an important ranking signal. It's off for the dynamic index for now. Correspondingly, tell the index infrastructure only to report declarations for the dynamic index. Reviewers: ioeric, hokein Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D44315 llvm-svn: 327275
* [clangd] Don't index template specializations.Sam McCall2018-03-091-0/+13
| | | | | | | | | | | | | | Summary: These have different USRs than the underlying entity, but are not typically interesting in their own right and can be numerous (e.g. generated traits). Reviewers: ioeric Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D44298 llvm-svn: 327127
* [clangd] Support include canonicalization in symbol leve.Eric Liu2018-03-011-0/+26
| | | | | | | | | | | | | | | | | Summary: Symbols with different canonical includes might be defined in the same header (e.g. symbols defined in STL <iosfwd>). This patch adds support for mapping from qualified symbol names to canonical headers and special mapping for symbols in <iosfwd> Reviewers: sammccall, hokein Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43869 llvm-svn: 326456
* [clangd] Prefer the definition of a TagDecl (e.g. class) as ↵Eric Liu2018-02-281-65/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CanonicalDeclaration. Summary: Currently, we pick the first declaration of a symbol in a TU, which is considered canonical in the clangIndex, as the canonical declaration in clangd. This causes forward declarations that might appear in a random header to be used as a canonical declaration, which is not desirable for features like go-to-declaration or include insertion. For example, for class X, we would consider the forward declaration in fwd.h to be the canonical declaration, while the preferred canonical declaration should be the actual definition in x.h. ``` // fwd.h class X; // forward decl // x.h class X {}; ``` This patch fixes the issue by making symbol collector favor the actual definition of a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen declarations in a TU. Other symbol types like functions are not handled because using the first seen declarations as canonical declarations is usually a good heuristic for them. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43823 llvm-svn: 326313
* Revert "[Tooling] [1/1] Refactor FrontendActionFactory::create() to return ↵Roman Lebedev2018-02-271-4/+3
| | | | | | | | | | | | std::unique_ptr<>" This reverts commit rL326202 This broke gcc4.8 builds, compiler just segfaults: http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/14909 http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/22673 llvm-svn: 326203
* [Tooling] [1/1] Refactor FrontendActionFactory::create() to return ↵Roman Lebedev2018-02-271-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | std::unique_ptr<> Summary: I'm not sure whether there are any principal reasons why it returns raw owning pointer, or it is just a old code that was not updated post-C++11. I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason, but it does not //appear// asif those failures are related to these changes. This is Clang-tools-extra part. Clang part is D43779. Reviewers: klimek, bkramer, alexfh, pcc Reviewed By: alexfh Subscribers: ioeric, jkorous-apple, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D43780 llvm-svn: 326202
* [clangd] Not collect include headers for dynamic index for now.Eric Liu2018-02-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The new behaviors introduced by this patch: o When include collection is enabled, we always set IncludeHeader field in Symbol even if it's the same as FileURI in decl. o Disable include collection in FileIndex which is currently only used to build dynamic index. We should revisit when we actually want to use FileIndex to global index. o Code-completion only uses IncludeHeader to insert headers but not FileURI in CanonicalDeclaration. This ensures that inserted headers are always canonicalized. Note that include insertion can still be triggered for symbols that are already included if they are merged from dynamic index and static index, but we would only use includes that are already canonicalized (e.g. from static index). Reason for change: Collecting header includes in dynamic index enables inserting includes for headers that are not indexed but opened in the editor. Comparing to inserting includes for symbols in global/static index, this is nice-to-have but would probably require non-trivial amount of work to get right. For example: o Currently it's not easy to fully support CanonicalIncludes in dynamic index, given the way we run dynamic index. o It's also harder to reason about the correctness of include canonicalization for dynamic index (i.e. symbols in the current file/TU) than static index where symbols are collected offline and sanity check is possible before shipping to production. o We have less control/flexibility over symbol info in the dynamic index (e.g. URIs, path normalization), which could be used to help make decision when inserting includes. As header collection (especially canonicalization) is relatively new, and enabling it for dynamic index would immediately affect current users with only dynamic index support, I propose we disable it for dynamic index for now to avoid compromising other hot features like code completion and only support it for static index where include insertion would likely to bring more value. Reviewers: ilya-biryukov, sammccall, hokein Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43550 llvm-svn: 325764
* [clangd] collect symbol #include & insert #include in global code completion.Eric Liu2018-02-161-9/+75
| | | | | | | | | | | | | | | | | | Summary: o Collect suitable #include paths for index symbols. This also does smart mapping for STL symbols and IWYU pragma (code borrowed from include-fixer). o For global code completion, add a command for inserting new #include in each code completion item. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, ilya-biryukov, jkorous-apple, hintonda, cfe-commits Differential Revision: https://reviews.llvm.org/D42640 llvm-svn: 325343
* [clangd] TestFS cleanup: getVirtualBlahBlah -> testPath/testRoot. Remove ↵Sam McCall2018-02-161-7/+6
| | | | | | SmallString micro-opt for more ergonomic tests. NFC llvm-svn: 325326
* [clangd] SymbolLocation only covers symbol name.Haojian Wu2018-02-131-20/+15
| | | | | | | | | | | | | | Summary: * Change the offset range to half-open, [start, end). * Fix a few fixmes. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D43182 llvm-svn: 324992
* [clangd] Collect definitions when indexing.Sam McCall2018-02-091-28/+67
| | | | | | | | | | | | | | | | | | | | | | | | | Within a TU: - as now, collect a declaration from the first occurrence of a symbol (taking clang's canonical declaration) - when we first see a definition occurrence, copy the symbol and add it Across TUs/sources: - mergeSymbol in Merge.h is responsible for combining matching Symbols. This covers dynamic/static merges and cross-TU merges in the static index. - it prefers declarations from Symbols that have a definition. - GlobalSymbolBuilderMain is modified to use mergeSymbol as a reduce step. Random cleanups (can be pulled out): - SymbolFromYAML -> SymbolsFromYAML, new singular SymbolFromYAML added - avoid uninit'd SymbolLocations. Add an idiomatic way to check "absent". - CanonicalDeclaration (as well as Definition) are mapped as optional in YAML. - added operator<< for Symbol & SymbolLocation, for debugging Reviewers: ioeric, hokein Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42942 llvm-svn: 324735
* [clangd] Use URIs in index symbols.Eric Liu2018-02-061-36/+79
| | | | | | | | | | | | Reviewers: hokein, sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42915 llvm-svn: 324358
* [clangd] Fix incorrect file path for symbols defined by the compile ↵Haojian Wu2018-02-061-2/+24
| | | | | | | | | | | | | | | | command-line option. Summary: Reviewers: ioeric Reviewed By: ioeric Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42913 llvm-svn: 324328
* [clangd] Fix ExternC test broken by r324081Sam McCall2018-02-021-2/+2
| | | | llvm-svn: 324105
* [clangd] Skip inline namespace when collecting scopes for index symbols.Eric Liu2018-02-021-2/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Some STL symbols are defined in inline namespaces. For example, ``` namespace std { inline namespace __cxx11 { typedef ... string; } } ``` Currently, this will be `std::__cxx11::string`; however, `std::string` is desired. Inline namespaces are treated as transparent scopes. This reflects the way they're most commonly used for lookup. Ideally we'd include them, but at query time it's hard to find all the inline namespaces to query: the preamble doesn't have a dedicated list. Reviewers: sammccall, hokein Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42796 llvm-svn: 324065
* [clangd] remove the unused code NFC.Haojian Wu2018-02-011-3/+0
| | | | llvm-svn: 323960
* [clangd] Better handling symbols defined in macros.Haojian Wu2018-01-311-7/+69
| | | | | | | | | | | | | | | | | | | Summary: For symbols defined inside macros: * use expansion location, if the symbol is formed via macro concatenation. * use spelling location, otherwise. This will fix some symbols that have ill-format location (especial invalid filepath). Reviewers: ioeric Reviewed By: ioeric Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42575 llvm-svn: 323867
* [clangd] Fix r323658 test failure on windows.Eric Liu2018-01-291-5/+7
| | | | llvm-svn: 323703
* [clangd] Add a fallback directory for collected symbols with relative paths.Eric Liu2018-01-291-12/+20
| | | | | | | | | | Reviewers: hokein, sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42638 llvm-svn: 323658
* [clangd] Change index scope convention from "outer::inner" to "outer::inner::"Sam McCall2018-01-191-5/+3
| | | | | | | | | | | | | | | | | | | Global scope is "" (was "") Top-level namespace scope is "ns::" (was "ns") Nested namespace scope is "ns::ns::" (was "ns::ns") This composes more naturally: - qname = scope + name - full scope = resolved scope + unresolved scope (D42073 was the trigger) It removes a wart from the old way: "foo::" has one more separator than "". Another alternative that has these properties is "::ns", but that lacks the property that both the scope and the name are substrings of the qname as produced by clang. This is re-landing r322996 which didn't build. llvm-svn: 323000
* Revert "[clangd] Change index scope convention from "outer::inner" to ↵Sam McCall2018-01-191-3/+5
| | | | | | | | "outer::inner::"" This reverts commit r322996. llvm-svn: 322998
* [clangd] Change index scope convention from "outer::inner" to "outer::inner::"Sam McCall2018-01-191-5/+3
| | | | | | | | | | | | | | | | | Global scope is "" (was "") Top-level namespace scope is "ns::" (was "ns") Nested namespace scope is "ns::ns::" (was "ns::ns") This composes more naturally: - qname = scope + name - full scope = resolved scope + unresolved scope (D42073 was the trigger) It removes a wart from the old way: "foo::" has one more separator than "". Another alternative that has these properties is "::ns", but that lacks the property that both the scope and the name are substrings of the qname as produced by clang. llvm-svn: 322996
* [clangd] Collect enum constants in SymbolCollectorHaojian Wu2018-01-191-0/+37
| | | | | | | | | | | | | | | | Summary: * ignore nameless symbols * include enum constant declarataion Reviewers: ilya-biryukov, jkorous-apple Reviewed By: ilya-biryukov Subscribers: ioeric, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D42074 llvm-svn: 322929
* [clangd] Add more filters for collected symbols.Eric Liu2018-01-101-9/+68
| | | | | | | | | | | | | | | | Summary: o We only collect symbols in namespace or translation unit scopes. o Add an option to only collect symbols in included headers. Reviewers: hokein, ilya-biryukov Reviewed By: hokein, ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41823 llvm-svn: 322193
* [clangd] Add more symbol information for code completion.Eric Liu2018-01-091-5/+60
| | | | | | | | | | | | Reviewers: hokein, sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41345 llvm-svn: 322097
* [clangd] Use ToolExecutor to write the global-symbol-builder tool.Eric Liu2018-01-091-1/+1
| | | | | | | | | | | | | | | Summary: This enables more execution modes like standalone and Mapreduce-style execution. See also D41729 Reviewers: hokein, sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41730 llvm-svn: 322084
* [clangd] Catch more symbols in SymbolCollector.Haojian Wu2018-01-091-2/+40
| | | | | | | | | | | | | | | | | | Summary: We currently only collect external-linkage symbols in the collector, which results in missing some typical symbols (like no-linkage type alias symbols). This patch relaxes the constraint a bit to allow collecting more symbols. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41759 llvm-svn: 322067
* [clangd] Use Builder for symbol slabs, and use sorted-vector for storageSam McCall2017-12-231-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This improves a few things: - the insert -> freeze -> read sequence is now enforced/communicated by the type system - SymbolSlab::const_iterator iterates over symbols, not over id-symbol pairs - we avoid permanently storing a second copy of the IDs, and the string map's hashtable The slab size is now down to 21.8MB for the LLVM project. Of this only 2.7MB is strings, the rest is #symbols * `sizeof(Symbol)`. `sizeof(Symbol)` is currently 96, which seems too big - I think SymbolInfo isn't efficiently packed. That's a topic for another patch! Also added simple API to see the memory usage/#symbols of a slab, since it seems likely we will continue to care about this. Reviewers: ilya-biryukov Subscribers: klimek, mgrang, cfe-commits Differential Revision: https://reviews.llvm.org/D41506 llvm-svn: 321412
* [clangd] Index symbols share storage within a slab.Sam McCall2017-12-211-1/+1
| | | | | | | | | | | | | | | | | Summary: Symbols are not self-contained - it's only safe to hand them out if you guarantee the lifetime of the underlying data. Before this lands, I'm going to measure the before/after memory usage of the LLVM index loaded into memory in a single slab. Reviewers: hokein Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41483 llvm-svn: 321272
* [clangd] Support filtering by fixing scopes in fuzzyFind.Eric Liu2017-12-191-3/+8
| | | | | | | | | | | | | | 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] 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] clang-format the source code. NFCIlya Biryukov2017-12-131-4/+4
| | | | llvm-svn: 320577
* [clangd] Introduce a "Symbol" class.Haojian Wu2017-12-121-0/+110
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
OpenPOWER on IntegriCloud