Repository navigation
Bugfix 770 #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Bugfix 770 #775
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
719c8df
First attempt to resolve the issue
33e6d0d
Avoid polluting the user experience
1099898
Avoid doing the same thing twice
3d2c6f4
New strategy to position the cursor after deletion
8559fe2
Adds test for phpactor#_applyTextEdits
523dfe9
Adds a new test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| Include: utils.vader | ||
|
|
||
| Given php (Original source): | ||
| <?php | ||
|
|
||
| class Foo | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| private $foo: | ||
|
|
||
| private function foo() | ||
| { | ||
| return $this->foo(); | ||
| } | ||
| } | ||
|
|
||
| Execute (Goes to the method line and changes the visibility): | ||
| 10 | ||
| call Apply( | ||
| \ Delete(10), | ||
| \ Insert(10, ' public function foo()') | ||
| \ ) | ||
|
|
||
| Then (The cursor should not have moved): | ||
| call AssertCursorDidntMove() | ||
|
|
||
| Expect php (The visibility shoud have changed): | ||
| <?php | ||
|
|
||
| class Foo | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| private $foo: | ||
|
|
||
| public function foo() | ||
| { | ||
| return $this->foo(); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
plugin/tests/apply_text_edits/replace_line_which_move.vader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| Include: utils.vader | ||
|
|
||
| Given php (Original source): | ||
| <?php | ||
|
|
||
| class Foo | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| private $foo: | ||
|
|
||
| private function foo() | ||
| { | ||
| return $this->foo(); | ||
| } | ||
| } | ||
|
|
||
| Execute (Goes to the method line and changes the visibility): | ||
| 10 | ||
| call Apply( | ||
| \ Delete(10), | ||
| \ Insert(10, ' /**'), | ||
| \ Insert(11, ' * @var int $i'), | ||
| \ Insert(12, ' */'), | ||
| \ Insert(13, ' private function foo(int $i)') | ||
| \ ) | ||
|
|
||
| Then (Then cursor should still be on the method signature): | ||
| call AssertCursorOnLine(13) | ||
|
|
||
| Expect php (The docblock should be added and the signature changed): | ||
| <?php | ||
|
|
||
| class Foo | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| private $foo: | ||
|
|
||
| /** | ||
| * @var int $i | ||
| */ | ||
| private function foo(int $i) | ||
| { | ||
| return $this->foo(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| Before: | ||
| Save g:applyTextEditsPosBefore | ||
|
|
||
| set nofoldenable | ||
|
|
||
| function! Apply(...) | ||
| let g:applyTextEditsPosBefore = getpos('.') | ||
| let ApplyTextEdits = function('phpactor#_applyTextEdits', [expand('%:p')]) | ||
|
|
||
| call ApplyTextEdits(a:000) | ||
| endfunction | ||
|
|
||
| function! Position(line) | ||
| return { 'line': a:line, 'character': 0 } | ||
| endfunction | ||
|
|
||
| function! Delete(startLine, ...) | ||
| let startLine = a:startLine - 1 | ||
| let endLine = 0 < a:0 ? a:1 : a:startLine | ||
|
|
||
| return { 'start': Position(startLine), 'end': Position(endLine), 'text': '' } | ||
| endfunction | ||
|
|
||
| function! Insert(line, text) | ||
| let line = a:line - 1 | ||
|
|
||
| return { 'start': Position(line), 'end': Position(line), 'text': a:text } | ||
| endfunction | ||
|
|
||
| function! AssertCursorDidntMove() | ||
| AssertEqual g:applyTextEditsPosBefore, getpos('.') | ||
| endfunction | ||
|
|
||
| function! AssertCursorOnLine(line) | ||
| AssertEqual a:line, line('.') | ||
| endfunction | ||
|
|
||
| After: | ||
| Restore |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be a stupid question but why don't we just have the above
Givenand just goto the method line and invoke the change visiblity?e.g. the
insert_usetest:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, this isn't testing change visibility :)