Permalink
Browse files

- added jump-to-global command

- added automatic cache update on save
- added manual cache regeneration
  • Loading branch information...
1 parent 008b45e commit f63e4ce206133cb527b663b70a7d8c7ec4fe3276 @JulianEberius JulianEberius committed Jan 23, 2012
Showing with 67 additions and 25 deletions.
  1. +11 −0 README.markdown
  2. +51 −22 python_completions.py
  3. +5 −3 ropemate/__init__.py
View
@@ -22,6 +22,7 @@ Available Commands:
* Go to Definition
* Show Documentation
+* Jump to Global
* Refactor: Rename
* Refactor: Extract Method
* And, of course, completions, which hook into Sublime's normal completion system (Ctrl+Space)
@@ -51,6 +52,16 @@ SublimeRope provides no default keybindings, so you need to set them yourself. T
{ "key": "selector", "operator": "equal", "operand": "source.python" }
]
},
+ { "keys": ["ctrl+r", "ctrl+c"], "command": "python_regenerate_cache", "context":
+ [
+ { "key": "selector", "operator": "equal", "operand": "source.python" }
+ ]
+ },
+ { "keys": ["ctrl+r", "ctrl+j"], "command": "python_jump_to_global", "context":
+ [
+ { "key": "selector", "operator": "equal", "operand": "source.python" }
+ ]
+ },
Getting all completions to work
View
@@ -52,6 +52,50 @@ def output(self, string):
self.view.window().focus_view(out_view)
+class PythonJumpToGlobal(sublime_plugin.TextCommand):
+ """Allows the user to select from a list of all known globals
+ in a quick panel to jump there."""
+ def run(self, edit):
+ with ropemate.ropecontext(self.view) as context:
+ self.names = list(context.importer.get_all_names())
+ self.view.window().show_quick_panel(
+ self.names, self.on_select_global, sublime.MONOSPACE_FONT)
+
+ def on_select_global(self, choice):
+ def loc_to_str(loc):
+ resource, line = loc
+ return "%s:%s" % (resource.path, line)
+
+ if choice is not -1:
+ selected_global = self.names[choice]
+ with ropemate.ropecontext(self.view) as context:
+ self.locs = context.importer.get_name_locations(selected_global)
+ self.locs = map(loc_to_str, self.locs)
+
+ if not self.locs:
+ return
+ if len(self.locs) == 1:
+ self.on_select_location(0)
+ else:
+ self.view.window().show_quick_panel(
+ self.locs, self.on_select_location, sublime.MONOSPACE_FONT)
+
+ def on_select_location(self, choice):
+ loc = self.locs[choice]
+ with ropemate.ropecontext(self.view) as context:
+ path, line = loc.split(":")
+ path = context.project._get_resource_path(path)
+ self.view.window().open_file("%s:%s" % (path, line), sublime.ENCODED_POSITION)
+
+
+class PythonEventListener(sublime_plugin.EventListener):
+
+ def on_post_save(self, view):
+ with ropemate.ropecontext(view) as context:
+ context.importer.generate_cache(
+ resources=[context.resource])
+
+
class PythonCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
@@ -238,6 +282,13 @@ def run(self, edit, block=False):
window.open_file(path, sublime.ENCODED_POSITION)
+class PythonRegenerateCache(sublime_plugin.TextCommand):
+ def run(self, edit):
+ with ropemate.ropecontext(self.view) as context:
+ context.importer.clear_cache()
+ context.importer.generate_cache()
+
+
class RopeNewProject(sublime_plugin.WindowCommand):
def run(self):
folders = self.window.folders()
@@ -298,25 +349,3 @@ def done(self, path):
msg = "Could not create project folder at %s.\nException: %s"
sublime.error_message(msg % (self.proj_dir, str(e)))
return
-
-
-class AnalyzeModule(sublime_plugin.TextCommand):
- def run(self, edit):
- with ropemate.ropecontext(self.view) as context:
- if not context.project_dir:
- # no project dir known
- return
- file_name = self.view.file_name()
- cprefix = os.path.commonprefix(
- [context.project_dir, file_name])
- if not cprefix == context.project_dir:
- # current file not beneath the project dir
- return
-
- relpath = os.path.relpath(file_name, context.project_dir)
- module_name = relpath.replace(os.sep, ".")\
- .replace(".py", "").replace(".__init__", "")
-
- mod = context.project.pycore.find_module(module_name)
- print mod, mod.path
- context.project.pycore.analyze_module(mod)
View
@@ -26,10 +26,10 @@ def __enter__(self):
project_dir = self.find_ropeproject(file_path)
if project_dir:
self.project = project.Project(project_dir)
+ self.importer = autoimport.AutoImport(
+ project=self.project, observe=True)
if not os.path.exists("%s/.ropeproject/globalnames" % project_dir):
- importer = autoimport.AutoImport(
- project=self.project, observe=True)
- importer.generate_cache()
+ self.importer.generate_cache()
if os.path.exists("%s/__init__.py" % project_dir):
sys.path.append(project_dir)
else:
@@ -41,6 +41,8 @@ def __enter__(self):
self.project = project.Project(
ropefolder=None, projectroot=folder,
ignored_resources=ignored_res)
+ self.importer = autoimport.AutoImport(
+ project=self.project, observe=True)
self.resource = libutils.path_to_resource(self.project, file_path)
update_python_path(self.project.prefs.get('python_path', []))

0 comments on commit f63e4ce

Please sign in to comment.