Commits

Anonymous committed 91d0e7b

introduced "local_function" decorator, which is similar to local_command,
but suppresses exceptions. methods definition_location, get_calltip,
get_doc, completions, extended_completions now use it.

thanks Anton Beloglazov for patch

Comments (0)

Files changed (2)

ropemode/decorators.py

                     exceptions.ModuleSyntaxError,
                     exceptions.BadIdentifierError)
 
-def _exception_handler(func):
+def _exception_handler(func, raise_exceptions, error_return):
     def newfunc(*args, **kwds):
         try:
             return func(*args, **kwds)
         except exceptions.RopeError, e:
             short = None
             if isinstance(e, input_exceptions):
+                if not raise_exceptions:
+                    return error_return
                 short = _exception_message(e)
             logger(str(traceback.format_exc()), short)
     newfunc.__name__ = func.__name__
         return func
     return decorator
 
-
-def local_command(key=None, prefix=False, shortcut=None, name=None):
+def local_command(key=None, prefix=False, shortcut=None,
+                  name=None, raise_exceptions=True,
+                  error_return=None):
     def decorator(func, name=name):
-        func = _exception_handler(func)
+        func = _exception_handler(func, raise_exceptions,
+                                  error_return)
         func.kind = 'local'
         func.prefix = prefix
         func.local_key = key
         return func
     return decorator
 
+def local_function(error_return=None):
+       return local_command(raise_exceptions=False,
+                            error_return=error_return)
 
-def global_command(key=None, prefix=False):
+def global_command(key=None, prefix=False, raise_exceptions=True,
+                   error_return=None):
     def decorator(func):
-        func = _exception_handler(func)
+        func = _exception_handler(func, raise_exceptions,
+                                  error_return)
         func.kind = 'global'
         func.prefix = prefix
         func.global_key = key

ropemode/interface.py

     def pop_mark(self):
         self.env.pop_mark()
 
-    @decorators.local_command()
+    @decorators.local_function()
     def definition_location(self):
         definition = self._base_definition_location()
         if definition:
         self._check_project()
         self._base_show_doc(prefix, self._base_get_doc(codeassist.get_doc))
 
-    @decorators.local_command()
+    @decorators.local_function()
     def get_calltip(self):
         self._check_project()
         def _get_doc(project, text, offset, *args, **kwds):
         else:
             self.env.message('No docs available!')
 
-    @decorators.local_command()
+    @decorators.local_function()
     def get_doc(self):
         self._check_project()
         return self._base_get_doc(codeassist.get_doc)
     def auto_import(self):
         _CodeAssist(self, self.env).auto_import()
 
-    @decorators.local_command()
+    @decorators.local_function([])
     def completions(self):
         return _CodeAssist(self, self.env).completions()
 
-    @decorators.local_command()
+    @decorators.local_function([])
     def extended_completions(self):
         return _CodeAssist(self, self.env).extended_completions()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.