summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/refactor/Tweak.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Revert "[clangd] Reapply b60896fad926 Fall back to selecting ↵Sam McCall2019-12-161-3/+3
| | | | | | | 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-3/+3
| | | | | | token-after-cursor fails. This reverts commit 8f876d5105507f874c0fb86bc779c9853eab3fe2.
* Revert "[clangd] Reapply b60896fad926 Fall back to selecting ↵Sam McCall2019-12-161-7/+0
| | | | | | 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-0/+7
| | | | | | | token-after-cursor fails. This reverts commit f0604e73a4daa35a10eb17a998657d6c4bd0e971 The issue with movability of Tweak::Selection was addressed in 7dc388bd9596bbf42633f8a8e450224e39740b60
* [clangd] Make Tweak::Selection movable. NFCSam McCall2019-12-161-1/+1
|
* Revert "[clangd] Fall back to selecting token-before-cursor if ↵Nico Weber2019-12-141-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Reland Store Index in Tweak::SelectionKadir Cetinkaya2019-10-281-3/+5
| | | | | | | | | | | | | | | | Summary: Incoming define out-of-line tweak requires access to index. This patch simply propogates the index in ClangdServer to Tweak::Selection while passing the AST. Also updates TweakTest to accommodate this change. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69165
* [clangd] Revert define-inline action changes to un-break windows build-botsKadir Cetinkaya2019-10-251-5/+3
|
* [clangd] Store Index in Tweak::SelectionKadir Cetinkaya2019-10-251-3/+5
| | | | | | | | | | | | | | | | Summary: Incoming define out-of-line tweak requires access to index. This patch simply propogates the index in ClangdServer to Tweak::Selection while passing the AST. Also updates TweakTest to accommodate this change. Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69165
* [clangd] Support multifile edits as output of TweaksKadir Cetinkaya2019-09-091-0/+29
| | | | | | | | | | | | | | | | | | | | 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] Ignore semicolons, whitespace, and comments in SelectionTree.Sam McCall2019-07-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Whitespace and comments are a clear bugfix: selecting some comments/space near a statement doesn't mean you're selecting the surrounding block. Semicolons are less obvious, but for similar reasons: these tokens aren't actually claimed by any AST node (usually), so an AST-based model like SelectionTree shouldn't take them into account. Callers may still sometimes care about semis of course: - when the selection is an expr with a non-expr parent, selection of the semicolon indicates intent to select the statement. - when a statement with a trailing semi is selected, we need to know its range to ensure it can be removed. SelectionTree may or may not play a role here, but these are separate questions from its core function of describing which AST nodes were selected. The mechanism here is the TokenBuffer from syntax-trees. We use it in a fairly low-level way (just to get boundaries of raw spelled tokens). The actual mapping of AST nodes to coordinates continues to use the (fairly mature) SourceLocation based logic. TokenBuffer/Syntax trees don't currently offer an alternative to getFileRange(), I think. Reviewers: SureYeaah, kadircet Subscribers: MaskRay, jkorous, arphaman, cfe-commits, ilya-biryukov Tags: #clang Differential Revision: https://reviews.llvm.org/D65486 llvm-svn: 367453
* [Clangd] Changed ExtractVariable to only work on non empty selectionsShaurya Gupta2019-07-181-1/+2
| | | | | | | | | | | | | | | | Summary: - For now, we don't trigger in any case if it's an empty selection - Fixed unittests Reviewers: kadircet, sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64912 llvm-svn: 366451
* [clangd] Don't run the prepare for tweaks that are disabled.Haojian Wu2019-07-121-2/+4
| | | | | | | | | | | | | | Summary: Previously, we ran the prepare, even for the tweaks that are disabled. Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64565 llvm-svn: 365882
* [clangd] Add SourceManager accessor to ParsedAST. NFCSam McCall2019-05-281-1/+1
| | | | llvm-svn: 361883
* Revamp the "[clangd] Format tweak's replacements"Haojian Wu2019-02-111-8/+0
| | | | | | | | | | | | | | | | | | | | Summary: This patch contains two parts: 1) reverts commit r353306. 2) move the format logic out from tweaks, keep tweaks API unchanged. Reviewers: sammccall, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58051 llvm-svn: 353712
* [clangd] Format tweak's replacements.Haojian Wu2019-02-061-0/+8
| | | | llvm-svn: 353306
* [clangd] Expose SelectionTree to code tweaks, and use it for swap if branches.Sam McCall2019-02-011-0/+8
| | | | | | | | | | | | | | | | | Summary: This reduces the per-check implementation burden and redundant work. It also makes checks range-aware by default (treating the commonAncestor as if it were a point selection should be good baseline behavior). Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet Tags: #clang Differential Revision: https://reviews.llvm.org/D57570 llvm-svn: 352876
* [clangd] Fix crash in applyTweak, remove TweakID alias.Sam McCall2019-02-011-1/+1
| | | | | | | Strings are complicated, giving them opaque names makes us forget they're complicated. llvm-svn: 352837
* [clangd] Remove extra ';' to fix -Wpedantic warning. NFCIlya Biryukov2019-01-291-1/+1
| | | | llvm-svn: 352511
* [clangd] Attempt to fix failing buildbots after r352494Ilya Biryukov2019-01-291-1/+1
| | | | | | | For failures see: http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/38501/steps/build-unified-tree/logs/stdio llvm-svn: 352510
* [clangd] Interfaces for writing code tweaksIlya Biryukov2019-01-291-0/+74
Summary: The code tweaks are an implementation of mini-refactorings exposed via the LSP code actions. They run in two stages: - Stage 1. Decides whether the action is available to the user and collects all the information required to finish the action. Should be cheap, since this will run over all the actions known to clangd on each textDocument/codeAction request from the client. - Stage 2. Uses information from stage 1 to produce the actual edits that the code action should perform. This stage can be expensive and will only run if the user chooses to perform the specified action in the UI. One unfortunate consequence of this change is increased latency of processing the textDocument/codeAction requests, which now wait for an AST. However, we cannot avoid this with what we have available in the LSP today. Reviewers: kadircet, ioeric, hokein, sammccall Reviewed By: sammccall Subscribers: mgrang, mgorny, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D56267 llvm-svn: 352494
OpenPOWER on IntegriCloud