Example #1
0
 def run(self, edit):
     view = self.view
     unsaved_files = []
     if view.is_dirty():
         unsaved_files.append((sencode(view.file_name()),
                       view.substr(Region(0, view.size()))))
     translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files)
Example #2
0
    def recompile(self):
        view = self.view
        unsaved_files = []
        if view.is_dirty() and get_setting("reparse_use_dirty_buffer", False, view):
            unsaved_files.append((sencode(view.file_name()),
                                  view.substr(Region(0, view.size()))))
        if not translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files,
                        self.reparse_done):

            # Already parsing so retry in a bit
            self.restart_recompile_timer(1)
Example #3
0
def warm_up_cache(view, filename=None):
    if filename == None:
        filename = sencode(view.file_name())
    stat = translationunitcache.tuCache.get_status(filename)
    if stat == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE:
        translationunitcache.tuCache.add(view, filename)
    return stat
Example #4
0
def get_translation_unit(view, filename=None, blocking=False):
    if filename == None:
        filename = sencode(view.file_name())
    if get_setting("warm_up_in_separate_thread", True, view) and not blocking:
        stat = warm_up_cache(view, filename)
        if stat == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE:
            return None
        elif stat == translationunitcache.TranslationUnitCache.STATUS_PARSING:
            sublime.status_message("Hold your horses, cache still warming up")
            return None
    return translationunitcache.tuCache.get_translation_unit(filename, translationunitcache.tuCache.get_opts(view), translationunitcache.tuCache.get_opts_script(view))
Example #5
0
 def on_close(self, view):
     if not get_setting("pop_on_close", True, view):
         return
     # If the view we just closed was last in the navigation_stack,
     # consider it "popped" from the stack
     fn = view.file_name()
     if fn == None:
         return
     fn = sencode(fn)
     while True:
         if len(navigation_stack) == 0 or \
                 not navigation_stack[
                     len(navigation_stack) - 1][1].startswith(fn):
             break
         navigation_stack.pop()
Example #6
0
 def on_close(self, view):
     if self.remove_on_close and is_supported_language(view):
         translationunitcache.tuCache.remove(sencode(view.file_name()))
Example #7
0
    def on_query_completions(self, view, prefix, locations):
        global clang_complete_enabled
        if not is_supported_language(view) or not clang_complete_enabled or \
                not view.match_selector(locations[0], '-string -comment -constant'):
            return []

        line = view.substr(sublime.Region(view.line(locations[0]).begin(), locations[0]))
        match = re.search(r"[,\s]*(\w+)\s+\w+$", line)
        if match != None:
            valid = ["new", "delete", "return", "goto", "case", "const", "static", "class", "struct", "typedef", "union"]
            if match.group(1) not in valid:
                # Probably a variable or function declaration
                # There's no point in trying to complete
                # a name that hasn't been typed yet...
                return self.return_completions([], view)

        timing = ""
        tot = 0
        start = time.time()
        tu = get_translation_unit(view)
        if tu == None:
            return self.return_completions([], view)
        ret = None
        tu.lock()
        try:
            if self.time_completions:
                curr = (time.time() - start)*1000
                tot += curr
                timing += "TU: %f" % (curr)
                start = time.time()

            cached_results = None
            if clang_fast_completions and get_setting("enable_fast_completions", True, view):
                data = view.substr(sublime.Region(0, locations[0]))
                try:
                    cached_results = tu.cache.complete(data, prefix)
                except:
                    traceback.print_exc()
            if cached_results != None:
                print("found fast completions")
                ret = cached_results
            else:
                print("doing slow completions")
                row, col = view.rowcol(locations[0] - len(prefix))
                unsaved_files = []
                if view.is_dirty():
                    unsaved_files.append((sencode(view.file_name()),
                                      view.substr(Region(0, view.size()))))
                ret = tu.cache.clangcomplete(sencode(view.file_name()), row+1, col+1, unsaved_files, is_member_completion(view, locations[0] - len(prefix)))
            if self.time_completions:
                curr = (time.time() - start)*1000
                tot += curr
                timing += ", Comp: %f" % (curr)
                start = time.time()

            if len(self.dont_complete_startswith) and ret:
                i = 0
                while i < len(ret):
                    disp = ret[i][0]
                    pop = False
                    for comp in self.dont_complete_startswith:
                        if disp.startswith(comp):
                            pop = True
                            break

                    if pop:
                        ret.pop(i)
                    else:
                        i += 1

            if self.time_completions:
                curr = (time.time() - start)*1000
                tot += curr
                timing += ", Filter: %f" % (curr)
                timing += ", Tot: %f ms" % (tot)
                print(timing)
                sublime.status_message(timing)
        finally:
            tu.unlock()

        if not ret is None:
            return self.return_completions(ret, view)
        return self.return_completions([], view)
Example #8
0
def format_current_file(view):
    row, col = view.rowcol(view.sel()[0].a)
    return "%s:%d:%d" % (sencode(view.file_name()), row + 1, col + 1)