Skip to content

Commit

Permalink
Add jump to definition as Command Palette option
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan2552 committed Jan 9, 2017
1 parent 7a02205 commit c25bca4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 2 additions & 4 deletions Default.sublime-commands
@@ -1,6 +1,4 @@
[
{
"caption": "SourceKittenSubl: Show documentation popup",
"command": "source_kitten_subl_doc"
}
{ "caption": "SourceKittenSubl: Show documentation popup", "command": "source_kitten_subl_doc" },
{ "caption": "SourceKittenSubl: Jump to definition", "command": "source_kitten_subl_jump_to_definition" }
]
13 changes: 11 additions & 2 deletions src/subl_source_kitten.py
Expand Up @@ -38,7 +38,17 @@ def popup(offset, file, project_directory, text):

return popup_text

def source_location_link(offset, file, project_directory, text):
dictionary = source_kitten.cursor_info(offset, file, project_directory, text)
href, relative_path_with_offset = _source_location_paths(file, project_directory, dictionary)
return href

def _source_location_popup_section(file, project_directory, dictionary):
href, relative_path_with_offset = _source_location_paths(file, project_directory, dictionary)
value = "<a href=\"" + href + "\">" + relative_path_with_offset + "</a>"
return _popup_section("Location", value)

def _source_location_paths(file, project_directory, dictionary):
filepath = _value_or_empty_string("key.filepath", dictionary)
offset = _value_or_empty_string("key.offset", dictionary)
length = _value_or_empty_string("key.length", dictionary)
Expand All @@ -54,8 +64,7 @@ def _source_location_popup_section(file, project_directory, dictionary):
relative_path_with_offset = relative_path + ":1:" + str(offset)
absolute_path_with_offset = filepath + ":1:" + str(offset)
href = absolute_path_with_offset + "-" + str(length)
value = "<a href=\"" + href + "\">" + relative_path_with_offset + "</a>"
return _popup_section("Location", value)
return [href, relative_path_with_offset]

def _popup_section_from_dict(title, key, dictionary, xml=None):
value = _value_or_empty_string(key, dictionary)
Expand Down
12 changes: 12 additions & 0 deletions subl.py
Expand Up @@ -67,6 +67,18 @@ def run(self, edit):
point = self.view.sel()[0].begin()
SublCompletions().on_hover(self.view, point, sublime.HOVER_TEXT)

class SourceKittenSublJumpToDefinitionCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
file = view.file_name()
point = view.sel()[0].begin()
project_directory = _project_directory(view)
text = _view_text(view)
href = subl_source_kitten.source_location_link(point, file, project_directory, text)
instance = SublCompletions()
instance.view = view
instance.on_navigate(href)

def _project_directory(view):
if len(view.window().folders()) > 0:
return view.window().folders()[0]
Expand Down

0 comments on commit c25bca4

Please sign in to comment.