summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/refactor/Rename.cpp
Commit message (Collapse)AuthorAgeFilesLines
* NFC: Fix trivial typos in commentsKazuaki Ishizaki2020-01-041-1/+1
|
* [clangd] targetDecl() returns only NamedDecls.Sam McCall2020-01-031-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 "[clangd] Reapply b60896fad926 Fall back to selecting ↵Sam McCall2019-12-161-2/+1
| | | | | | | 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-1/+2
| | | | | | token-after-cursor fails. This reverts commit 8f876d5105507f874c0fb86bc779c9853eab3fe2.
* Revert "[clangd] Reapply b60896fad926 Fall back to selecting ↵Sam McCall2019-12-161-2/+1
| | | | | | 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-1/+2
| | | | | | | token-after-cursor fails. This reverts commit f0604e73a4daa35a10eb17a998657d6c4bd0e971 The issue with movability of Tweak::Selection was addressed in 7dc388bd9596bbf42633f8a8e450224e39740b60
* [NFC] Fix typos in Clangd and ClangKirill Bobyrev2019-12-161-2/+2
| | | | | | Reviewed by: Jim Differential Revision: https://reviews.llvm.org/D71455
* Revert "[clangd] Fall back to selecting token-before-cursor if ↵Nico Weber2019-12-141-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Rename constructors and destructors in cross-file caseKirill Bobyrev2019-12-121-24/+28
| | | | | | | | | | | * Use ad-hoc Decl canonicalization from Clang-Rename to allow renaming constructors and destructors while using cross-file rename. * Manually handle the destructor selection * Add unit tests to prevent regressions and ensure the correct behaviour Reviewed by: sammccall Differential Revision: https://reviews.llvm.org/D71247
* [clangd] Deduplicate refs from index for cross-file rename.Haojian Wu2019-12-111-3/+12
| | | | | | | | | | | | | | | | | | | | | | Summary: If the index returns duplicated refs, it will trigger the assertion in BuildRenameEdit (we expect the processing position is always larger the the previous one, but it is not true if we have duplication), and also breaks our heuristics. This patch make the code robost enough to handle duplications, also save some cost of redundnat llvm::sort. Though clangd's index doesn't return duplications, our internal index kythe will. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71300
* [clangd] Implement range patching heuristics for cross-file rename.Haojian Wu2019-12-091-2/+162
| | | | | | | | | | | | Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: merge_guards_bot, MaskRay, jkorous, mgrang, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70594
* [clangd] NFC, add getLangOpts helper to ParsedASTAlex Lorenz2019-12-041-3/+2
| | | | | 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.
* [NFC] Slightly improve wording in the commentsKirill Bobyrev2019-12-031-18/+18
| | | | | | Reviewed by: hokein Differential Revision: https://reviews.llvm.org/D70943
* Remove extraneous semicolon.Bill Wendling2019-12-021-1/+1
|
* [clangd] Fix a regression issue in local rename.Haojian Wu2019-12-021-6/+12
| | | | | | | | | | | | | | Summary: The regression is that we can't rename symbols in annonymous namespaces. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70853
* [clangd] Correct the file path in Edit::replacements when generating the ↵Haojian Wu2019-11-291-4/+6
| | | | | | | | | | | | | | | | | rename edit. Summary: The file path was set to the file content previously, and it isn't covered by normal clangd & unittest code path (as we only uses the offset, length, replacement text). Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70828
* [clangd] Don't perform rename when the refs result from index is incomplete.Haojian Wu2019-11-281-13/+23
| | | | | | | | | | | | | | Summary: Also do an early return if the number of affected files > limit to save some unnecessary FileURI computations. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70811
* [clangd] Tweak the no-index error message for rename, NFC.Haojian Wu2019-11-281-1/+1
| | | | | | | | | | | | Summary: The current error message doesn't fit well for cross-file rename. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70809
* [clangd] Speed up when building rename edit.Haojian Wu2019-11-261-34/+56
| | | | | | | | | | | | | | Summary: We used to scan the code everytime when computing the LSP position to the offset (respect the LSP encoding). Now we only scan the source code once. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70441
* [clangd] Implement cross-file rename.Haojian Wu2019-11-261-67/+267
| | | | | | | | | | | | | | | | | Summary: This is the initial version. The cross-file rename is purely based on the index. It is hidden under a command-line flag, and only available for a small set of symbols. Reviewers: ilya-biryukov, sammccall Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69263
* Reland "[clangd] Implement rename by using SelectionTree and ↵Haojian Wu2019-11-191-32/+103
| | | | | | | | | findExplicitReferences." this reland the commit 4f80fc2491cc35730a9a84b86975278b7daa8522 which has been reverted at f805c60a093325c16ce4200d2615ef48555d9cb8. Fixed windows buildbot failure (by adding -fno-delayed-template-parsing flag).
* Revert "[clangd] Implement rename by using SelectionTree and ↵Wolfgang Pieb2019-11-181-103/+32
| | | | | | | | | findExplicitReferences." This reverts commit 4f80fc2491cc35730a9a84b86975278b7daa8522. Caused buildbot failure at http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/58251
* [clangd] Implement rename by using SelectionTree and findExplicitReferences.Haojian Wu2019-11-181-32/+103
| | | | | | | | | | | | | | | | | | | | | | | Summary: With the new implemenation, we will have better coverage of various AST nodes, and fix some known/potential bugs. Also added the existing clang-renamae tests. Known changed behavior: - "~Fo^o()" will not trigger the rename, will fix afterwards - references in macro bodies are not renamed now This fixes: - https://github.com/clangd/clangd/issues/167 - https://github.com/clangd/clangd/issues/169 - https://github.com/clangd/clangd/issues/171 Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69934
* [clangd] Replace getLangOpts().isHeaderFile usage with isHeaderFile helper.Haojian Wu2019-11-151-1/+1
| | | | | | | | | | | | | | | | Summary: The helper is more correct to detect header file, this would fix our issues caused by false positive before. Reviewers: sammccall Reviewed By: sammccall Subscribers: merge_guards_bot, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70299
* [clangd] NFC, use URI::resolve to simplify the code.Haojian Wu2019-10-291-9/+5
|
* [clangd] Bail out early if we are sure that the symbol is used outside of ↵Haojian Wu2019-10-021-1/+5
| | | | | | | | | | | | | | | | | | the file. Summary: This would reduce the false positive when the static index is in an unavailable state, e.g. background index is not finished. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68325 llvm-svn: 373444
* [clangd] Fix a crash when renaming operator.Haojian Wu2019-09-161-0/+4
| | | | | | | | | | | | | | | | | | | | Summary: The renamelib uses a tricky way to calculate the end location by relying on decl name, this is incorrect for the overloaded operator (the name is "operator++" instead of "++"), which will cause out-of-file offset. We also disable renaming operator symbol, this case is tricky, and renamelib doesnt handle it properly. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D67607 llvm-svn: 371971
* [clangd] Remove macro-expansion-location from getBeginningOfIdentifier. ↵Sam McCall2019-09-041-2/+3
| | | | | | Inline into relevant callsites. NFC llvm-svn: 370869
* [clangd] Rename ClangdUnit.h -> ParsedAST.h. NFCSam McCall2019-09-041-1/+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-2/+4
| | | | | | dependencies on ClangdUnit from some headers. NFC llvm-svn: 370768
* [clangd] Use raw rename functions to implement the rename.Haojian Wu2019-08-091-60/+45
| | | | | | | | | | | | | | | | | | | | | | | Summary: The API provided by refactoring lib doesn't provide enough flexibility to get clangd's rename to behave as we expect. Instead, we replace it with the low-level rename functions, which give us more control. Bonus: - performance, previously we visit the TU to find all occurrences, now we just visit top-level decls from main file; - fix a bug where we wrongly filter out the main file replacement due to the different relative/absolute file path; Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65936 llvm-svn: 368429
* [clangd] cleanup: unify the implemenation of checking a location is inside ↵Haojian Wu2019-07-191-2/+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] Show better message when we rename macros.Haojian Wu2019-07-011-18/+25
| | | | | | | | | | | | | | | | | | 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
* [clangd] Fix a case where we fail to detect a header-declared symbol in rename.Haojian Wu2019-06-271-12/+13
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Failing case: ``` #include "foo.h" void fo^o() {} ``` getRenameDecl() returns the decl of the symbol under the cursor (which is in the current main file), instead, we use the canonical decl to determine whether a symbol is declared in #included header. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63872 llvm-svn: 364537
* [clangd] Don't rename the namespace.Haojian Wu2019-06-261-0/+5
| | | | | | | | | | | | | | | | | Summary: Also fix a small bug -- the extra argument "-xc++" doesn't overwrite the language if the argument is present after the file name in the compiler command. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63759 llvm-svn: 364392
* [clangd] Narrow rename to local symbols.Haojian Wu2019-06-251-1/+107
| | | | | | | | | | | | | | | | | | | Summary: Previously, we performed rename for all kinds of symbols (local, global). This patch narrows the scope by only renaming symbols not being used outside of the main file (with index asisitance). Renaming global symbols is not supported at the moment (return an error). Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63426 llvm-svn: 364283
* [clangd] Add missing license for rename.cpp, NFC.Haojian Wu2019-05-311-1/+9
| | | | llvm-svn: 362226
* [clangd] Add SourceManager accessor to ParsedAST. NFCSam McCall2019-05-281-4/+3
| | | | llvm-svn: 361883
* [clangd] Add test that r360116 accidentally fixed a duplicate-edits bug in ↵Sam McCall2019-05-071-0/+2
| | | | | | rename. NFC llvm-svn: 360118
* [clangd] Move Rename into its own file, and add unit test. NFCSam McCall2019-05-071-0/+79
Reviewers: kadircet Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61596 llvm-svn: 360116
OpenPOWER on IntegriCloud