summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/XRefs.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Publish xref for macros from Index and AST.Utkarsh Saxena2020-01-131-39/+60
| | | | | | | | | | | | | | | | | | | Summary: With this patch the `findReferences` API will return Xref for macros. If the symbol under the cursor is a macro then we collect the references to it from: 1. Main file by looking at the ParsedAST. (These were added to the ParsedAST in https://reviews.llvm.org/D70008) 2. Files other than the mainfile by looking at the: * static index (Added in https://reviews.llvm.org/D70489) * file index (Added in https://reviews.llvm.org/D71406) This patch collects all the xref from the above places and outputs it in `findReferences` API. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72395
* [clangd] Show template arguments in type hierarchy when possibleNathan Ridge2020-01-121-3/+24
| | | | | | | | | | | | Summary: Fixes https://github.com/clangd/clangd/issues/31 Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71533
* [clangd] targetDecl() returns only NamedDecls.Sam McCall2020-01-031-24/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: While it's perfectly reasonable for non-named decls such as static_assert to resolve to themselves: - nothing else ever resolves to them - features based on references (hover, highlight, find refs etc) tend to be uninteresting where only trivial references are possible - returning NamedDecl is a more convenient API (we cast to it in many places) - this aligns closer to findExplicitReferences/explicitReferenceTargets This fixes a crash in explicitReferenceTargets: if the target is a non-named decl then there's an invalid unchecked cast to NamedDecl. In practice this means when hovering over e.g. a static_assert: - before ac3f9e4842, we would show a (boring) hover card - after ac3f9e4842, we would crash - after this patch, we will show nothing Reviewers: kadircet, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72163
* Revert "Revert "[clangd] Implement "textDocument/documentLink" protocol ↵Sam McCall2020-01-021-0/+20
| | | | | | | | | | support"" This reverts commit 079ef783dd5530b5f87beefe624b9179547ded7e. The revert describes a test failure without details, after offline discussion this in in a private/unsupported build system and doesn't seem to reflect a real upstream bug.
* Revert "[clangd] Reapply b60896fad926 Fall back to selecting ↵Sam McCall2019-12-161-9/+8
| | | | | | | token-before-cursor if token-after-cursor fails." This reverts commit a0ff8cd631add513423fc2d8afa49e9650d01fe3. Buildbot failures I can't chase further tonight.
* [clangd] Reapply b60896fad926 Fall back to selecting token-before-cursor if ↵Sam McCall2019-12-161-8/+9
| | | | | | token-after-cursor fails. This reverts commit 8f876d5105507f874c0fb86bc779c9853eab3fe2.
* Revert "[clangd] Reapply b60896fad926 Fall back to selecting ↵Sam McCall2019-12-161-9/+8
| | | | | | token-before-cursor if token-after-cursor fails." This reverts commit 2500a8d5d8813a3e31fc9ba8dd45e211439a1e3d.
* [clangd] Reapply b60896fad926 Fall back to selecting token-before-cursor if ↵Sam McCall2019-12-161-8/+9
| | | | | | | token-after-cursor fails. This reverts commit f0604e73a4daa35a10eb17a998657d6c4bd0e971 The issue with movability of Tweak::Selection was addressed in 7dc388bd9596bbf42633f8a8e450224e39740b60
* Revert "[clangd] Implement "textDocument/documentLink" protocol support"Dmitri Gribenko2019-12-161-20/+0
| | | | | | This reverts commit d6417f5584aa7673fa0212029a96cc9cacb1aad5. The tests depend on builtin headers, which is not intentionally supported in clangd tests; these tests are broken in some build environments.
* [NFC] Fix typos in Clangd and ClangKirill Bobyrev2019-12-161-5/+5
| | | | | | Reviewed by: Jim Differential Revision: https://reviews.llvm.org/D71455
* Revert "[clangd] Fall back to selecting token-before-cursor if ↵Nico Weber2019-12-141-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | token-after-cursor fails." This reverts commit b60896fad926754f715acc5d771555aaaa577e0f. Breaks building with gcc: /usr/include/c++/7/bits/stl_construct.h:75:7: error: use of deleted function ‘clang::clangd::Tweak::Selection::Selection(const clang::clangd::Tweak::Selection&)’ { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.h:28:0, from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.cpp:9: /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/refactor/Tweak.h:49:10: note: ‘clang::clangd::Tweak::Selection::Selection(const clang::clangd::Tweak::Selection&)’ is implicitly deleted because the default definition would be ill-formed: struct Selection { ^~~~~~~~~ /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/refactor/Tweak.h:49:10: error: use of deleted function ‘clang::clangd::SelectionTree::SelectionTree(const clang::clangd::SelectionTree&)’ In file included from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/refactor/Tweak.h:25:0, from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.h:28, from /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/ClangdServer.cpp:9: /home/buildslave/buildslave/clang-cmake-armv7-selfhost-neon/llvm/clang-tools-extra/clangd/Selection.h:96:3: note: declared here SelectionTree(const SelectionTree &) = delete; ^~~~~~~~~~~~~ e.g. here: http://lab.llvm.org:8011/builders/clang-cmake-armv7-selfhost-neon/builds/2714 http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/41866
* [clangd] Fall back to selecting token-before-cursor if token-after-cursor fails.Sam McCall2019-12-131-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The problem: LSP specifies that Positions are between characters. Therefore when a position (or an empty range) is used to target elements of the source code, there is an ambiguity - should we look left or right of the cursor? Until now, SelectionTree resolved this to the right except in trivial cases (where there's whitespace, semicolon, or eof on the right). This meant that it's unable to e.g. out-line `int foo^()` today. Complicating this, LSP notwithstanding the cursor is *on* a character in many editors (mostly terminal-based). In these cases there's no ambiguity - we must "look right" - but there's also no way to tell in LSP. (Several features currently resolve this by using getBeginningOfIdentifier, which tries to rewind and supports end-of-identifier. But this relies on raw lexing and is limited and buggy). Precedent: well - most other languages aren't so full of densely packed symbols that we might want to target. Bias-towards-identifier works well enough. MS C++ for vscode seems to mostly use bias-toward-identifier too. The problem with this solution is it doesn't provide any way to target some things such as the constructor call in Foo^(bar()); Presented solution: When an ambiguous selection is found, we generate *both* possible selection trees. We try to run the feature on the rightward tree first, and then on the leftward tree if it fails. This is basically do-what-I-mean, the main downside is the need to do this on a feature-by-feature basis (because each feature knows what "fail" means). The most complicated instance of this is Tweaks, where the preferred selection may vary tweak-by-tweak. Wrinkles: While production behavior is pretty consistent, this introduces some inconsistency in testing, depending whether the interface we're testing is inside or outside the "retry" wrapper. In particular, for many features like Hover, the unit tests will show production behavior, while for Tweaks the harness would have to run the loop itself if we want this. Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71345
* [clangd] Implement "textDocument/documentLink" protocol supportMichael Forster2019-12-121-0/+20
| | | | | | | | | | | | | | | | | | | Summary: This adds an implementation for the "textDocument/documentLink" LSP request. It returns links for all `#include` directives to the resolved target files. Fixes https://github.com/clangd/clangd/issues/217. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70872
* [clangd] Simplify code using findName. NFCIlya Biryukov2019-12-101-4/+2
| | | | | | | | | | | | | `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.
* [clangd] Navigation from definition of template specialization to primary ↵Nathan Ridge2019-12-081-4/+16
| | | | | | | | | | | | | | template Fixes https://github.com/clangd/clangd/issues/212. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71090
* [clangd] Simplify the code, NFC.Haojian Wu2019-12-051-1/+1
| | | | AST.getASTContext().getSourceManager() => AST.getSourceManager().
* [clangd] NFC, add getLangOpts helper to ParsedASTAlex Lorenz2019-12-041-12/+9
| | | | | The addition of the helper is split out from https://reviews.llvm.org/D69543 as suggested by Kadir. I also updated the existing uses to use the new API.
* [clangd] Untangle Hover from XRefs, move into own file.Sam McCall2019-11-191-537/+0
| | | | | | | | | | | | | | | | | | | | | | | | 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] Fix hover 'local scope' to include class template paramsSam McCall2019-11-191-6/+6
| | | | | | | | | | | | Summary: Fixes the last part of https://github.com/clangd/clangd/issues/76 Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70325
* [clangd] More sensible output for constructors/destructors in hover.Sam McCall2019-11-191-39/+46
| | | | | | | | | | | | | | 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] Store xref for Macros in ParsedAST.Utkarsh Saxena2019-11-181-2/+1
| | | | | | | This patch adds the cross references for Macros in the MainFile. We add references for the main file to the ParsedAST. We query the references from it using the SymbolID. Xref outside main file will be added to the index in a separate patch.
* [clangd] Expose the xref's incomplete flag to clangdServer API.Haojian Wu2019-11-181-11/+17
| | | | | | | | | | | | Summary: so that clangd C++ API users (via ClangdServer) can access it. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70380
* [clangd] Don't repeat class template args when printing constructor definitionsSam McCall2019-11-151-0/+1
| | | | This fixes part of https://github.com/clangd/clangd/issues/76
* [clangd] Don't consider class template params part of constructor name.Sam McCall2019-11-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | 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] Expose value of enumerators to Hover API. (not UI yet)Sam McCall2019-11-141-0/+4
| | | | | | | | | | | | Summary: This is part of https://github.com/clangd/clangd/issues/180. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70209
* Refactor getDeclAtPosition() to use SelectionTree + targetDecl()Nathan Ridge2019-10-311-105/+77
| | | | | | | | | | | | Summary: This fixes issue #163, among other improvements to go-to-definition. Reviewers: sammccall Subscribers: jkorous, mgrang, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69237
* [clangd] Flush streams when printing HoverInfo Name and DefinitionKadir Cetinkaya2019-10-281-0/+2
| | | | Summary: Fixes some windows breakages when compiled via msvc.
* [clangd] Report declaration references in findExplicitReferences.Haojian Wu2019-10-181-1/+2
| | | | | | | | | | | | Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68977 llvm-svn: 375226
* [clangd] Use our own relation kind.Haojian Wu2019-10-171-1/+2
| | | | | | | | | | | | | | | | Summary: Move the RelationKind from Serialization.h to Relation.h. This patch doesn't introduce any breaking changes. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68981 llvm-svn: 375117
* [clangd] Add a helper for extracting nonlocal decls in a FunctionDeclKadir Cetinkaya2019-09-261-0/+14
| | | | | | | | | | | | | | | | | | | Summary: To be used by define-inline code action to determine whether the function/method body will still be valid in another context. Traverses clang-ast to find all decl nodes under the function decl and stores the non-local ones. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67748 llvm-svn: 372948
* [clang][Index][NFC] Put IndexingOptions to a separate headerJan Korous2019-09-061-0/+1
| | | | llvm-svn: 371250
* [clangd] Remove macro-expansion-location from getBeginningOfIdentifier. ↵Sam McCall2019-09-041-14/+18
| | | | | | Inline into relevant callsites. NFC llvm-svn: 370869
* [clangd] Rename ClangdUnit.h -> ParsedAST.h. NFCSam McCall2019-09-041-0/+1
| | | | | | | | | | This much better reflects what is (now) in this header. Maybe a rename to ParsedTU would be an improvement, but that's a much more invasive change and life is too short. ClangdUnit is dead, long live ClangdUnitTests! llvm-svn: 370862
* [clangd] Move getBeginningOfIdentifier from ClangdUnit to SourceCode. Drop ↵Sam McCall2019-09-031-11/+12
| | | | | | dependencies on ClangdUnit from some headers. NFC llvm-svn: 370768
* [clangd] Decouple macro/decl-under-cursor finding. Don't pretend there can ↵Sam McCall2019-09-031-73/+41
| | | | | | be multiple macros. NFC. llvm-svn: 370759
* [clangd] Ignore implicit conversion-operator nodes in find refs.Haojian Wu2019-08-211-0/+5
| | | | | | | | | | | | Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66478 llvm-svn: 369514
* [clangd] Fix one testcase in XRefsTests.Haojian Wu2019-08-201-11/+19
| | | | | | | | | | | | | | | | | | Summary: The test didn't test anything actually -- it used "[]" as annotation which should be "[[]]". This patch also fixes a bug in XRef where we may return duplicated refs. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66349 llvm-svn: 369387
* [clangd] Unfold SourceLocation flattening from findNameLoc in preparation ↵Sam McCall2019-08-061-2/+5
| | | | | | for adding more overloads. NFC llvm-svn: 368083
* [clangd] Fix a crash when presenting values for HoverIlya Biryukov2019-08-021-1/+1
| | | | | | | | | | | | | | | | | | | Summary: We should pass the expression type, not a variable type when printing the resulting value. Variable type may be different from what the pretty-printing function expects, e.g. have references. Reviewers: sammccall Reviewed By: sammccall Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65655 llvm-svn: 367687
* [clangd] Remove bad assert: nothing relies on it, and the reasons it was ↵Sam McCall2019-08-021-3/+2
| | | | | | true no longer hold. llvm-svn: 367672
* [clangd] cleanup: unify the implemenation of checking a location is inside ↵Haojian Wu2019-07-191-1/+1
| | | | | | | | | | | | | | | | main file. Summary: We have variant implementations in the codebase, this patch unifies them. Reviewers: ilya-biryukov, kadircet Subscribers: MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64915 llvm-svn: 366541
* [clangd] Type hierarchy: don't resolve parents if the client only asked for ↵Nathan Ridge2019-07-171-16/+17
| | | | | | | | | | | | | | | | | | children Summary: Also reorganize the code for computing supertypes to make it more symmetric to subtypes. Reviewers: kadircet Reviewed By: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64613 llvm-svn: 366338
* [clangd] Implement typeHierarchy/resolve for subtypesNathan Ridge2019-07-131-1/+24
| | | | | | | | | | | | | | | | | | Summary: This allows the client to resolve subtypes one level at a time. For supertypes, this is not necessary, because we eagerly compute supertypes and return all levels. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64308 llvm-svn: 365986
* Revert "[clangd] Implement typeHierarchy/resolve for subtypes"Russell Gallop2019-07-121-24/+1
| | | | | | | | Causing test failure on Windows bot This reverts commit 5b9484e559d44bd923fc290e335891b1dd2e17c4. llvm-svn: 365899
* [clangd] Implement typeHierarchy/resolve for subtypesNathan Ridge2019-07-121-1/+24
| | | | | | | | | | | | | | | | | | Summary: This allows the client to resolve subtypes one level at a time. For supertypes, this is not necessary, because we eagerly compute supertypes and return all levels. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64308 llvm-svn: 365867
* [clangd] Add a missing early return in getTypeHierarchy()Nathan Ridge2019-07-121-0/+2
| | | | | | | | | | | | Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64307 llvm-svn: 365849
* [clangd] Implementation of auto type expansion.Sam McCall2019-07-111-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Show documentation in hover, and fetch docs from index if needed.Sam McCall2019-07-091-7/+39
| | | | | | | | | | | | | | | | | | | Summary: I assume showing docs is going to be part of structured hover rendering, but it's unclear whether that's going to make clangd 9 so this is low-hanging fruit. (Also fixes a bug uncovered in FormattedString's plain text output: need blank lines when text follows codeblocks) Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64296 llvm-svn: 365522
* [clangd] Fix unused var from r364735Sam McCall2019-07-011-5/+4
| | | | llvm-svn: 364741
* [clangd] Show better message when we rename macros.Haojian Wu2019-07-011-46/+21
| | | | | | | | | | | | | | | | | | Summary: Previously, when we rename a macro, we get an error message of "there is no symbol found". This patch improves the message of this case (as we don't support macros). Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63922 llvm-svn: 364735
OpenPOWER on IntegriCloud