8000 Merge remote-tracking branch 'origin/develop' into lieryan-in-hierarchy · python-mode/python-mode@2b047c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b047c2

Browse files
committed
Merge remote-tracking branch 'origin/develop' into lieryan-in-hierarchy
2 parents 41ed4df + 71a7f08 commit 2b047c2

File tree

17 files changed

+191
-57
lines changed

17 files changed

+191
-57
lines changed

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@
4848
[submodule "submodules/toml"]
4949
path = submodules/toml
5050
url = https://github.com/uiri/toml.git
51+
[submodule "submodules/pytoolconfig"]
52+
path = submodules/pytoolconfig
53+
url = https://github.com/bagel897/pytoolconfig.git
54+
[submodule "submodules/tomli"]
55+
path = submodules/tomli
56+
url = https://github.com/hukkin/tomli.git
57+
[submodule "submodules/appdirs"]
58+
path = submodules/appdirs
59+
url = https://github.com/ActiveState/appdirs.git

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ Contributors:
7575
* Yury A. Kartynnik (https://github.com/kartynnik);
7676
* Xiangyu Xu (https://github.com/bkbncn);
7777
* Zach Himsel (https://github.com/zhimsel);
78+
* Nathan Pemberton (https://github.com/NathanTP);

after/ftplugin/python.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ if g:pymode_motion
4242
vnoremap <buffer> aM :<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@', '^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
4343
vnoremap <buffer> iM :<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@', '^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 1)<CR>
4444
45+
onoremap <buffer> V :<C-U>call pymode#rope#select_logical_line()<CR>
46+
4547
endif
4648

4749
if g:pymode_rope && g:pymode_rope_completion

autoload/pymode/rope.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,7 @@ fun! pymode#rope#generate_package() "{{{
194194
endif
195195
PymodePython rope.GenerateElementRefactoring('package').run()
196196
endfunction "}}}
197+
198+
fun! pymode#rope#select_logical_line() "{{{
199+
PymodePython rope.select_logical_line()
200+
endfunction "}}}

doc/pymode.txt

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ Key Command
209209
]] Jump to next class or function (normal, visual, operator modes)
210210
[M Jump to previous class or method (normal, visual, operator modes)
211211
]M Jump to next class or method (normal, visual, operator modes)
212-
aC Select a class. Ex: vaC, daC, yaC, caC (normal, operator modes)
213-
iC Select inner class. Ex: viC, diC, yiC, ciC (normal, operator modes)
214-
aM Select a function or method. Ex: vaM, daM, yaM, caM (normal, operator modes)
215-
iM Select inner function or method. Ex: viM, diM, yiM, ciM (normal, operator modes)
212+
aC Select a class. Ex: vaC, daC, yaC, caC (operator modes)
213+
iC Select inner class. Ex: viC, diC, yiC, ciC (operator modes)
214+
aM Select a function or method. Ex: vaM, daM, yaM, caM (operator modes)
215+
iM Select inner function or method. Ex: viM, diM, yiM, ciM (operator modes)
216+
V Select logical line. Ex: dV, yV, cV (operator modes), also works with count
216217
==== ============================
217218

218219
Enable pymode-motion *'g:pymode_motion'*
@@ -423,6 +424,10 @@ Turn on the rope script *'g:pymode_rope'
423424
>
424425
let g:pymode_rope = 1
425426
427+
Set the prefix for rope commands *'g:pymode_rope_prefix'*
428+
>
429+
let g:pymode_rope_refix = '<C-c>'
430+
426431
.ropeproject Folder ~
427432
*.ropeproject*
428433

@@ -613,14 +618,31 @@ code to call it instead.
613618
let g:pymode_rope_use_function_bind = '<C-c>ru'
614619
615620
616-
Move method/fields ~
621+
Move refactoring ~
617622
*pymode-rope-move*
618623

624+
Moving method/fields
625+
619626
It happens when you perform move refactoring on a method of a class. In this
620627
refactoring, a method of a class is moved to the class of one of its
621628
attributes. The old method will call the new method. If you want to change all
622629
of the occurrences of the old method to use the new method you can inline it
623630
afterwards.
631+
632+
Moving global variable/class/function into another module
633+
634+
It happens when you perform move refactoring on global variable/class/function.
635+
In this refactoring, the object being refactored will be moved to a destination
636+
module. All references to the object being moved will be updated to point to
637+
the new location.
638+
639+
Moving module variable/class/function into a package
640+
641+
It happens when you perform move refactoring on a name referencing a module.
642+
In this refactoring, the module being refactored will be moved to a destination
643+
package. All references to the object being moved will be updated to point to
644+
the new location.
645+
624646
>
625647
let g:pymode_rope_move_bind = '<C-c>rv'
626648
@@ -670,6 +692,10 @@ Highlight '=' operator *'g:pymode_syntax_highlight_equal_operator'
670692
>
671693
let g:pymode_syntax_highlight_equal_operator = g:pymode_syntax_all
672694
695+
Highlight ':=' operator *'g:pymode_syntax_highlight_walrus_operator'*
696+
>
697+
let g:pymode_syntax_highlight_walrus_operator = g:pymode_syntax_all
698+
673699
Highlight '*' operator *'g:pymode_syntax_highlight_stars_operator'*
674700
>
675701
let g:pymode_syntax_highlight_stars_operator = g:pymode_syntax_all

plugin/pymode.vim

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
" vi: fdl=1
22
let g:pymode_version = "0.13.0"
33

4+
45
" Enable pymode by default :)
56
call pymode#default('g:pymode', 1)
67
call pymode#default('g:pymode_debug', 0)
@@ -185,6 +186,7 @@ call pymode#default('g:pymode_breakpoint_cmd', '')
185186
"
186187
" Rope support
187188
call pymode#default('g:pymode_rope', 0)
189+
call pymode#default('g:pymode_rope_prefix', '<C-c>')
188190

189191
" System plugin variable
190192
if g:pymode_rope
@@ -213,7 +215,7 @@ if g:pymode_rope
213215
call pymode#default('g:pymode_rope_autoimport_modules', ['os', 'shutil', 'datetime'])
214216

215217
" Bind keys to autoimport module for object under cursor
216-
call pymode#default('g:pymode_rope_autoimport_bind', '<C-c>ra')
218+
call pymode#default('g:pymode_rope_autoimport_bind', g:pymode_rope_prefix . 'ra')
217219

218220
" Automatic completion on dot
219221
call pymode#default('g:pymode_rope_complete_on_dot', 1)
@@ -222,56 +224,56 @@ if g:pymode_rope
222224
call pymode#default('g:pymode_rope_completion_bind', '<C-Space>')
223225

224226
" Bind keys for goto definition (leave empty for disable)
225-
call pymode#default('g:pymode_rope_goto_definition_bind', '<C-c>g')
227+
call pymode#default('g:pymode_rope_goto_definition_bind', g:pymode_rope_prefix . 'g')
226228

227229
" set command for open definition (e, new, vnew)
228230
call pymode#default('g:pymode_rope_goto_definition_cmd', 'new')
229231

230232
" Bind keys for show documentation (leave empty for disable)
231-
call pymode#default('g:pymode_rope_show_doc_bind', '<C-c>d')
233+
call pymode#default('g:pymode_rope_show_doc_bind', g:pymode_rope_prefix . 'd')
232234

233235
" Bind keys for find occurencies (leave empty for disable)
234-
call pymode#default('g:pymode_rope_find_it_bind', '<C-c>f')
236+
call pymode#default('g:pymode_rope_find_it_bind', g:pymode_rope_prefix . 'f')
235237

236238
" Bind keys for organize imports (leave empty for disable)
237-
call pymode#default('g:pymode_rope_organize_imports_bind', '<C-c>ro' F438 )
239+
call pymode#default('g:pymode_rope_organize_imports_bind', g:pymode_rope_prefix . 'ro')
238240

239241
" Bind keys for rename variable/method/class in the project (leave empty for disable)
240-
call pymode#default('g:pymode_rope_rename_bind', '<C-c>rr')
242+
call pymode#default('g:pymode_rope_rename_bind', g:pymode_rope_prefix . 'rr')
241243

242244
" Bind keys for rename module
243-
call pymode#default('g:pymode_rope_rename_module_bind', '<C-c>r1r')
245+
call pymode#default('g:pymode_rope_rename_module_bind', g:pymode_rope_prefix . 'r1r')
244246

245247
" Bind keys for convert module to package
246-
call pymode#default('g:pymode_rope_module_to_package_bind', '<C-c>r1p')
248+
call pymode#default('g:pymode_rope_module_to_package_bind', g:pymode_rope_prefix . 'r1p')
247249

248250
" Creates a new function or method (depending on the context) from the selected lines
249-
call pymode#default('g:pymode_rope_extract_method_bind', '<C-c>rm')
251+
call pymode#default('g:pymode_rope_extract_method_bind', g:pymode_rope_prefix . 'rm')
250252

251253
" Creates a variable from the selected lines
252-
call pymode#default('g:pymode_rope_extract_variable_bind', '<C-c>rl')
254+
call pymode#default('g:pymode_rope_extract_variable_bind', g:pymode_rope_prefix . 'rl')
253255

254256
" Inline refactoring
255-
call pymode#default('g:pymode_rope_inline_bind', '<C-c>ri')
257+
call pymode#default('g:pymode_rope_inline_bind', g:pymode_rope_prefix . 'ri')
256258

257259
" Move refactoring
258-
call pymode#default('g:pymode_rope_move_bind', '<C-c>rv')
260+
call pymode#default('g:pymode_rope_move_bind', g:pymode_rope_prefix . 'rv')
259261

260262
" Generate function
261-
call pymode#default('g:pymode_rope_generate_function_bind', '<C-c>rnf')
263+
call pymode#default('g:pymode_rope_generate_function_bind', g:pymode_rope_prefix . 'rnf')
262264

263265
" Generate class
264-
call pymode#default('g:pymode_rope_generate_class_bind', '<C-c>rnc')
266+
call pymode#default('g:pymode_rope_generate_class_bind', g:pymode_rope_prefix . 'rnc')
265267

266268
" Generate package
267-
call pymode#default('g:pymode_rope_generate_package_bind', '<C-c>rnp')
269+
call pymode#default('g:pymode_rope_generate_package_bind', g:pymode_rope_prefix . 'rnp')
268270

269271
" Change signature
270-
call pymode#default('g:pymode_rope_change_signature_bind', '<C-c>rs')
272+
call pymode#default('g:pymode_rope_change_signature_bind', g:pymode_rope_prefix . 'rs')
271273

272274
" Tries to find the places in which a function can be used and changes the
273275
" code to call it instead
274-
call pymode#default('g:pymode_rope_use_function_bind', '<C-c>ru')
276+
call pymode#default('g:pymode_rope_use_function_bind', g:pymode_rope_prefix . 'ru')
275277

276278
" Regenerate project cache on every save
277279
call pymode#default('g:pymode_rope_regenerate_on_write', 1)

pymode/environment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,8 @@ def goto_buffer(bufnr):
242242
if str(bufnr) != '-1':
243243
vim.command('buffer %s' % bufnr)
244244

245+
def select_line(self, start, end):
246+
vim.command('normal %sggV%sgg' % (start, end))
247+
245248

246249
env = VimPymodeEnviroment()

pymode/libs/appdirs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../submodules/appdirs/appdirs.py

pymode/libs/pytoolconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../submodules/pytoolconfig/pytoolconfig/

pymode/libs/tomli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../submodules/tomli/src/tomli

pymode/rope.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import site
66
import sys
77

8-
from rope.base import project, libutils, exceptions, change, worder, pycore
8+
from rope.base import project, libutils, exceptions, change, worder, pycore, codeanalyze
99
from rope.base.fscommands import FileSystemCommands # noqa
1010
from rope.base.taskhandle import TaskHandle # noqa
1111
from rope.contrib import autoimport as rope_autoimport, codeassist, findit, generate # noqa
@@ -716,13 +716,14 @@ def get_refactor(ctx):
716716
offset = None
717717
return move.create_move(ctx.project, ctx.resource, offset)
718718

719-
def get_code_actions(self):
720-
return [
721-
'perform',
722-
'preview',
723-
'perform in class hierarchy',
724-
'preview in class hierarchy',
725-
]
719+
@staticmethod
720+
def get_changes(refactor, input_str, in_hierarchy=False):
721+
with RopeContext() as ctx:
722+
if isinstance(refactor, (move.MoveGlobal, move.MoveModule)):
723+
dest = ctx.project.pycore.find_module(input_str)
724+
else:
725+
dest = input_str
726+
return super(MoveRefactoring, MoveRefactoring).get_changes(refactor, dest)
726727

727728

728729
class ChangeSignatureRefactoring(Refactoring):
@@ -952,6 +953,22 @@ def _insert_import(name, module, ctx):
952953
reload_changes(changes)
953954

954955

956+
@env.catch_exceptions
957+
def select_logical_line():
958+
source, offset = env.get_offset_params()
959+
count = int(env.var('v:count1'))
960+
961+
lines = codeanalyze.SourceLinesAdapter(source)
962+
start_line = lines.get_line_number(offset)
963+
line_finder = codeanalyze.LogicalLineFinder(lines)
964+
965+
start_lineno, end_lineno = line_finder.logical_line_in(start_line)
966+
for _, (_, end_lineno) in zip(range(count), line_finder.generate_regions(start_lineno)):
967+
pass
968+
969+
env.select_line(start_lineno, end_lineno)
970+
971+
955972
# Monkey patch Rope
956973
def find_source_folders(self, folder):
957974
"""Look only python files an packages."""

submodules/appdirs

Submodule appdirs added at 193a2cb

submodules/pytoolconfig

Submodule pytoolconfig added at 549787f

submodules/rope

Submodule rope updated 166 files

submodules/tomli

Submodule tomli added at 7e563ee

0 commit comments

Comments
 (0)
0