Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_settings():
- """
- Load settings.
- :returns: dictionary containing settings
- """
- return sublime.load_settings("CTags.sublime-settings")
- def get_setting(key, default=None):
- """
- Load individual setting.
- :param key: setting key to get value for
- :param default: default value to return if no value found
- :returns: value for ``key`` if ``key`` exists, else ``default``
- """
- return get_settings().get(key, default)
- setting = get_setting
- class NavigateToDefinition(sublime_plugin.TextCommand):
- """
- Provider for the ``navigate_to_definition`` command.
- Command navigates to the definition for a symbol in the open file(s) or
- folder(s).
- """
- is_enabled = check_if_building
- def __init__(self, args):
- sublime_plugin.TextCommand.__init__(self, args)
- self.endings = re.compile(RUBY_SPECIAL_ENDINGS)
- def is_visible(self):
- return setting('show_context_menus')
- @ctags_goto_command(jump_directly=setting("jump_single_match")) # this is it
- def run(self, view, args, tags_file):
- region = view.sel()[0]
- if region.begin() == region.end(): # point
- region = view.word(region)
- # handle special line endings for Ruby
- language = view.settings().get('syntax')
- endings = view.substr(sublime.Region(region.end(), region.end()+1))
- if 'Ruby' in language and self.endings.match(endings):
- region = sublime.Region(region.begin(), region.end()+1)
- symbol = view.substr(region)
- return JumpToDefinition.run(sym
- # this isn't part of the problem, but I included it to show other code uses setting() normally in conditionals
- class TestCtags(sublime_plugin.TextCommand):
- routine = None
- def run(self, edit, **args):
- if self.routine is None:
- self.routine = self.co_routine(self.view)
- next(self.routine)
- def __next__(self):
- try:
- next(self.routine)
- except Exception as e:
- print(e)
- self.routine = None
- def co_routine(self, view):
- tag_file = find_tags_relative_to(
- view.file_name(), setting('tag_file'))
- with codecs.open(tag_file, encoding='utf-8') as tf:
- tags = parse_tag_lines(tf, tag_class=TagElements)
- print('Starting Test')
- ex_failures = []
- line_failures = []
- for symbol, tag_list in list(tags.items()):
- for tag in tag_list:
- tag.root_dir = os.path.dirname(tag_file)
- def hook(av):
- test_context = av.sel()[0]
- if tag.ex_command.isdigit():
- test_string = tag.symbol
- else:
- test_string = tag.ex_command
- test_context = av.line(test_context)
- if not av.substr(test_context).startswith(test_string):
- failure = 'FAILURE %s' % pprint.pformat(tag)
- failure += av.file_name()
- if setting('debug'):
- if not sublime.question_box('%s\n\n\n' % failure):
- self.routine = None
- return sublime.set_clipboard(failure)
- ex_failures.append(tag)
- sublime.set_timeout(self.__next__, 5)
- scroll_to_tag(view, tag, hook)
- yield
- failures = line_failures + ex_failures
- tags_tested = sum(len(v) for v in list(tags.values())) - len(failures)
- view = sublime.active_window().new_file()
- with Edit(view) as edit:
- edit.insert(view.size(), '%s Tags Tested OK\n' % tags_tested)
- edit.insert(view.size(), '%s Tags Failed' % len(failures))
- view.set_scratch(True)
- view.set_name('CTags Test Results')
- if failures:
- sublime.set_clipboard(pprint.pformat(failures))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement