Permalink
Browse files

Fixed jump_to_declaration

  • Loading branch information...
Schmallon committed Nov 12, 2011
1 parent 2446ac7 commit 3d4a22ce6f05f2753bfac6ce270129f3f873bfd6
Showing with 17 additions and 3 deletions.
  1. +3 −3 plugin/libclang.py
  2. +14 −0 plugin/test_clang.py
View
@@ -957,12 +957,12 @@ def __init__(self, editor, translation_unit_accessor):
def _find_declaration_in_translation_unit(self, translation_unit):
current_location_cursor = self._editor.get_current_cursor_in_translation_unit(translation_unit)
parent_cursor = current_location_cursor.get_semantic_parent()
- if parent_cursor == Cursor.nullCursor():
- return None
+ if parent_cursor == clang.cindex.Cursor.nullCursor():
+ return current_location_cursor.get_cursor_referenced()
for child_cursor in parent_cursor.get_children():
if child_cursor.get_canonical() == current_location_cursor.get_canonical():
return child_cursor
- return None
+ return current_location_cursor.get_cursor_referenced()
def declaration_cursors_do(self, function):
def call_function_with_declaration_in(translation_unit):
View
@@ -83,13 +83,24 @@ def jump_to_definition(self, source_file_name, start_line, start_column):
self.open_source_file(source_file_name, start_line, start_column)
self.clang_plugin.jump_to_definition()
+ def jump_to_declaration(self, source_file_name, start_line, start_column):
+ self.open_source_file(source_file_name, start_line, start_column)
+ self.clang_plugin.jump_to_declaration()
+
def assert_jumps_to_definition(self, source_file_name, start_line, start_column, expected_filename, expected_line, expected_column):
self.jump_to_definition(source_file_name, start_line, start_column)
if not self.editor.filename().endswith(expected_filename):
self.fail(self.editor.filename() + " does not end with " + expected_filename)
self.assertEquals(self.editor.current_column(), expected_column)
self.assertEquals(self.editor.current_line(), expected_line)
+ def assert_jumps_to_declaration(self, source_file_name, start_line, start_column, expected_filename, expected_line, expected_column):
+ self.jump_to_declaration(source_file_name, start_line, start_column)
+ if not self.editor.filename().endswith(expected_filename):
+ self.fail(self.editor.filename() + " does not end with " + expected_filename)
+ self.assertEquals(self.editor.current_column(), expected_column)
+ self.assertEquals(self.editor.current_line(), expected_line)
+
def test_jump_to_definition_in_same_file(self):
self.assert_jumps_to_definition("test_defined_in_same_file.cpp", 7, 3, "test_defined_in_same_file.cpp", 1, 1)
@@ -102,6 +113,9 @@ def test_jump_to_definition_in_another_source(self):
def test_jump_to_definition_default_to_declaration_if_no_definition_available(self):
self.assert_jumps_to_definition("test_declared_in_header.cpp", 5, 3, "declared_in_header.h", 1, 1)
+ def test_jump_to_declaration(self):
+ self.assert_jumps_to_declaration("test_declared_in_header.cpp", 5, 3, "declared_in_header.h", 1, 1)
+
def test_expression_in_macro(self):
# For now ensure that we don't crash
self.jump_to_definition("test_reference_in_macro.cpp", 9, 9)

0 comments on commit 3d4a22c

Please sign in to comment.