summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/AST.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Don't assert when completing a lambda variable inside the lambda.Sam McCall2020-06-101-0/+7
| | | | | | | | | | | | | | | | | | | Summary: This is a fairly ugly hack - we back off several features for any variable whose type isn't deduced, to avoid computing/caching linkage. Better suggestions welcome. Fixes https://github.com/clangd/clangd/issues/274 Reviewers: kadircet, kbobyrev Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73960 (cherry picked from commit 2629035a009095f62f48413e175437261165ecd7)
* [clangd] Replace shortenNamespace with getQualificationKadir Cetinkaya2020-01-031-27/+18
| | | | | | | | | | Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71652
* [clangd] Fix handling of inline/anon namespaces and names of deduced types ↵Kadir Cetinkaya2019-12-171-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | in hover Summary: Clangd normally skips inline and anon namespaces while printing nested name specifiers. It also drops any tag specifiers since we make use of `HoverInfo::Kind` instead of some text in `HoverInfo::Name` There was a bug causing us to print innermost inline/anon namespace, this patch fixes that by skipping those. Also changes printing and kind detection of deduced types to be similar to decl case. Also improves printing for lambdas, currently clangd prints lambdas as `(anonymous class)`, we can improve it by at least printing `(lambda)` instead. Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71543
* [NFC] Fix typos in Clangd and ClangKirill Bobyrev2019-12-161-1/+1
| | | | | | Reviewed by: Jim Differential Revision: https://reviews.llvm.org/D71455
* [clangd] Simplify code using findName. NFCIlya Biryukov2019-12-101-1/+6
| | | | | | | | | | | | | `findName` was always used in conjuction with `spellingLocIfSpelled`. This patch replaces patterns of the form: spellingLocIfSpelled(findName(&ND), SM) With a new helper function: nameLocation(ND, SM) And removes `spellingLocIfSpelled` and `findName`. Both are never used anywhere else and the latter is an equivalent of `Decl::getLocation` if we ever need it again.
* Fix an unused variable warning where a variable was only used in an assert.Eric Christopher2019-11-251-1/+3
|
* [clangd] Helper for getting nested namespace qualificationKadir Cetinkaya2019-11-251-8/+115
| | | | | | | | | | | | | | | | | Summary: Introduce a new helper for getting minimally required qualifiers necessary to spell a name at a point in a given DeclContext. Currently takes using directives and nested namespecifier of DeclContext itself into account. Initially will be used in define inline and outline actions. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69608
* [clangd] Untangle Hover from XRefs, move into own file.Sam McCall2019-11-191-0/+111
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This is mostly mechanical, with a few exceptions: - getDeducedType moved into AST.h where it belongs. It now takes ASTContext instead of ParsedAST, and avoids using the preprocessor. - hover now uses SelectionTree directly rather than via getDeclAtPosition helper - hover on 'auto' used to find the decl that contained the 'auto' and use that to set Kind and documentation for the hover result. Now we use targetDecl() to find the decl matching the deduced type instead. This changes tests, e.g. 'variable' -> class for auto on lambdas. I think this is better, but the motivation was to avoid depending on the internals of DeducedTypeVisitor. This functionality is removed from the visitor. Reviewers: kadircet Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70357
* [clangd] More sensible output for constructors/destructors in hover.Sam McCall2019-11-191-0/+6
| | | | | | | | | | | | | | Summary: Previously: both had type void() and return type void. Now: neither have a type. Constructors return T, destructors return void. Reviewers: hokein Subscribers: merge_guards_bot, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70317
* [clangd] Don't consider class template params part of constructor name.Sam McCall2019-11-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This is shorter and usually the extra info is noise. There are cases where the params become type-parameter-0-0 that are hard to fix. This affects a few features: - 'name' field in structured hover API (not exposed yet) - 'name' field in locateSymbolAt (not exposed in LSP) - 'document/symbol' - the symbol is hierarchically nested in the class template, or written as foo<t>::foo when defined out-of-line. Added a test case for hover from https://github.com/clangd/clangd/issues/76. This patch fixes one field, but no fewer than four others are wrong! I'll fix them... Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70308
* [clangd] Use name of Macro to compute its SymbolID, NFC.Utkarsh Saxena2019-11-111-2/+2
| | | | | | | | | | | | | | | | | | | Summary: We use the name from the IdentifierInfo of the Macro to compute its SymbolID. It is better to just take the Name as a parameter to avoid storing the IdentifierInfo whenever we need the SymbolID for the Macro. Patch by UTKARSH SAXENA! Reviewers: hokein Reviewed By: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69937
* [clangd] Report declaration references in findExplicitReferences.Haojian Wu2019-10-181-9/+5
| | | | | | | | | | | | Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68977 llvm-svn: 375226
* [clangd] Add RemoveUsingNamespace tweak.Utkarsh Saxena2019-10-161-0/+12
| | | | | | | | | | | | | | | | | | Summary: Removes the 'using namespace' under the cursor and qualifies all accesses in the current file. E.g.: using namespace std; vector<int> foo(std::map<int, int>); Would become: std::vector<int> foo(std::map<int, int>); Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68562 llvm-svn: 374982
* [clangd] Print qualifiers of out-of-line definitions in document outlineIlya Biryukov2019-08-141-12/+40
| | | | | | | | | | | | | | | | Summary: To improve the UX around navigating and searching through the results. Reviewers: hokein Reviewed By: hokein Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66215 llvm-svn: 368842
* [clangd] Fixed printTemplateSpecializationArgs not printing partial variable ↵Johan Vikstrom2019-08-091-0/+4
| | | | | | | | | | | | | | | | | | specialization arguments. Summary: printTemplateSpecializationArgs was not printing partial variable specialization args. This adds an additional If clause where we check if it's a VariableTemplatePartialSpecializationDecl and returns the ArgumentLocs if that's the case. Also adds tests for printTemplateSpecializationArgs in ASTTests.cpp. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65926 llvm-svn: 368403
* [clangd] Remove a function accidently being added in rL368261.Haojian Wu2019-08-081-20/+0
| | | | llvm-svn: 368282
* [clangd] Fix implicit template instatiations appearing as topLevelDecls.Johan Vikstrom2019-08-081-0/+45
| | | | | | | | | | | | | | Summary: The parser gives implicit template instantiations to the action's HandleTopLevelDecls callback. This makes semantic highlighting highlight these templated functions multiple times. Fixed by filtering on if a Decl is an implicit function/variable/class instantiation. Also added a testcase to semantic highlighting on this. Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65510 llvm-svn: 368261
* [clangd] Unfold SourceLocation flattening from findNameLoc in preparation ↵Sam McCall2019-08-061-26/+6
| | | | | | for adding more overloads. NFC llvm-svn: 368083
* [clangd] Suppress unwritten scopes when expanding auto.Haojian Wu2019-07-181-0/+1
| | | | | | | | | | | | | | Summary: otherwise the replacement will break the code. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64627 llvm-svn: 366446
* [clangd] Fix MSVC build failure.Paul Robinson2019-07-111-1/+1
| | | | | | http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26898 llvm-svn: 365844
* [clangd] Implementation of auto type expansion.Sam McCall2019-07-111-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a tweak for clangd to replace an auto keyword to the deduced type. This way a user can declare something with auto and then have the IDE/clangd replace auto with whatever type clangd thinks it is. In case of long/complext types this makes is reduces writing effort for the user. The functionality is similar to the hover over the auto keyword. Example (from the header): ``` /// Before: /// auto x = Something(); /// ^^^^ /// After: /// MyClass x = Something(); /// ^^^^^^^ ``` Patch by kuhnel! (Christian Kühnel) Differential Revision: https://reviews.llvm.org/D62855 llvm-svn: 365792
* [clangd] Print template arguments helperKadir Cetinkaya2019-04-121-14/+52
| | | | | | | | | | | | | | | | Summary: Prepares ground for printing template arguments as written in the source code, part of re-landing rC356541 with D59599 applied. Reviewers: ioeric, ilya-biryukov Subscribers: mgorny, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59639 llvm-svn: 358272
* Revert "[clangd] Print arguments in template specializations"Jordan Rupprecht2019-03-201-32/+0
| | | | | | This reverts commit 44a63f6a150dec72dea43730d2a89d292e58bd6f. It segfaults on an internal test case (will follow up off thread). llvm-svn: 356623
* [clangd] Print arguments in template specializationsKadir Cetinkaya2019-03-201-0/+32
| | | | | | | | | | | | Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59354 llvm-svn: 356541
* 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-9/+9
| | | | | | | | 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-1/+1
| | | | llvm-svn: 350303
* [clangd] Dont provide locations for non-existent files.Kadir Cetinkaya2018-12-051-4/+7
| | | | | | | | | | | | | | Summary: We were getting assertion errors when we had bad file names, instead we should skip those. Reviewers: hokein Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D55275 llvm-svn: 348359
* [clangd] NFC: Prefer `isa<>` to `dyn_cast<>` to do the checking.Henry Wong2018-11-271-2/+2
| | | | | | | | | | | | | | Summary: Prefer `isa<>` to `dyn_cast<>` when there only need a checking. Reviewers: ilya-biryukov, MaskRay Reviewed By: ilya-biryukov, MaskRay Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits, MTC Differential Revision: https://reviews.llvm.org/D54878 llvm-svn: 347635
* [clangd] Cleanup after landing documentSymbol. NFCIlya Biryukov2018-11-261-2/+2
| | | | | | | | - fix compile error on older gcc in Protocol.cpp, - remove redundant 'llvm::' qualifiers from Protocol.cpp, - remove unused variables in AST.cpp llvm-svn: 347539
* [clangd] Add support for hierarchical documentSymbolIlya Biryukov2018-11-231-0/+43
| | | | | | | | | | | | Reviewers: ioeric, sammccall, simark Reviewed By: sammccall Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52311 llvm-svn: 347498
* [clangd] Make TestTU build with preamble, and fix the fallout.Sam McCall2018-11-091-7/+4
| | | | | | | | | | | | | | | | | | | | Our testing didn't reflect reality: live clangd almost always uses a preamble, and sometimes the preamble behaves differently. This patch fixes a common test helper to be more realistic. Preamble doesn't preserve information about which tokens come from the command-line (this gets inlined into a source file). So remove logic that attempts to treat symbols with such names differently. A SymbolCollectorTest tries to verify that locals in headers are not indexed, with preamble enabled this is only meaningful for locals of auto-typed functions (otherwise the bodies aren't parsed). Tests were relying on the fact that the findAnyDecl helper actually did expose symbols from headers. Resolve by making all these functions consistently able to find symbols in headers/preambles. llvm-svn: 346488
* [clangd] Namespace style cleanup in cpp files. NFC.Sam McCall2018-10-201-10/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Names that are not spelled in source code are reserved.Eric Liu2018-10-181-15/+25
| | | | | | | | | | | | | | | | | | | | | | | | Summary: These are often not expected to be used directly e.g. ``` TEST_F(Fixture, X) { ^ // "Fixture_X_Test" expanded in the macro should be down ranked. } ``` Only doing this for sema for now, as such symbols are mostly coming from sema e.g. gtest macros expanded in the main file. We could also add a similar field for the index symbol. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53374 llvm-svn: 344736
* [clangd] Support scope proximity in code completion.Eric Liu2018-10-171-0/+8
| | | | | | | | | | | | | | | | Summary: This should make all-scope completion more usable. Scope proximity for indexes will be added in followup patch. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53131 llvm-svn: 344688
* [clangd] Set SymbolID for sema macros so that they can be merged with index ↵Eric Liu2018-09-061-0/+11
| | | | | | | | | | | | macros. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51688 llvm-svn: 341534
* [clangd] Share getSymbolID implementation.Haojian Wu2018-08-071-0/+8
| | | | | | | | | | | | Summary: And remove all duplicated implementation. Reviewers: ioeric Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50375 llvm-svn: 339116
* [clangd] Expose qualified symbol names in CompletionItem (C++ structure ↵Eric Liu2018-06-221-0/+15
| | | | | | | | | | | | | | | | | | | | only, no json). Summary: The qualified name can be used to match a completion item to its corresponding symbol. This can be useful for tools that measure code completion quality. Qualified names are not precise for identifying symbols; we need to figure out a better way to identify completion items. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48425 llvm-svn: 335334
* Fix up after clang r331155.Richard Smith2018-04-301-1/+1
| | | | llvm-svn: 331156
* [clangd] Use identifier range as the definition range.Haojian Wu2018-03-091-0/+42
Summary: This also matches the range in symbol index. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44247 llvm-svn: 327129
OpenPOWER on IntegriCloud