Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Started work on #10
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed May 15, 2014
1 parent 0ed651f commit d1e2b60
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions sublime_ocp_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ def query_type(self, view, location):
else:
return "Type: %s" % result

def query_locate(self, view, location):
# TODO: de-dupe with query_type.... somehow
endword = view.word(location).end()
while view.substr(endword) in ['_', '#', '\'']:
endword = endword + 1
if view.substr(endword) is not ' ':
endword = view.word(endword).end()

query = self.extract_query(view, endword)

if query is not None:
(module, queryString, context, settings) = query

result = self.run_ocp('locate', view.window().folders(), module, queryString, context, settings)

if not (result is None or len(result) == 0):
view.window().open_file(result, sublime.ENCODED_POSITION | sublime.TRANSIENT)


def query_completions(self, view, prefix, location):
query = self.extract_query(view, location)
Expand Down Expand Up @@ -172,6 +190,22 @@ def extract_locals(self, view):

class SublimeOCPEventListener(sublime_plugin.EventListener):

def on_window_command(self, window, command_name, args):
if command_name == "goto_definition":
view = window.active_view()
location = view.sel()[0]
scopes = set(view.scope_name(location.begin()).split(" "))

if len(set(["source.ocaml", "source.ocamllex", "source.ocamlyacc"]) & scopes) > 0:
sublimeocp.query_locate(view, location)

# 'noop' doesn't exist, just here to disable the goto_definition command.
# We could allow the default if ocp-index doesn't find anything, but
# then we get weird results on library functions.
return ("sublime_ocp_noop")

# default return runs command unmodified

def on_query_completions(self, view, prefix, locations):
if len(locations) != 1:
return
Expand Down

0 comments on commit d1e2b60

Please sign in to comment.