summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/refactor/tweaks
Commit message (Collapse)AuthorAgeFilesLines
* [clangd] Make use of SourceOrder to find first initializer in DefineOutlineKadir Cetinkaya2020-06-101-6/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Constructors can have implicit initializers, this was crashing define outline. Make sure we find the first "written" ctor initializer to figure out `:` location. Fixes https://github.com/clangd/clangd/issues/400 Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80521 (cherry picked from commit eeedbd033612e105755156023bdeec2fba4eca21) Fixes https://github.com/clangd/clangd/issues/418
* [clangd] DefineOutline won't copy virtual specifiers on methodsNathan James2020-03-041-4/+63
| | | | | | | | | | | | | | | | | | Summary: The define out of line refactor tool previously would copy the `virtual`, `override` and `final` specifier into the out of line method definition. This results in malformed code as those specifiers aren't allowed outside the class definition. Reviewers: hokein, kadircet Reviewed By: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D75429 (cherry picked from commit b2666ccca0277371a09e43a0a5a0f78029ba81e5)
* NFC: Fix trivial typos in commentsKazuaki Ishizaki2020-01-041-1/+1
|
* [clangd] Make Tweak::Selection movable. NFCSam McCall2019-12-1612-48/+49
|
* [clangd] Add "inline" keyword to prevent ODR-violations in DefineInlineKadir Cetinkaya2019-12-131-3/+30
| | | | | | | | | | Reviewers: ilya-biryukov, hokein Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68261
* [clangd] Delete ctor initializers while moving functions out-of-lineKadir Cetinkaya2019-12-091-1/+43
| | | | | | | | | | | | | | | | | | | | Summary: Currently we only delete function body from declaration, in addition to that we should also drop ctor initializers. Unfortunately CXXConstructorDecl doesn't store the location of `:` before initializers, therefore we make use of token buffer to figure out where to start deletion. Fixes https://github.com/clangd/clangd/issues/220 Reviewers: hokein, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71188
* [clangd] Delete default arguments while moving functions out-of-lineKadir Cetinkaya2019-12-091-10/+41
| | | | | | | | | | | | | | | | | | Summary: Only function declarations should have the default arguments. This patch makes sure we don't propogate those arguments to out-of-line definitions. Fixes https://github.com/clangd/clangd/issues/221 Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71187
* [clangd] Allow extract-to-function on regions that always return.Sam McCall2019-12-091-14/+51
| | | | | | | | | | | | | | Summary: We only do a trivial check whether the region always returns - it has to end with a return statement. Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70569
* [clangd] Fix gcc warning about extra ";" [NFC]Mikael Holmen2019-12-061-1/+1
| | | | | | | | gcc complained with /data/repo/master/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:326:30: warning: extra ';' [-Wpedantic] REGISTER_TWEAK(DefineOutline); ^
* [clangd] Simplify the code, NFC.Haojian Wu2019-12-052-3/+3
| | | | AST.getASTContext().getSourceManager() => AST.getSourceManager().
* [clangd] Add a tweak refactoring to wrap Objective-C string literals in ↵Alex Lorenz2019-12-042-0/+86
| | | | | | | | `NSLocalizedString` macros The commit adds a refactoring to Clangd that mimics the existing refactoring action in Xcode that wraps around an Objective-C string literal in an NSLocalizedString macro. Differential Revision: https://reviews.llvm.org/D69543
* [clangd] NFC, add getLangOpts helper to ParsedASTAlex Lorenz2019-12-043-7/+6
| | | | | 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] Define out-of-line qualify function nameKadir Cetinkaya2019-12-041-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When moving function definitions to a different context, the function name might need a different spelling, for example in the header it might be: ``` namespace a { void foo() {} } ``` And we might want to move it into a context which doesn't have `namespace a` as a parent, then we must re-spell the function name, i.e: ``` void a::foo() {} ``` This patch implements a version of this which ignores using namespace declarations in the source file. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70656
* [clangd] Define out-of-line qualify return valueKadir Cetinkaya2019-12-041-24/+139
| | | | | | | | | | | | | | | | Summary: Return type might need qualification if insertion context doesn't have the same decls visible as the source context. This patch adds qualification for return value to cover such cases. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70535
* [clangd] Define out-of-line initial apply logicKadir Cetinkaya2019-12-041-3/+112
| | | | | | | | | | | | | | | | | | Summary: Initial implementation for apply logic, replaces function body with a semicolon in source location and copies the full function definition into target location. Will handle qualification of return type and function name in following patches to keep the changes small. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69298
* [clangd] Define out-of-line availability checksKadir Cetinkaya2019-12-042-0/+110
| | | | | | | | | | | | | | | | | | Summary: Initial availability checks for performing define out-of-line code action, which is a refactoring that will help users move function/method definitions from headers to implementation files. Proposed implementation only checks whether we have an interesting selection, namely function name or full function definition/body. Reviewers: hokein Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69266
* [clangd] Improve symbol qualification in DefineInline code actionKadir Cetinkaya2019-11-251-7/+10
| | | | | | | | | | | | | | | | | | | | | | Summary: Currently define inline action fully qualifies any names in the function body, which is not optimal and definitely natural. This patch tries to improve the situation by dropping any name specifiers shared by function and names spelled in the body. For example if you are moving definition of a function in namespace clang::clangd, and body has any decl's coming from clang or clang::clangd namespace, those qualifications won't be added since they are redundant. It also drops any qualifiers that are visible in target context. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69033
* [clangd] Untangle Hover from XRefs, move into own file.Sam McCall2019-11-191-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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 crash in DefineInline::prepare()Sam McCall2019-11-111-1/+1
|
* [clangd] NFC, reuse the source manager variable in the RawStringLiteral ↵Alex Lorenz2019-11-081-2/+1
| | | | | | apply method Differential Revision: https://reviews.llvm.org/D69544
* [clangd] Add parameter renaming to define-inline code actionKadir Cetinkaya2019-10-311-2/+108
| | | | | | | | | | | | | | | | | Summary: When moving a function definition to declaration location we also need to handle renaming of the both function and template parameters. This patch achives that by making sure every parameter name and dependent type in destination is renamed to their respective name in the source. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68937
* [clangd] Add a hidden tweak to dump symbol under the cursor.Haojian Wu2019-10-291-0/+27
| | | | | | | | | | | | | | Summary: This provides a convenient way to see the SymbolID/USR of the symbol, mainly for debugging purpose. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69517
* Remove extra ';'. NFCI.Simon Pilgrim2019-10-281-1/+1
|
* [clangd] Reland DefineInline action apply logic with fully qualified namesKadir Cetinkaya2019-10-281-4/+183
| | | | | | | | | | | | Summary: Initial version of DefineInline action that will fully qualify every name inside function body. Reviewers: sammccall, ilya-biryukov, hokein Tags: #clang Differential Revision: https://reviews.llvm.org/D66647
* [clangd] Reland DefineInline action availability checksKadir Cetinkaya2019-10-282-0/+215
| | | | | | | | | | | | | | | | Summary: Introduces DefineInline action and initial version of availability checks. Reviewers: sammccall, ilya-biryukov, hokein Reviewed By: hokein Subscribers: thakis, usaxena95, mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65433
* [clangd] Revert define-inline action changes to un-break windows build-botsKadir Cetinkaya2019-10-252-394/+0
|
* Fix compilation error in clangd/refactor/tweaks/ExpandAutoType.cppKadir Cetinkaya2019-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Summary: During the compilation of the `clangd/refactor/tweaks/ExpandAutoType.cpp`, MSVC returns the following error: llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(85): error C2146: syntax error: missing ')' before identifier 'and' llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(85): error C2065: 'and': undeclared identifier llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(86): error C2143: syntax error: missing ';' before '<template-id>' llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(73): fatal error C1075: '{': no matching token found So, && must be used instead of `and`. Patch By Pavel Samolysov (@psamolysov) ! Reviewers: kadircet Reviewed By: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D69427
* [clangd] DefineInline action apply logic with fully qualified namesKadir Cetinkaya2019-10-251-4/+183
| | | | | | | | | | | | Summary: Initial version of DefineInline action that will fully qualify every name inside function body. Reviewers: sammccall, ilya-biryukov, hokein Tags: #clang Differential Revision: https://reviews.llvm.org/D66647
* [clangd] DefineInline action availability checksKadir Cetinkaya2019-10-252-0/+215
| | | | | | | | | | | | Summary: Introduces DefineInline action and initial version of availability checks. Reviewers: sammccall, ilya-biryukov, hokein Tags: #clang Differential Revision: https://reviews.llvm.org/D65433
* [clangd] Add the missing dependency on `clangLex`.Michael Liao2019-10-161-0/+1
| | | | llvm-svn: 375039
* [clangd] Add RemoveUsingNamespace tweak.Utkarsh Saxena2019-10-162-0/+207
| | | | | | | | | | | | | | | | | | 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] Disable expand auto on decltype(auto)Ilya Biryukov2019-10-081-1/+3
| | | | | | | | | | | | | | | | Summary: Applying it produces incorrect code at the moment. Reviewers: sammccall Reviewed By: sammccall Subscribers: kuhnel, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68630 llvm-svn: 374048
* [Clangd] ExtractFunction: Don't extract body of enclosing function.Shaurya Gupta2019-10-021-8/+21
| | | | | | | | | | | | | | | | | | | Summary: This patch disable extraction of the body of the enclosing function. `void f() [[{}]]` Extracting this CompoundStmt would leave the enclosing function without a body. Reviewers: sammccall, kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68245 llvm-svn: 373472
* [Clangd] Ensure children are always RootStmt in ExtractFunction (Fixes #153)Shaurya Gupta2019-10-021-4/+14
| | | | | | | | | | | | | | | | | | Summary: We weren't always checking if children are RootStmts in ExtractFunction. For `void f([[int a]]);`, the ParmVarDecl appeared as a RootStmt since we didn't perform the check and ended up being casted to a (null) Stmt. Reviewers: sammccall, kadircet Subscribers: kristof.beyls, ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68182 llvm-svn: 373471
* [clangd] SelectionTree should mark a node as fully-selected if the only ↵Sam McCall2019-10-021-6/+3
| | | | | | | | | | | | | | | | | | | claimed tokens were early-claimed. Summary: Previously they would be marked as partially-selected based on the early claim, and never updated as no more tokens were claimed. This affects simple VarDecls like "int x". Reviewers: SureYeaah Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66872 llvm-svn: 373442
* [clangd] Support multifile edits as output of TweaksKadir Cetinkaya2019-09-097-14/+16
| | | | | | | | | | | | | | | | | | | | Summary: First patch for propogating multifile changes from tweak outputs to LSP WorkspaceEdits. Uses SM to convert tooling::Replacements to TextEdits. Errors out if there are any inconsistencies between the draft version and the version generated the edits. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66637 llvm-svn: 371392
* [clangd] Rename ClangdUnit.h -> ParsedAST.h. NFCSam McCall2019-09-044-4/+4
| | | | | | | | | | 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] ExtractFunction Added checks for broken control flowShaurya Gupta2019-08-301-13/+59
| | | | | | | | | | | | | | | | Summary: - Added checks for broken control flow - Added unittests Reviewers: sammccall, kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66732 llvm-svn: 370455
* [Clangd] NFC: Added fixme for checking for local/anonymous types for ↵Shaurya Gupta2019-08-291-0/+1
| | | | | | extracted parameters llvm-svn: 370372
* Fix MSVC "not all control paths return a value" warning. NFCI.Simon Pilgrim2019-08-291-0/+1
| | | | llvm-svn: 370343
* [clangd] Fix ExtractFunction dependenciesHeejin Ahn2019-08-281-0/+1
| | | | | | | | | | | | | | Summary: Without these dependencies, builds with `-DBUILD_SHARED_LIBS=ON` fail. Reviewers: SureYeaah Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66910 llvm-svn: 370273
* [Clangd] Initial version of ExtractFunctionShaurya Gupta2019-08-282-0/+606
| | | | | | | | | | | | | | | | | | | Summary: - Only works for extraction from free functions - Basic analysis of the code being extracted. - Extract to void function - Bail out if extracting a return, continue or break. - Doesn't hoist decls yet Reviewers: kadircet, sammccall Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65526 llvm-svn: 370249
* [clang-tools-extra] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-1/+1
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368944
* [clangd] Refactor computation of extracted expr in ExtractVariable tweak. NFCSam McCall2019-08-121-61/+66
| | | | | | | | | | | | | | | | | | | | | | | Summary: This takes this logic out of the Tweak class, and simplifies the signature of the function where the main logic is. The goal is to make it easier to turn into a loop like: for (current = N; current and current->parent are both expr; current = current->parent) if (suitable(current)) return current; return null; Reviewers: SureYeaah Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65333 llvm-svn: 368590
* [clangd] Disallow extraction of expression-statements.Sam McCall2019-08-091-48/+77
| | | | | | | | | | | | | | | | | | | | | Summary: I split out the "extract parent instead of this" logic from the "this isn't worth extracting" logic (now in eligibleForExtraction()), because I found it hard to reason about. While here, handle overloaded as well as builtin assignment operators. Also this uncovered a bug in getCallExpr() which I fixed. Reviewers: SureYeaah Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65337 llvm-svn: 368500
* [clangd] Fix a regression in rL366996.Haojian Wu2019-07-301-7/+5
| | | | | | | | | | | | | | Summary: That patch made the tweak always annotate the whole file by accident. Reviewers: jvikstrom Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65443 llvm-svn: 367313
* [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].Sam McCall2019-07-261-16/+157
| | | | | | | | | | | | | | | | | | | | | Summary: These aren't formally subexpressions in C++, in this case + is left-associative. However informally +, *, etc are usually (mathematically) associative and users consider these subexpressions. We detect these and in simple cases support extracting the partial expression. As well as builtin associative operators, we assume that overloads of them are associative and support those too. Reviewers: SureYeaah Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65139 llvm-svn: 367121
* [Clangd] Disable ExtractVariable for all types of assignmentsShaurya Gupta2019-07-261-1/+1
| | | | | | | | | | | | Reviewers: sammccall, kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65332 llvm-svn: 367113
* [clangd] Fix the annotate tweak after rL366893Haojian Wu2019-07-251-17/+23
| | | | | | | | | | | | | | | | | | Summary: After rL366893, the annoate tweak is not activated when we select the whole file (the commonAncestor is TUDecl but we intend to return null). This patch fixes this, and also avoid traversing the TUDecl. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65210 llvm-svn: 366996
* [clangd] SelectionTree treats TranslationUnitDecl (mostly) consistently with ↵Sam McCall2019-07-241-3/+1
| | | | | | | | | | | | | | | | | | | | | | | other containers. Summary: Previously TranslationUnitDecl would never be selected. This means root() is never null, and returns a reference. commonAncestor() is in principle never null also, but returning TUDecl here requires tweaks to be careful not to traverse it (this was already possible when selecting multiple top-level decls, and there are associated bugs!) Instead, never allow commonAncestor() to return TUDecl, return null instead. Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65101 llvm-svn: 366893
OpenPOWER on IntegriCloud