Exemplo n.º 1
0
 def on_query_context(self, view, key, operator, operand, match_all):
     if key == "clang_supported_language":
         if view == None:
             view = sublime.active_window().active_view()
         return is_supported_language(view)
     elif key == "clang_is_code":
         return self.not_code_regex.search(view.scope_name(view.sel()[0].begin())) == None
     elif key == "clang_complete_enabled":
         return clang_complete_enabled
     elif key == "clang_automatic_completion_popup":
         return get_setting("automatic_completion_popup", True, view)
     elif key == "clang_panel_visible":
         return clang_error_panel.is_visible()
Exemplo n.º 2
0
 def on_query_context(self, view, key, operator, operand, match_all):
     if key == "clang_supported_language":
         if view == None:
             view = sublime.active_window().active_view()
         return is_supported_language(view)
     elif key == "clang_is_code":
         return self.not_code_regex.search(view.scope_name(view.sel()[0].begin())) == None
     elif key == "clang_complete_enabled":
         return clang_complete_enabled
     elif key == "clang_automatic_completion_popup":
         return get_setting("automatic_completion_popup", True, view)
     elif key == "clang_panel_visible":
         return clang_error_panel.is_visible()
Exemplo n.º 3
0
 def on_close(self, view):
     if self.remove_on_close and is_supported_language(view):
         translationunitcache.tuCache.remove(sencode(view.file_name()))
Exemplo n.º 4
0
 def on_load(self, view):
     if self.cache_on_load and is_supported_language(view):
         warm_up_cache(view)
Exemplo n.º 5
0
    def on_modified(self, view):
        if (self.recompile_delay <= 0) or not is_supported_language(view):
            return

        self.view = view
        self.restart_recompile_timer(self.recompile_delay / 1000.0)
Exemplo n.º 6
0
 def on_post_save(self, view):
     if is_supported_language(view) and get_setting("reparse_on_save", True, view):
         self.view = view
         self.restart_recompile_timer(0.1)
Exemplo n.º 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)
Exemplo n.º 8
0
 def is_visible(self):
     return is_supported_language(sublime.active_window().active_view())
Exemplo n.º 9
0
 def is_enabled(self):
     return is_supported_language(sublime.active_window().active_view()) and len(navigation_stack) > 0
Exemplo n.º 10
0
 def on_close(self, view):
     if self.remove_on_close and is_supported_language(view):
         translationunitcache.tuCache.remove(sencode(view.file_name()))
Exemplo n.º 11
0
 def on_load(self, view):
     if self.cache_on_load and is_supported_language(view):
         warm_up_cache(view)
Exemplo n.º 12
0
    def on_modified(self, view):
        if (self.recompile_delay <= 0) or not is_supported_language(view):
            return

        self.view = view
        self.restart_recompile_timer(self.recompile_delay / 1000.0)
Exemplo n.º 13
0
 def on_post_save(self, view):
     if is_supported_language(view) and get_setting("reparse_on_save", True,
                                                    view):
         self.view = view
         self.restart_recompile_timer(0.1)
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def is_visible(self):
     return is_supported_language(sublime.active_window().active_view())
Exemplo n.º 16
0
 def is_enabled(self):
     return is_supported_language(sublime.active_window().active_view()
                                  ) and len(navigation_stack) > 0