@@ -91,10 +91,8 @@ def open_project(self, root=None):
9191 if not self .env .y_or_n ('Project not exists in %s, create one?' % root ):
9292 self .env .message ("Project creation aborted" )
9393 return
94-
9594 progress = self .env .create_progress ('Opening [%s] project' % root )
9695 self .project = rope .base .project .Project (root )
97-
9896 if self .env .get ('enable_autoimport' ):
9997 underlined = self .env .get ('autoimport_underlineds' )
10098 self .autoimport = autoimport .AutoImport (self .project ,
@@ -182,21 +180,24 @@ def _base_definition_location(self):
182180 @decorators .local_command ('a d' , 'P' , 'C-c d' )
183181 def show_doc (self , prefix ):
184182 self ._check_project ()
185- self ._base_show_doc (prefix , codeassist .get_doc )
183+ self ._base_show_doc (prefix , self . _base_get_doc ( codeassist .get_doc ) )
186184
187- @decorators .local_command ('a c' , 'P' )
188- def show_calltip (self , prefix ):
185+ @decorators .local_command ()
186+ def get_calltip (self ):
189187 self ._check_project ()
190188 def _get_doc (project , text , offset , * args , ** kwds ):
191189 try :
192190 offset = text .rindex ('(' , 0 , offset ) - 1
193191 except ValueError :
194192 return None
195193 return codeassist .get_calltip (project , text , offset , * args , ** kwds )
196- self ._base_show_doc ( prefix , _get_doc )
194+ return self ._base_get_doc ( _get_doc )
197195
198- def _base_show_doc (self , prefix , get_doc ):
199- docs = self ._base_get_doc (get_doc )
196+ @decorators .local_command ('a c' , 'P' )
197+ def show_calltip (self , prefix ):
198+ self ._base_show_doc (prefix , self .get_calltip ())
199+
200+ def _base_show_doc (self , prefix , docs ):
200201 if docs :
201202 self .env .show_doc (docs , prefix )
202203 else :
@@ -302,31 +303,29 @@ def _check_autoimport(self):
302303
303304 @decorators .global_command ('g' )
304305 def generate_autoimport_cache (self ):
305-
306306 if not self ._check_autoimport ():
307307 return
308-
309308 modules = self .env .get ('autoimport_modules' )
310309 modules = [ m if isinstance (m , basestring ) else m .value () for m in modules ]
311310
312- def gen (handle ):
311+ def generate (handle ):
313312 self .autoimport .generate_cache (task_handle = handle )
314313 self .autoimport .generate_modules_cache (modules , task_handle = handle )
315314
316- refactor .runtask (self .env , gen , 'Generate autoimport cache' )
315+ refactor .runtask (self .env , generate , 'Generate autoimport cache' )
317316 self .write_project ()
318317
319318 @decorators .global_command ('f' , 'P' )
320319 def find_file (self , prefix ):
321- f = self ._base_find_file (prefix )
322- if f is not None :
323- self .env .find_file (f .real_path )
320+ file = self ._base_find_file (prefix )
321+ if file is not None :
322+ self .env .find_file (file .real_path )
324323
325324 @decorators .global_command ('4 f' , 'P' )
326325 def find_file_other_window (self , prefix ):
327- f = self ._base_find_file (prefix )
328- if f is not None :
329- self .env .find_file (f .real_path , other = True )
326+ file = self ._base_find_file (prefix )
327+ if file is not None :
328+ self .env .find_file (file .real_path , other = True )
330329
331330 def _base_find_file (self , prefix ):
332331 self ._check_project ()
@@ -338,14 +337,14 @@ def _base_find_file(self, prefix):
338337
339338 def _ask_file (self , files ):
340339 names = []
341- for f in files :
342- names .append ('<' .join (reversed (f .path .split ('/' ))))
340+ for file in files :
341+ names .append ('<' .join (reversed (file .path .split ('/' ))))
343342 result = self .env .ask_values ('Rope Find File: ' , names )
344343 if result is not None :
345344 path = '/' .join (reversed (result .split ('<' )))
346- f = self .project .get_file (path )
347- return f
348- self .env .message ('No f selected' )
345+ file = self .project .get_file (path )
346+ return file
347+ self .env .message ('No file selected' )
349348
350349 @decorators .local_command ('a j' )
351350 def jump_to_global (self ):
@@ -464,6 +463,13 @@ def resource(self):
464463 if resource and resource .exists ():
465464 return resource
466465
466+ @decorators .global_command ()
467+ def get_project_root (self ):
468+ if self .project is not None :
469+ return self .project .root .real_path
470+ else :
471+ return None
472+
467473 def _check_project (self ):
468474 if self .project is None :
469475 if self .env .get ('guess_project' ):
@@ -490,12 +496,10 @@ def _reload_buffers(self, changes, undo=False):
490496 changes .get_changed_resources (),
491497 self ._get_moved_resources (changes , undo ))
492498
493- def _reload_buffers_for_changes (self , changed , moved = None ):
494- if moved is None :
495- moved = dict ()
496-
499+ def _reload_buffers_for_changes (self , changed , moved = {}):
497500 filenames = [resource .real_path for resource in changed ]
498- moved = dict ((resource .real_path , moved [resource ].real_path ) for resource in moved )
501+ moved = dict ([(resource .real_path , moved [resource ].real_path )
502+ for resource in moved ])
499503 self .env .reload_files (filenames , moved )
500504
501505 def _get_moved_resources (self , changes , undo = False ):
@@ -595,7 +599,6 @@ def lucky_assist(self, prefix):
595599 self ._apply_assist (result )
596600
597601 def auto_import (self ):
598-
599602 if not self .interface ._check_autoimport ():
600603 return
601604
@@ -604,7 +607,6 @@ def auto_import(self):
604607
605608 name = self .env .current_word ()
606609 modules = self .autoimport .get_modules (name )
607-
608610 if modules :
609611 if len (modules ) == 1 :
610612 module = modules [0 ]
@@ -644,7 +646,7 @@ def _calculate_proposals(self):
644646 proposals = codeassist .code_assist (
645647 self .interface .project , self .source , self .offset ,
646648 resource , maxfixes = maxfixes )
647- if self .env .get ('sorted_completions' ):
649+ if self .env .get ('sorted_completions' , True ):
648650 proposals = codeassist .sorted_proposals (proposals )
649651 if self .autoimport is not None :
650652 if self .starting .strip () and '.' not in self .expression :
0 commit comments