From e5263dc59e22dcdf5c89dd6127927e24e6ab94d9 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 28 Sep 2022 01:22:49 +0200 Subject: [PATCH 01/34] Add extract variable --- README.md | 39 ++++++++++++++++++++++++ doc/refactoring-toolbox.txt | 48 ++++++++++++++++++++++++++---- playground.php | 13 ++++++++ plugin/php-refactoring-toolbox.vim | 29 ++++++++++++++++++ 4 files changed, 123 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8aa4a0d..55387a6 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ PHP Refactoring Toolbox for VIM * Rename Method * Extract Use * Extract Const +* Extract Variable * Extract Class Property * Extract Method * Create Property @@ -79,6 +80,7 @@ let g:vim_php_refactoring_make_setter_fluent = 2 nnoremap rm :call PhpRenameMethod() nnoremap eu :call PhpExtractUse() vnoremap ec :call PhpExtractConst() + vnoremap ev :call PhpExtractVariable() nnoremap ep :call PhpExtractClassProperty() vnoremap em :call PhpExtractMethod() nnoremap np :call PhpCreateProperty() @@ -250,6 +252,43 @@ class HelloWorld { } ``` +### Extract Variable + +``` php +ev`. +You'll be prompted for a variable name. Enter a variable name and press enter + +``` php +np` will create a new property in your current class. diff --git a/doc/refactoring-toolbox.txt b/doc/refactoring-toolbox.txt index 38e6b03..0570747 100755 --- a/doc/refactoring-toolbox.txt +++ b/doc/refactoring-toolbox.txt @@ -30,6 +30,7 @@ nnoremap rcv :call PhpRenameClassVariable() nnoremap rm :call PhpRenameMethod() nnoremap eu :call PhpExtractUse() vnoremap ec :call PhpExtractConst() +vnoremap ev :call PhpExtractVariable() nnoremap ep :call PhpExtractClassProperty() vnoremap em :call PhpExtractMethod() nnoremap np :call PhpCreateProperty() @@ -47,11 +48,12 @@ Examples *refactoring-to 4. Extract Use Statement........................................|extract-use-statement| 5. Extract Class Property.......................................|extract-class-property| 6. Extract Method...............................................|extract-method| -7. Create Property..............................................|create-property| -8. Detect Unused Use Statements.................................|detect-unused-use| -9. Align assignments............................................|align-assignments| -10. Create Setters and Getters..................................|create-set-get| -11. Document all................................................|document-all| +7. Extract Variable.............................................|extract-variable| +8. Create Property..............................................|create-property| +9. Detect Unused Use Statements.................................|detect-unused-use| +10. Align assignments...........................................|align-assignments| +11. Create Setters and Getters..................................|create-set-get| +12. Document all................................................|document-all| Note: ↑ Is the position of your cursor @@ -191,7 +193,41 @@ class HelloWorld { } =============================================================================== -Create Property *create-property* +Extract Variable *extract-variable* + +ev`. +You'll be prompted for a variable name. Enter a variable name and press enter + +np will create a new property in your current class. diff --git a/playground.php b/playground.php index ffa8a97..f74ca1d 100644 --- a/playground.php +++ b/playground.php @@ -63,6 +63,19 @@ public function testExtractConst() $string = 'FOOBAR'; } + /** + * Select the content you want to place in the content with the visual mode + * (you could use viw on int or va' on string) + * and then press ev to create a variable and replace every occurrences of this + * by the variable usage + */ + public function testExtractVariable() + { + if (!$obj instanceof \Fully\Qualified\Classname) { + Throw new Exception('$obj is not a \Fully\Qualified\Classname'); + } + } + /** * Place your cursor on the "localVariableWanabeAClassVariable" variable * and press ep to promote this variable as class property diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 36fda35..03fe898 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -62,6 +62,7 @@ if g:vim_php_refactoring_use_default_mapping == 1 nnoremap eu :call PhpExtractUse() nnoremap rm :call PhpRenameMethod() vnoremap ec :call PhpExtractConst() + vnoremap ev :call PhpExtractVariable() nnoremap ep :call PhpExtractClassProperty() vnoremap em :call PhpExtractMethod() nnoremap np :call PhpCreateProperty() @@ -252,6 +253,34 @@ function! PhpExtractConst() " {{{ endfunction " }}} +function! PhpExtractVariable() " {{{ + if visualmode() != 'v' + call s:PhpEchoError('Extract variable only works in Visual mode, not in Visual Line or Visual block') + return + endif + let l:name = inputdialog("Name of new variable: ") + " go to select and copy and delete + normal! gvx + " add marker + normal! mr + " type variable name + exec 'normal! i$'.l:name + " go to start on selection + normal! `r + let l:indentChars = indent(line('.')) + " got to line to write assignment + normal! O + " type variable assignment + exec 'normal! i'.repeat(' ', l:indentChars).'$'.l:name.' = ' + " paste selection + normal! pa; + " add empty line after assignment + normal! o + " go to start on selection + normal! `r +endfunction +" }}} + function! PhpExtractClassProperty() " {{{ normal! mr let l:name = substitute(expand(''), '^\$*', '', '') From 5804b8b1f299632e19199f291237163af18741b3 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 28 Sep 2022 03:20:05 +0200 Subject: [PATCH 02/34] fixup! Add extract variable --- README.md | 2 ++ doc/refactoring-toolbox.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 55387a6..74ce965 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,7 @@ class HelloWorld { private function prepareSentence($firstName) { $sentence = 'Hello'; + if ('foo' === $firstName) { $sentence .= ' ' . $firstName; } @@ -279,6 +280,7 @@ class HelloWorld { private function prepareSentence($firstName) { $sentence = 'Hello'; + $firstNameIsValid = 'foo' === $firstName; if ($firstNameIsValid) { diff --git a/doc/refactoring-toolbox.txt b/doc/refactoring-toolbox.txt index 0570747..d420f5c 100755 --- a/doc/refactoring-toolbox.txt +++ b/doc/refactoring-toolbox.txt @@ -217,6 +217,7 @@ class HelloWorld { private function prepareSentence($firstName) { $sentence = 'Hello'; + $firstNameIsValid = 'foo' === $firstName; if ($firstNameIsValid) { From 29cb21b38dc4042d374c2f6863f76563ee95648d Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 28 Sep 2022 03:18:38 +0200 Subject: [PATCH 03/34] Add test with vader --- .gitignore | 1 + README.md | 9 ++++++ bin/test | 31 +++++++++++++++++++ test/extract_variable.vader | 61 +++++++++++++++++++++++++++++++++++++ test/fixtures/vimrc | 14 +++++++++ 5 files changed, 116 insertions(+) create mode 100644 .gitignore create mode 100755 bin/test create mode 100644 test/extract_variable.vader create mode 100644 test/fixtures/vimrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/README.md b/README.md index 74ce965..70173a7 100644 --- a/README.md +++ b/README.md @@ -381,3 +381,12 @@ class Foo { `da` will call your documentation plugin (by default Php Documentor for vim https://github.com/tobyS/pdv) for every uncommented classes, methods, functions and properties. +## Running tests + +``` +bin/test +``` + +### How to write tests? + +See https://github.com/junegunn/vader.vim diff --git a/bin/test b/bin/test new file mode 100755 index 0000000..3efa9b6 --- /dev/null +++ b/bin/test @@ -0,0 +1,31 @@ +#! /bin/sh -eu + +installVader () +{ + vaderdir='vendor/vader.vim' + vaderCommit='6fff477431ac3191c69a3a5e5f187925466e275a' + + test -d "$vaderdir" || { + { + git clone \ + --branch=master \ + --single-branch \ + https://github.com/junegunn/vader.vim.git \ + "$vaderdir" + + git \ + --work-tree="$vaderdir" \ + --git-dir="$vaderdir/.git" \ + reset --hard \ + "$vaderCommit" -- + } || { + rm -rf "$vaderdir" + + exit 1 + } + } +} + +installVader + +vim -esNu test/fixtures/vimrc -c 'Vader! test/*' diff --git a/test/extract_variable.vader b/test/extract_variable.vader new file mode 100644 index 0000000..6893262 --- /dev/null +++ b/test/extract_variable.vader @@ -0,0 +1,61 @@ +Given php (condition on if): + + vi( + ;ev + firstNameIsValid\ + +Expect php (variable is extracted): + + vi( + ;ev + firstNameIsValid\ + +Expect php (variable is extracted): + Date: Fri, 30 Sep 2022 23:41:14 +0200 Subject: [PATCH 04/34] fixup! Add extract variable --- bin/test | 2 +- .../on_condition/in_function.vader} | 26 ------------------- .../on_condition/outside_function.vader | 25 ++++++++++++++++++ 3 files changed, 26 insertions(+), 27 deletions(-) rename test/{extract_variable.vader => extract_variable/on_condition/in_function.vader} (58%) create mode 100644 test/extract_variable/on_condition/outside_function.vader diff --git a/bin/test b/bin/test index 3efa9b6..7314f9e 100755 --- a/bin/test +++ b/bin/test @@ -28,4 +28,4 @@ installVader () installVader -vim -esNu test/fixtures/vimrc -c 'Vader! test/*' +vim -esNu test/fixtures/vimrc -c 'Vader! test/**' diff --git a/test/extract_variable.vader b/test/extract_variable/on_condition/in_function.vader similarity index 58% rename from test/extract_variable.vader rename to test/extract_variable/on_condition/in_function.vader index 6893262..1895a1d 100644 --- a/test/extract_variable.vader +++ b/test/extract_variable/on_condition/in_function.vader @@ -1,29 +1,3 @@ -Given php (condition on if): - - vi( - ;ev - firstNameIsValid\ - -Expect php (variable is extracted): - + vi( + ;ev + firstNameIsValid\ + +Expect php (variable is extracted): + Date: Fri, 30 Sep 2022 23:56:02 +0200 Subject: [PATCH 05/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 4 ++-- .../it_place_assignment_outside_array.vader | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/extract_variable/it_place_assignment_outside_array.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 03fe898..b0347a9 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -268,11 +268,11 @@ function! PhpExtractVariable() " {{{ " go to start on selection normal! `r let l:indentChars = indent(line('.')) - " got to line to write assignment + " go to line to write assignment normal! O " type variable assignment exec 'normal! i'.repeat(' ', l:indentChars).'$'.l:name.' = ' - " paste selection + " paste selection and add semi-colon normal! pa; " add empty line after assignment normal! o diff --git a/test/extract_variable/it_place_assignment_outside_array.vader b/test/extract_variable/it_place_assignment_outside_array.vader new file mode 100644 index 0000000..97b7b5e --- /dev/null +++ b/test/extract_variable/it_place_assignment_outside_array.vader @@ -0,0 +1,21 @@ +Given php: + 1234, + ]; + +Do: + /1234\ + viw + ;ev + baz\ + +Expect: + $baz, + ]; From 7ebf157aaa8a080c53ce28cba670fe9c22415fa6 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 00:14:22 +0200 Subject: [PATCH 06/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 8 ++++---- .../it_place_assignment_outside_array.vader | 2 +- test/extract_variable/on_condition/in_function.vader | 2 +- test/extract_variable/on_condition/outside_function.vader | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index b0347a9..51cb208 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -259,6 +259,7 @@ function! PhpExtractVariable() " {{{ return endif let l:name = inputdialog("Name of new variable: ") + let l:lineForAssignment = inputdialog("Line of assignment: ") " go to select and copy and delete normal! gvx " add marker @@ -267,15 +268,14 @@ function! PhpExtractVariable() " {{{ exec 'normal! i$'.l:name " go to start on selection normal! `r - let l:indentChars = indent(line('.')) " go to line to write assignment - normal! O + exec 'normal! '.l:lineForAssignment.'gg' + let l:indentChars = indent(line('.')) + normal! o " type variable assignment exec 'normal! i'.repeat(' ', l:indentChars).'$'.l:name.' = ' " paste selection and add semi-colon normal! pa; - " add empty line after assignment - normal! o " go to start on selection normal! `r endfunction diff --git a/test/extract_variable/it_place_assignment_outside_array.vader b/test/extract_variable/it_place_assignment_outside_array.vader index 97b7b5e..35f42da 100644 --- a/test/extract_variable/it_place_assignment_outside_array.vader +++ b/test/extract_variable/it_place_assignment_outside_array.vader @@ -10,10 +10,10 @@ Do: viw ;ev baz\ + 1\ Expect: + 5\ Expect php (variable is extracted): + 3\ Expect php (variable is extracted): Date: Sat, 1 Oct 2022 00:15:09 +0200 Subject: [PATCH 07/34] fixup! Add extract variable --- .../it_place_assignment_outside_array.vader | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/extract_variable/it_place_assignment_outside_array.vader b/test/extract_variable/it_place_assignment_outside_array.vader index 35f42da..b6fab4e 100644 --- a/test/extract_variable/it_place_assignment_outside_array.vader +++ b/test/extract_variable/it_place_assignment_outside_array.vader @@ -1,6 +1,8 @@ Given php: 1234, ]; @@ -10,10 +12,12 @@ Do: viw ;ev baz\ - 1\ + 3\ Expect: Date: Sat, 1 Oct 2022 00:24:26 +0200 Subject: [PATCH 08/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 4 ++-- test/extract_variable/on_condition/in_function.vader | 2 +- test/extract_variable/on_condition/outside_function.vader | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 51cb208..ff81b7a 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -259,7 +259,7 @@ function! PhpExtractVariable() " {{{ return endif let l:name = inputdialog("Name of new variable: ") - let l:lineForAssignment = inputdialog("Line of assignment: ") + let l:lineUpwardForAssignment = inputdialog("Line upward for assignment: ") " go to select and copy and delete normal! gvx " add marker @@ -269,7 +269,7 @@ function! PhpExtractVariable() " {{{ " go to start on selection normal! `r " go to line to write assignment - exec 'normal! '.l:lineForAssignment.'gg' + exec 'normal! '.l:lineUpwardForAssignment.'gk' let l:indentChars = indent(line('.')) normal! o " type variable assignment diff --git a/test/extract_variable/on_condition/in_function.vader b/test/extract_variable/on_condition/in_function.vader index f8a1432..f9bb859 100644 --- a/test/extract_variable/on_condition/in_function.vader +++ b/test/extract_variable/on_condition/in_function.vader @@ -17,7 +17,7 @@ Do (select the condition and extract variable): vi( ;ev firstNameIsValid\ - 5\ + 2\ Expect php (variable is extracted): - 3\ + 2\ Expect php (variable is extracted): Date: Sat, 1 Oct 2022 00:30:05 +0200 Subject: [PATCH 09/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 8 ++++-- ...utside_function_using_default_upward.vader | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/extract_variable/on_condition/outside_function_using_default_upward.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index ff81b7a..6ad35bd 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -258,8 +258,12 @@ function! PhpExtractVariable() " {{{ call s:PhpEchoError('Extract variable only works in Visual mode, not in Visual Line or Visual block') return endif - let l:name = inputdialog("Name of new variable: ") - let l:lineUpwardForAssignment = inputdialog("Line upward for assignment: ") + let l:name = inputdialog('Name of new variable: ') + let l:defaultUpwardMove = 2 + let l:lineUpwardForAssignment = inputdialog('Line upward for assignment (default is '.l:defaultUpwardMove.'): ') + if empty(l:lineUpwardForAssignment) + let l:lineUpwardForAssignment = l:defaultUpwardMove + endif " go to select and copy and delete normal! gvx " add marker diff --git a/test/extract_variable/on_condition/outside_function_using_default_upward.vader b/test/extract_variable/on_condition/outside_function_using_default_upward.vader new file mode 100644 index 0000000..c73a923 --- /dev/null +++ b/test/extract_variable/on_condition/outside_function_using_default_upward.vader @@ -0,0 +1,25 @@ +Given php (condition on if): + + vi( + ;ev + firstNameIsValid\ + \ + +Expect php (variable is extracted): + Date: Sat, 1 Oct 2022 00:30:41 +0200 Subject: [PATCH 10/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 6ad35bd..8243cbd 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -258,28 +258,38 @@ function! PhpExtractVariable() " {{{ call s:PhpEchoError('Extract variable only works in Visual mode, not in Visual Line or Visual block') return endif + + " input let l:name = inputdialog('Name of new variable: ') let l:defaultUpwardMove = 2 let l:lineUpwardForAssignment = inputdialog('Line upward for assignment (default is '.l:defaultUpwardMove.'): ') if empty(l:lineUpwardForAssignment) let l:lineUpwardForAssignment = l:defaultUpwardMove endif + " go to select and copy and delete normal! gvx + " add marker normal! mr + " type variable name exec 'normal! i$'.l:name + " go to start on selection normal! `r + " go to line to write assignment exec 'normal! '.l:lineUpwardForAssignment.'gk' let l:indentChars = indent(line('.')) normal! o + " type variable assignment exec 'normal! i'.repeat(' ', l:indentChars).'$'.l:name.' = ' + " paste selection and add semi-colon normal! pa; + " go to start on selection normal! `r endfunction From 3e416c48d52a585620728943c6ee7ef488e9f68a Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 00:35:02 +0200 Subject: [PATCH 11/34] fixup! Add extract variable --- ...utside_function_using_default_upward.vader | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/extract_variable/on_condition/outside_function_using_default_upward.vader b/test/extract_variable/on_condition/outside_function_using_default_upward.vader index c73a923..679e15a 100644 --- a/test/extract_variable/on_condition/outside_function_using_default_upward.vader +++ b/test/extract_variable/on_condition/outside_function_using_default_upward.vader @@ -1,25 +1,17 @@ Given php (condition on if): - vi( + /Hello\ + va' ;ev - firstNameIsValid\ + foo\ \ Expect php (variable is extracted): Date: Sat, 1 Oct 2022 00:44:14 +0200 Subject: [PATCH 12/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 8243cbd..e4a8df9 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -262,7 +262,7 @@ function! PhpExtractVariable() " {{{ " input let l:name = inputdialog('Name of new variable: ') let l:defaultUpwardMove = 2 - let l:lineUpwardForAssignment = inputdialog('Line upward for assignment (default is '.l:defaultUpwardMove.'): ') + let l:lineUpwardForAssignment = inputdialog('Not empty line upward for assignment (default is '.l:defaultUpwardMove.'): ') if empty(l:lineUpwardForAssignment) let l:lineUpwardForAssignment = l:defaultUpwardMove endif From 2943869b03d6b50d95219137291abeebf307fbe7 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 01:25:42 +0200 Subject: [PATCH 13/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index e4a8df9..776b696 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -280,16 +280,35 @@ function! PhpExtractVariable() " {{{ normal! `r " go to line to write assignment - exec 'normal! '.l:lineUpwardForAssignment.'gk' + exec 'normal! '.l:lineUpwardForAssignment.'k' + let l:tab = '' let l:indentChars = indent(line('.')) + let l:needBlankLineAfter = v:false + + if '{' == trim(getline(line('.'))) + let l:currentLine = line('.') + let l:currentCol = col('.') + + call cursor(line('.') + 1, 0) + let l:indentChars = indent(line('.')) + + call cursor(l:currentLine, l:currentCol) + + let l:needBlankLineAfter = v:true + endif + normal! o " type variable assignment - exec 'normal! i'.repeat(' ', l:indentChars).'$'.l:name.' = ' + exec 'normal! i'.repeat(' ', l:indentChars).l:tab.'$'.l:name.' = ' " paste selection and add semi-colon normal! pa; + if l:needBlankLineAfter + normal! o + endif + " go to start on selection normal! `r endfunction From 8455984d26e3c9dd2ec4fef9150084b7dac4fc8a Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 01:31:43 +0200 Subject: [PATCH 14/34] fixup! Add extract variable --- ...on_will_place_on_first_function_line.vader | 32 +++++++++++++++ .../on_condition/in_method.vader | 41 +++++++++++++++++++ ...od_will_place_on_first_function_line.vader | 38 +++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 test/extract_variable/on_condition/in_function_will_place_on_first_function_line.vader create mode 100644 test/extract_variable/on_condition/in_method.vader create mode 100644 test/extract_variable/on_condition/in_method_will_place_on_first_function_line.vader diff --git a/test/extract_variable/on_condition/in_function_will_place_on_first_function_line.vader b/test/extract_variable/on_condition/in_function_will_place_on_first_function_line.vader new file mode 100644 index 0000000..4273c33 --- /dev/null +++ b/test/extract_variable/on_condition/in_function_will_place_on_first_function_line.vader @@ -0,0 +1,32 @@ +Given php (condition on if and on function): + + vi( + ;ev + firstNameIsValid\ + 1\ + +Expect php (variable is extracted): + + vi( + ;ev + firstNameIsValid\ + 2\ + +Expect php (variable is extracted): + + vi( + ;ev + firstNameIsValid\ + 1\ + +Expect php (variable is extracted): + Date: Sat, 1 Oct 2022 01:38:34 +0200 Subject: [PATCH 15/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 776b696..e606c1e 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -280,7 +280,7 @@ function! PhpExtractVariable() " {{{ normal! `r " go to line to write assignment - exec 'normal! '.l:lineUpwardForAssignment.'k' + call cursor(line('.') - l:lineUpwardForAssignment, 0) let l:tab = '' let l:indentChars = indent(line('.')) let l:needBlankLineAfter = v:false From 6f1e39ef2d0c5276f50f0222352a8168b462550d Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:17:15 +0200 Subject: [PATCH 16/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 11 +++++++-- ...side_function_cursor_on_line_comment.vader | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/extract_variable/on_condition/outside_function_cursor_on_line_comment.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index e606c1e..221c7af 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -297,15 +297,22 @@ function! PhpExtractVariable() " {{{ let l:needBlankLineAfter = v:true endif - normal! o + if 1 == l:lineUpwardForAssignment + let l:needBlankLineAfter = v:true + endif " type variable assignment - exec 'normal! i'.repeat(' ', l:indentChars).l:tab.'$'.l:name.' = ' + let l:prefixAssign = repeat(' ', l:indentChars).l:tab.'$'.l:name.' = ' + + call append(line('.'), l:prefixAssign) + call cursor(line('.') + 1, 0) + normal! $ " paste selection and add semi-colon normal! pa; if l:needBlankLineAfter + " call append(line('.') + 1, '') normal! o endif diff --git a/test/extract_variable/on_condition/outside_function_cursor_on_line_comment.vader b/test/extract_variable/on_condition/outside_function_cursor_on_line_comment.vader new file mode 100644 index 0000000..558cef8 --- /dev/null +++ b/test/extract_variable/on_condition/outside_function_cursor_on_line_comment.vader @@ -0,0 +1,24 @@ +Given php (condition on if): + + vi( + ;ev + firstNameIsValid\ + 1\ + +Expect php (variable is extracted): + Date: Sat, 1 Oct 2022 02:18:45 +0200 Subject: [PATCH 17/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 221c7af..627d00d 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -312,8 +312,7 @@ function! PhpExtractVariable() " {{{ normal! pa; if l:needBlankLineAfter - " call append(line('.') + 1, '') - normal! o + call append(line('.'), '') endif " go to start on selection From e33539164ee0b0db674f593bd8a817dfea6eaf5f Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:20:00 +0200 Subject: [PATCH 18/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 627d00d..f9eda44 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -281,7 +281,6 @@ function! PhpExtractVariable() " {{{ " go to line to write assignment call cursor(line('.') - l:lineUpwardForAssignment, 0) - let l:tab = '' let l:indentChars = indent(line('.')) let l:needBlankLineAfter = v:false @@ -302,7 +301,7 @@ function! PhpExtractVariable() " {{{ endif " type variable assignment - let l:prefixAssign = repeat(' ', l:indentChars).l:tab.'$'.l:name.' = ' + let l:prefixAssign = repeat(' ', l:indentChars).'$'.l:name.' = ' call append(line('.'), l:prefixAssign) call cursor(line('.') + 1, 0) From 44cf732859436f7176d522b75013cd872001cd29 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:21:50 +0200 Subject: [PATCH 19/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index f9eda44..4993121 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -302,8 +302,9 @@ function! PhpExtractVariable() " {{{ " type variable assignment let l:prefixAssign = repeat(' ', l:indentChars).'$'.l:name.' = ' - call append(line('.'), l:prefixAssign) + + " move cursor at the after the equal sign call cursor(line('.') + 1, 0) normal! $ From c12fd4574955f0d65c68e4bf4063e6a658610eec Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:29:41 +0200 Subject: [PATCH 20/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 4993121..4fa3ac7 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -296,6 +296,16 @@ function! PhpExtractVariable() " {{{ let l:needBlankLineAfter = v:true endif + if empty(trim(getline(line('.')))) + let l:currentLine = line('.') + let l:currentCol = col('.') + + call cursor(nextnonblank(l:currentLine), 0) + let l:indentChars = indent(line('.')) + + call cursor(l:currentLine, l:currentCol) + endif + if 1 == l:lineUpwardForAssignment let l:needBlankLineAfter = v:true endif From 6723e0fc4efcd675a529434698462ab3f90adfca Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:37:30 +0200 Subject: [PATCH 21/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 4fa3ac7..3b4b5dc 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -279,6 +279,9 @@ function! PhpExtractVariable() " {{{ " go to start on selection normal! `r + let l:startLine = line('.') + let l:startCol = col('.') + " go to line to write assignment call cursor(line('.') - l:lineUpwardForAssignment, 0) let l:indentChars = indent(line('.')) @@ -303,7 +306,9 @@ function! PhpExtractVariable() " {{{ call cursor(nextnonblank(l:currentLine), 0) let l:indentChars = indent(line('.')) - call cursor(l:currentLine, l:currentCol) + call cursor(prevnonblank(l:currentLine), l:currentCol) + + let l:lineUpwardForAssignment = l:currentLine - l:startLine endif if 1 == l:lineUpwardForAssignment From 501ac6816242a9205573c1b85546fc6dd73f2c17 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:37:38 +0200 Subject: [PATCH 22/34] fixup! Add extract variable --- ...ill_use_indent_of_next_nonblank_line.vader | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/extract_variable/on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader diff --git a/test/extract_variable/on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader b/test/extract_variable/on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader new file mode 100644 index 0000000..b78d694 --- /dev/null +++ b/test/extract_variable/on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader @@ -0,0 +1,35 @@ +Given php (condition on if and on function): + + vi( + ;ev + firstNameIsValid\ + 1\ + +Expect php (variable is extracted): + Date: Sat, 1 Oct 2022 02:41:49 +0200 Subject: [PATCH 23/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 3b4b5dc..56c285b 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -261,7 +261,7 @@ function! PhpExtractVariable() " {{{ " input let l:name = inputdialog('Name of new variable: ') - let l:defaultUpwardMove = 2 + let l:defaultUpwardMove = 1 let l:lineUpwardForAssignment = inputdialog('Not empty line upward for assignment (default is '.l:defaultUpwardMove.'): ') if empty(l:lineUpwardForAssignment) let l:lineUpwardForAssignment = l:defaultUpwardMove From eeb589559529285ef5ac817ea02eb0d9e6a633f6 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 02:53:30 +0200 Subject: [PATCH 24/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 2 +- .../inside_block/it_keep_same_indent.vader | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/extract_variable/inside_block/it_keep_same_indent.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 56c285b..d2224bf 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -284,7 +284,7 @@ function! PhpExtractVariable() " {{{ " go to line to write assignment call cursor(line('.') - l:lineUpwardForAssignment, 0) - let l:indentChars = indent(line('.')) + let l:indentChars = indent(nextnonblank(line('.') + 1)) let l:needBlankLineAfter = v:false if '{' == trim(getline(line('.'))) diff --git a/test/extract_variable/inside_block/it_keep_same_indent.vader b/test/extract_variable/inside_block/it_keep_same_indent.vader new file mode 100644 index 0000000..eabdded --- /dev/null +++ b/test/extract_variable/inside_block/it_keep_same_indent.vader @@ -0,0 +1,22 @@ +Given php: + + vi( + ;ev + foo\ + \ + +Expect: + Date: Sat, 1 Oct 2022 02:58:07 +0200 Subject: [PATCH 25/34] fixup! Add extract variable --- ...assignment_outside_for_first_element.vader | 25 +++++++++++++++++++ ...lace_assignment_outside_using_input.vader} | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/extract_variable/on_array_definition/it_place_assignment_outside_for_first_element.vader rename test/extract_variable/{it_place_assignment_outside_array.vader => on_array_definition/it_place_assignment_outside_using_input.vader} (81%) diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_for_first_element.vader b/test/extract_variable/on_array_definition/it_place_assignment_outside_for_first_element.vader new file mode 100644 index 0000000..bdfc956 --- /dev/null +++ b/test/extract_variable/on_array_definition/it_place_assignment_outside_for_first_element.vader @@ -0,0 +1,25 @@ +Given php: + 1234, + ]; + +Do: + /1234\ + viw + ;ev + baz\ + \ + +Expect: + $baz, + ]; diff --git a/test/extract_variable/it_place_assignment_outside_array.vader b/test/extract_variable/on_array_definition/it_place_assignment_outside_using_input.vader similarity index 81% rename from test/extract_variable/it_place_assignment_outside_array.vader rename to test/extract_variable/on_array_definition/it_place_assignment_outside_using_input.vader index b6fab4e..5810c8d 100644 --- a/test/extract_variable/it_place_assignment_outside_array.vader +++ b/test/extract_variable/on_array_definition/it_place_assignment_outside_using_input.vader @@ -4,7 +4,7 @@ Given php: $sentence = 'Hello'; $foo = [ - 'bar' => 1234, + 'bar' => 1234, ]; Do: @@ -21,5 +21,5 @@ Expect: $baz = 1234; $foo = [ - 'bar' => $baz, + 'bar' => $baz, ]; From d0944a22d7deaca74bc9617c6708631b44f5c6e6 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 03:08:57 +0200 Subject: [PATCH 26/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index d2224bf..6c4f348 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -286,6 +286,13 @@ function! PhpExtractVariable() " {{{ call cursor(line('.') - l:lineUpwardForAssignment, 0) let l:indentChars = indent(nextnonblank(line('.') + 1)) let l:needBlankLineAfter = v:false + let l:currentLineContent = trim(getline(line('.'))) + + " line end with [ + if '[' == l:currentLineContent[-1:] + " backward one line + call cursor(line('.') - 1, 0) + endif if '{' == trim(getline(line('.'))) let l:currentLine = line('.') From fbcb4be821b86441b5ccaa55d82cb9849c422713 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 03:13:33 +0200 Subject: [PATCH 27/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 9 +++++-- ...ssignment_outside_for_second_element.vader | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/extract_variable/on_array_definition/it_place_assignment_outside_for_second_element.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 6c4f348..b988726 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -286,10 +286,15 @@ function! PhpExtractVariable() " {{{ call cursor(line('.') - l:lineUpwardForAssignment, 0) let l:indentChars = indent(nextnonblank(line('.') + 1)) let l:needBlankLineAfter = v:false - let l:currentLineContent = trim(getline(line('.'))) + + " line end with , + if ',' == trim(getline(line('.')))[-1:] + " backward one line + call cursor(line('.') - 1, 0) + endif " line end with [ - if '[' == l:currentLineContent[-1:] + if '[' == trim(getline(line('.')))[-1:] " backward one line call cursor(line('.') - 1, 0) endif diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_for_second_element.vader b/test/extract_variable/on_array_definition/it_place_assignment_outside_for_second_element.vader new file mode 100644 index 0000000..fc7bd81 --- /dev/null +++ b/test/extract_variable/on_array_definition/it_place_assignment_outside_for_second_element.vader @@ -0,0 +1,27 @@ +Given php: + 42, + 'bar' => 1234, + ]; + +Do: + /1234\ + viw + ;ev + baz\ + \ + +Expect: + 42, + 'bar' => $baz, + ]; From 331a6eec278d4a60f22cc4875901030d20a7995d Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 03:14:53 +0200 Subject: [PATCH 28/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index b988726..184ae53 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -288,10 +288,10 @@ function! PhpExtractVariable() " {{{ let l:needBlankLineAfter = v:false " line end with , - if ',' == trim(getline(line('.')))[-1:] + while ',' == trim(getline(line('.')))[-1:] " backward one line call cursor(line('.') - 1, 0) - endif + endwhile " line end with [ if '[' == trim(getline(line('.')))[-1:] From 6ecef6479e63bffcf7592442d8c11943750b32b9 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 03:15:59 +0200 Subject: [PATCH 29/34] fixup! Add extract variable --- ...assignment_outside_for_third_element.vader | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/extract_variable/on_array_definition/it_place_assignment_outside_for_third_element.vader diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_for_third_element.vader b/test/extract_variable/on_array_definition/it_place_assignment_outside_for_third_element.vader new file mode 100644 index 0000000..89653e4 --- /dev/null +++ b/test/extract_variable/on_array_definition/it_place_assignment_outside_for_third_element.vader @@ -0,0 +1,29 @@ +Given php: + 42, + 'foo' => 12, + 'bar' => 1234, + ]; + +Do: + /1234\ + viw + ;ev + baz\ + \ + +Expect: + 42, + 'foo' => 12, + 'bar' => $baz, + ]; From 8935547ffcdc7c15f18fdca4b6ecd11eacb25b97 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 03:22:27 +0200 Subject: [PATCH 30/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 16 ++-------- ...ne_will_place_on_first_function_line.vader | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 test/extract_variable/on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 184ae53..7d15d8c 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -287,30 +287,18 @@ function! PhpExtractVariable() " {{{ let l:indentChars = indent(nextnonblank(line('.') + 1)) let l:needBlankLineAfter = v:false - " line end with , + " line ends with , while ',' == trim(getline(line('.')))[-1:] " backward one line call cursor(line('.') - 1, 0) endwhile - " line end with [ + " line ends with [ if '[' == trim(getline(line('.')))[-1:] " backward one line call cursor(line('.') - 1, 0) endif - if '{' == trim(getline(line('.'))) - let l:currentLine = line('.') - let l:currentCol = col('.') - - call cursor(line('.') + 1, 0) - let l:indentChars = indent(line('.')) - - call cursor(l:currentLine, l:currentCol) - - let l:needBlankLineAfter = v:true - endif - if empty(trim(getline(line('.')))) let l:currentLine = line('.') let l:currentCol = col('.') diff --git a/test/extract_variable/on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader b/test/extract_variable/on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader new file mode 100644 index 0000000..3713496 --- /dev/null +++ b/test/extract_variable/on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader @@ -0,0 +1,30 @@ +Given php (condition on if and on function): + + vi( + ;ev + firstNameIsValid\ + 1\ + +Expect php (variable is extracted): + Date: Sat, 1 Oct 2022 03:22:58 +0200 Subject: [PATCH 31/34] fixup! Add extract variable --- ...ne_will_place_on_first_function_line.vader | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/extract_variable/on_condition/in_function_with_open_brace_alone_on_line_will_place_on_first_function_line.vader diff --git a/test/extract_variable/on_condition/in_function_with_open_brace_alone_on_line_will_place_on_first_function_line.vader b/test/extract_variable/on_condition/in_function_with_open_brace_alone_on_line_will_place_on_first_function_line.vader new file mode 100644 index 0000000..4273c33 --- /dev/null +++ b/test/extract_variable/on_condition/in_function_with_open_brace_alone_on_line_will_place_on_first_function_line.vader @@ -0,0 +1,32 @@ +Given php (condition on if and on function): + + vi( + ;ev + firstNameIsValid\ + 1\ + +Expect php (variable is extracted): + Date: Sat, 1 Oct 2022 03:46:32 +0200 Subject: [PATCH 32/34] fixup! Add extract variable --- plugin/php-refactoring-toolbox.vim | 2 +- .../first_element.vader} | 0 .../second_element.vader} | 0 .../third_element.vader} | 0 .../with_upward_target_before_array.vader} | 0 ...function_line_with_open_brace_alone.vader} | 0 ..._with_open_brace_at_the_end_of_line.vader} | 0 .../with_blank_target_line.vader} | 0 .../inside_function/with_upward_target.vader} | 0 .../inside_method/at_middle.vader} | 0 .../inside_method/on_top.vader} | 0 .../outside_function/at_middle.vader} | 0 .../using_custom_target_line.vader | 25 +++++++++++++++ .../using_default_target_line.vader | 25 +++++++++++++++ .../with_target_line_is_line_comment.vader} | 0 ...ne_will_place_on_first_function_line.vader | 32 ------------------- ...utside_function_using_default_upward.vader | 17 ---------- 17 files changed, 51 insertions(+), 50 deletions(-) rename test/extract_variable/{on_array_definition/it_place_assignment_outside_for_first_element.vader => from_array_definition/first_element.vader} (100%) rename test/extract_variable/{on_array_definition/it_place_assignment_outside_for_second_element.vader => from_array_definition/second_element.vader} (100%) rename test/extract_variable/{on_array_definition/it_place_assignment_outside_for_third_element.vader => from_array_definition/third_element.vader} (100%) rename test/extract_variable/{on_array_definition/it_place_assignment_outside_using_input.vader => from_array_definition/with_upward_target_before_array.vader} (100%) rename test/extract_variable/{on_condition/in_function_will_place_on_first_function_line.vader => from_condition/inside_function/will_place_on_first_function_line_with_open_brace_alone.vader} (100%) rename test/extract_variable/{on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader => from_condition/inside_function/will_place_on_first_function_line_with_open_brace_at_the_end_of_line.vader} (100%) rename test/extract_variable/{on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader => from_condition/inside_function/with_blank_target_line.vader} (100%) rename test/extract_variable/{on_condition/in_function.vader => from_condition/inside_function/with_upward_target.vader} (100%) rename test/extract_variable/{on_condition/in_method.vader => from_condition/inside_method/at_middle.vader} (100%) rename test/extract_variable/{on_condition/in_method_will_place_on_first_function_line.vader => from_condition/inside_method/on_top.vader} (100%) rename test/extract_variable/{on_condition/outside_function.vader => from_condition/outside_function/at_middle.vader} (100%) create mode 100644 test/extract_variable/from_condition/outside_function/using_custom_target_line.vader create mode 100644 test/extract_variable/from_condition/outside_function/using_default_target_line.vader rename test/extract_variable/{on_condition/outside_function_cursor_on_line_comment.vader => from_condition/outside_function/with_target_line_is_line_comment.vader} (100%) delete mode 100644 test/extract_variable/on_condition/in_function_with_open_brace_alone_on_line_will_place_on_first_function_line.vader delete mode 100644 test/extract_variable/on_condition/outside_function_using_default_upward.vader diff --git a/plugin/php-refactoring-toolbox.vim b/plugin/php-refactoring-toolbox.vim index 7d15d8c..b4f63c1 100644 --- a/plugin/php-refactoring-toolbox.vim +++ b/plugin/php-refactoring-toolbox.vim @@ -262,7 +262,7 @@ function! PhpExtractVariable() " {{{ " input let l:name = inputdialog('Name of new variable: ') let l:defaultUpwardMove = 1 - let l:lineUpwardForAssignment = inputdialog('Not empty line upward for assignment (default is '.l:defaultUpwardMove.'): ') + let l:lineUpwardForAssignment = inputdialog('Line upward for assignment (default is '.l:defaultUpwardMove.'): ') if empty(l:lineUpwardForAssignment) let l:lineUpwardForAssignment = l:defaultUpwardMove endif diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_for_first_element.vader b/test/extract_variable/from_array_definition/first_element.vader similarity index 100% rename from test/extract_variable/on_array_definition/it_place_assignment_outside_for_first_element.vader rename to test/extract_variable/from_array_definition/first_element.vader diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_for_second_element.vader b/test/extract_variable/from_array_definition/second_element.vader similarity index 100% rename from test/extract_variable/on_array_definition/it_place_assignment_outside_for_second_element.vader rename to test/extract_variable/from_array_definition/second_element.vader diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_for_third_element.vader b/test/extract_variable/from_array_definition/third_element.vader similarity index 100% rename from test/extract_variable/on_array_definition/it_place_assignment_outside_for_third_element.vader rename to test/extract_variable/from_array_definition/third_element.vader diff --git a/test/extract_variable/on_array_definition/it_place_assignment_outside_using_input.vader b/test/extract_variable/from_array_definition/with_upward_target_before_array.vader similarity index 100% rename from test/extract_variable/on_array_definition/it_place_assignment_outside_using_input.vader rename to test/extract_variable/from_array_definition/with_upward_target_before_array.vader diff --git a/test/extract_variable/on_condition/in_function_will_place_on_first_function_line.vader b/test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_alone.vader similarity index 100% rename from test/extract_variable/on_condition/in_function_will_place_on_first_function_line.vader rename to test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_alone.vader diff --git a/test/extract_variable/on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader b/test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_at_the_end_of_line.vader similarity index 100% rename from test/extract_variable/on_condition/in_function_with_open_brace_at_the_end_of_line_will_place_on_first_function_line.vader rename to test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_at_the_end_of_line.vader diff --git a/test/extract_variable/on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader b/test/extract_variable/from_condition/inside_function/with_blank_target_line.vader similarity index 100% rename from test/extract_variable/on_condition/in_function_with_cursor_on_blank_line_will_use_indent_of_next_nonblank_line.vader rename to test/extract_variable/from_condition/inside_function/with_blank_target_line.vader diff --git a/test/extract_variable/on_condition/in_function.vader b/test/extract_variable/from_condition/inside_function/with_upward_target.vader similarity index 100% rename from test/extract_variable/on_condition/in_function.vader rename to test/extract_variable/from_condition/inside_function/with_upward_target.vader diff --git a/test/extract_variable/on_condition/in_method.vader b/test/extract_variable/from_condition/inside_method/at_middle.vader similarity index 100% rename from test/extract_variable/on_condition/in_method.vader rename to test/extract_variable/from_condition/inside_method/at_middle.vader diff --git a/test/extract_variable/on_condition/in_method_will_place_on_first_function_line.vader b/test/extract_variable/from_condition/inside_method/on_top.vader similarity index 100% rename from test/extract_variable/on_condition/in_method_will_place_on_first_function_line.vader rename to test/extract_variable/from_condition/inside_method/on_top.vader diff --git a/test/extract_variable/on_condition/outside_function.vader b/test/extract_variable/from_condition/outside_function/at_middle.vader similarity index 100% rename from test/extract_variable/on_condition/outside_function.vader rename to test/extract_variable/from_condition/outside_function/at_middle.vader diff --git a/test/extract_variable/from_condition/outside_function/using_custom_target_line.vader b/test/extract_variable/from_condition/outside_function/using_custom_target_line.vader new file mode 100644 index 0000000..208a542 --- /dev/null +++ b/test/extract_variable/from_condition/outside_function/using_custom_target_line.vader @@ -0,0 +1,25 @@ +Given php (condition on if): + + vi( + ;ev + foo\ + 2\ + +Expect php (variable is extracted): + + vi( + ;ev + foo\ + \ + +Expect php (variable is extracted): + - vi( - ;ev - firstNameIsValid\ - 1\ - -Expect php (variable is extracted): - - va' - ;ev - foo\ - \ - -Expect php (variable is extracted): - Date: Sat, 1 Oct 2022 03:51:25 +0200 Subject: [PATCH 33/34] fixup! Add extract variable --- ...get_before_array.vader => with_target_line_before_array.vader} | 0 .../with_open_brace_alone.vader} | 0 .../with_open_brace_at_the_end_of_line.vader} | 0 ...r => with_target_line_on_another_assignment_just_before.vader} | 0 ...r => with_target_line_on_another_assignment_just_before.vader} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename test/extract_variable/from_array_definition/{with_upward_target_before_array.vader => with_target_line_before_array.vader} (100%) rename test/extract_variable/from_condition/inside_function/{will_place_on_first_function_line_with_open_brace_alone.vader => on_top/with_open_brace_alone.vader} (100%) rename test/extract_variable/from_condition/inside_function/{will_place_on_first_function_line_with_open_brace_at_the_end_of_line.vader => on_top/with_open_brace_at_the_end_of_line.vader} (100%) rename test/extract_variable/from_condition/inside_function/{with_upward_target.vader => with_target_line_on_another_assignment_just_before.vader} (100%) rename test/extract_variable/from_condition/outside_function/{using_custom_target_line.vader => with_target_line_on_another_assignment_just_before.vader} (100%) diff --git a/test/extract_variable/from_array_definition/with_upward_target_before_array.vader b/test/extract_variable/from_array_definition/with_target_line_before_array.vader similarity index 100% rename from test/extract_variable/from_array_definition/with_upward_target_before_array.vader rename to test/extract_variable/from_array_definition/with_target_line_before_array.vader diff --git a/test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_alone.vader b/test/extract_variable/from_condition/inside_function/on_top/with_open_brace_alone.vader similarity index 100% rename from test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_alone.vader rename to test/extract_variable/from_condition/inside_function/on_top/with_open_brace_alone.vader diff --git a/test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_at_the_end_of_line.vader b/test/extract_variable/from_condition/inside_function/on_top/with_open_brace_at_the_end_of_line.vader similarity index 100% rename from test/extract_variable/from_condition/inside_function/will_place_on_first_function_line_with_open_brace_at_the_end_of_line.vader rename to test/extract_variable/from_condition/inside_function/on_top/with_open_brace_at_the_end_of_line.vader diff --git a/test/extract_variable/from_condition/inside_function/with_upward_target.vader b/test/extract_variable/from_condition/inside_function/with_target_line_on_another_assignment_just_before.vader similarity index 100% rename from test/extract_variable/from_condition/inside_function/with_upward_target.vader rename to test/extract_variable/from_condition/inside_function/with_target_line_on_another_assignment_just_before.vader diff --git a/test/extract_variable/from_condition/outside_function/using_custom_target_line.vader b/test/extract_variable/from_condition/outside_function/with_target_line_on_another_assignment_just_before.vader similarity index 100% rename from test/extract_variable/from_condition/outside_function/using_custom_target_line.vader rename to test/extract_variable/from_condition/outside_function/with_target_line_on_another_assignment_just_before.vader From d6163541f742aa0c08e7ab00ed57e257301dec27 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Sat, 1 Oct 2022 21:39:46 +0200 Subject: [PATCH 34/34] fixup! Add extract variable --- README.md | 12 ++++-------- doc/refactoring-toolbox.txt | 11 ++++------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 70173a7..65e0c96 100644 --- a/README.md +++ b/README.md @@ -258,10 +258,8 @@ class HelloWorld {